Parsing#

This module allows to parse configuration files, which use a modified YAML syntax, to data and iteration trees, as defined in the iteration module. In particular, it defines the supported custom YAML types.

phileas.parsing.load_data_tree_from_yaml_file(file: Path | str) iteration.DataTree[source]#

Parses a YAML configuration file (from its path or its content) into a data tree.

phileas.parsing.load_iteration_tree_from_yaml_file(file: Path | str) IterationTree[source]#

Parses a YAML configuration file (from its path or its content) into an iteration tree. Iteration will be based on cartesian products, and iteration leaves can be specified with custom YAML types.

class phileas.parsing.YamlCustomType[source]#

Bases: ABC

class phileas.parsing.Configurations(configurations: dict[phileas.iteration.base.Key, Any], default: phileas.iteration.base.Key, move_up: bool, insert_name: bool)[source]#

Bases: YamlCustomType

Configurations container. It holds a dictionary of configurations, and has three optional arguments: _default, _move_up and _insert_name.

_default specifies the name of the default configuration.

_move_up is a boolean defaulting to False. If it is set, the content of the chosen configuration will be moved one level up.

_insert_name is a boolean defaulting to False. If it is set, the name of the chosen configuration will be inserted in the final :py:attr`~phileas.iteration.base.DataTree``. If move_up, then it is assigned to the key that previously hold the !configurations node. Otherwise, it is inserted under the name "_configuration".

See Configurations for more details on the impact of _move_up and _insert_name.

class phileas.parsing.CartesianProduct(children: dict[phileas.iteration.base.Key, Any] | list, order: list[phileas.iteration.base.Key] | None, lazy: bool, snake: bool)[source]#

Bases: YamlCustomType

Cartesian product node, see CartesianProduct for the supported arguments.

class phileas.parsing.Union(children: dict[phileas.iteration.base.Key, Any] | list, order: list[phileas.iteration.base.Key] | None, lazy: bool, preset: Literal['first'] | Literal['default'] | None, common_preset: bool, reset: Literal['first'] | Literal['last'] | Literal['default'] | None)[source]#

Bases: YamlCustomType

Union node, see Union for the supported arguments.

class phileas.parsing.Zip(children: dict[phileas.iteration.base.Key, Any] | list, order: list[phileas.iteration.base.Key] | None, lazy: bool, stops_at: Literal['shortest', 'longest'], ignore_fixed: bool)[source]#

Bases: YamlCustomType

Zip node, whose iteration behaves like zip().

class phileas.parsing.Shuffle(child: Any)[source]#

Bases: YamlCustomType

Shuffle node, whose iteration returns a permutation of its only child. It has a single child field.

class phileas.parsing.First(child: Any, size: int | None)[source]#

Bases: YamlCustomType

First node, which only iterates over the first elements of its child.

class phileas.parsing.Pick(children: dict[phileas.iteration.base.Key, Any], default_child: phileas.iteration.base.Key)[source]#

Bases: YamlCustomType

Pick node, whose iteration alternatively returns a single of its children. It contains a named mapping, with a _default_child field, containing the key of its default child.

class phileas.parsing.RT#

Numeric type of the Range

alias of TypeVar(‘RT’, bound=int | float)

class phileas.parsing.Range(start: RT, end: RT, default: RT | None = None, steps: int | None = None, resolution: float | int | None = None, progression: Literal['linear', 'geometric'] = 'linear')[source]#

Bases: YamlCustomType, Generic[RT]

Range of numbers, that can optionally (but usually will) specify an iteration method. It can be converted to an iteration leaf using to_iteration_tree().

The start and end attributes are mandatory, and default can be optionally specified.

steps or resolution (but not both) can be specified. If they are, and progression is not, or equals "linear", the range will represent

  • an IntegerRange if start and end are integers and resolution is used and is an integer;

  • an LinearRange otherwise.

If progression is geometric, the Range will represent an GeometricRange.

If neither steps nor resolution is specified, the range will represent an NumericRange.

class phileas.parsing.Sequence(elements: 'list[iteration.DataTree]', default: 'iteration.DataTree | None' = None)[source]#

Bases: YamlCustomType

class phileas.parsing.Random(distribution: 'str', parameters: 'dict[str, Any]', size: 'int | None' = None, default: 'iteration.DataTree | None' = None)[source]#

Bases: YamlCustomType

class phileas.parsing.UniformBigIntegerRng(high: 'int', low: 'int' = 0, size: 'int | None' = None, default: 'iteration.DataTree | None' = None)[source]#

Bases: YamlCustomType

class phileas.parsing.PrimeRng(high: 'int', low: 'int' = 0, size: 'int | None' = None, default: 'iteration.DataTree | None' = None)[source]#

Bases: YamlCustomType