Meta

Elements:

SetContext(key, value)

Set static context for this sequence.

StoreContext()

Store static context.

UpdateContextFromStatic()

Update runtime context with the static one.

Metaprogramming:

merge_heads(*seqs)

Merge common heads of sequences seqs.

Elements

class SetContext(key, value)[source]

Set static context for this sequence.

Static context does not automatically update runtime context. Use UpdateContextFromStatic for that.

Static context can be used during the initialisation phase to set output directories, Cache names, etc. There is no way to update static context from runtime one.

key is a string representing a (possibly nested) dictionary key. value is its value.

value can be a formatting string. See format_context() for details.

If value could not be formatted, LenaKeyError is raised.

class StoreContext[source]

Store static context. Use for debugging.

class UpdateContextFromStatic[source]

Update runtime context with the static one.

Note that for runtime context later elements update previous values, but for static context it is the opposite (external and previous elements take precedence).

Metaprogramming

These functions allow transformations of Lena sequences.

merge_heads(*seqs)[source]

Merge common heads of sequences seqs.

Equal elements are merged into a common sequence, first unequal ones are put into a Split and recursively merged with similar ones. To be able to be merged, sequence elements must support equality comparison.

This class can optimize processing same data with several sequences in different modules by reading that data once and processing that simultaneously. Example:

s1 = Source(
    ReadData(),
    Process1(),
)
s2 = Source(
    ReadData(),
    Process2(),
)
merged = merge_heads(s1, s2)

# merged is
Source(
    ReadData(),
    Split([
        Process1(),
        Process2(),
    ]),
)

# merge_heads(s1, s1) is s1

seqs are Lena sequences. They must be of the same type (for example Source).

Added in version 0.6.