table_spec module
Define the base objects constraining values/types of config parameters.
- class TableConfSpec(configured_object: Literal['beam', 'beam_calculator', 'beam_calculator_post', 'design_space', 'evaluators', 'files', 'plots', 'wtf'], table_entry: str, specs: Collection[KeyValConfSpec] | dict[str, Collection[KeyValConfSpec]] | dict[bool, Collection[KeyValConfSpec]], is_mandatory: bool = True, can_have_untested_keys: bool = False, selectkey_n_default: tuple[str, str | bool] | None = None, monkey_patches: dict[str, dict[str, Callable]] | dict[bool, dict[str, Callable]] | None = None)
Bases:
objectSet specifications for a table, which holds several key-value pairs.
Note
This object can be subclassed for specific configuration needs, eg
BeamTableConfSpec.- __init__(configured_object: Literal['beam', 'beam_calculator', 'beam_calculator_post', 'design_space', 'evaluators', 'files', 'plots', 'wtf'], table_entry: str, specs: Collection[KeyValConfSpec] | dict[str, Collection[KeyValConfSpec]] | dict[bool, Collection[KeyValConfSpec]], is_mandatory: bool = True, can_have_untested_keys: bool = False, selectkey_n_default: tuple[str, str | bool] | None = None, monkey_patches: dict[str, dict[str, Callable]] | dict[bool, dict[str, Callable]] | None = None) None
Set a table of properties. Correspond to a [table] in the
.toml.- Parameters:
configured_object (str) – Name of the object that will receive associated parameters.
table_entry (str) – Name of the table in the
.tomlfile, without brackets.specs (Collection[KeyValConfSpec] | dict[str, Collection[KeyValConfSpec]] | dict[str, Collection[KeyValConfSpec]]) – The
KeyValConfSpecobjects in the current table. When the format of the table depends on the value of a key, provide a dictionary linking every possible table with the corresponding value.is_mandatory (bool, optional) – If the current table must be provided. The default is True.
can_have_untested_keys (bool, optional) – If LightWin should remain calm when some keys are provided in the
.tomlbut do not correspond to anyKeyValConfSpec. The default is False.selectkey_n_default (tuple[str, str | bool] | None, optional) – Must be given if
specsis a dict. First value is name of the spec, second value is default value. We will look for this spec in the configuration file and select the properCollectionofKeyValConfSpecaccordingly.monkey_patches (dict[str, dict[str, Callable]] | dict[bool, dict[str, Callable]] | None, optional) – Same keys as
specs, to override some default methods. The default is None.
- _get_specs(toml_subdict: dict[str, Any] | None = None) list[KeyValConfSpec]
Get the proper list of
KeyValConfSpec.Used when we need to read the value of
_selectkey_n_defaultin the.tomlto choose precisely which configuration we should match.
- _set_specs_as_dict(toml_subdict: dict[str, Any] | None = None) None
Set the dict of specifications.
Used when we need to read the value of
_selectkey_n_defaultin the.tomlto choose precisely which configuration we should match. Iftoml_subdictis not provided, we use a default value.
- _get_proper_spec(spec_name: str) KeyValConfSpec | None
Get the specification for the property named
spec_name.
- to_toml_strings(toml_subdict: dict[str, Any], original_toml_folder: Path | None = None, **kwargs) list[str]
Convert the given dict in string that can be put in a
.toml.- Parameters:
toml_subdict (dict[str, Any]) – A dictionary corresponding to a
.tomltable.original_toml_folder (pathlib.Path | None, optional) – Where the original
.tomlwas; this is used to resolve paths relative to this location.
- Returns:
All the
.tomllines corresponding to the table under study.- Return type:
- _pre_treat(toml_subdict: dict[str, Any], **kwargs) None
Edit some values, create new ones. To call before validation.
Note
In general, the edited values will undergo the validation process.
- prepare(toml_subdict: dict[str, Any], **kwargs) bool
Validate the config dict and edit some values.
- _validate(toml_subdict: dict[str, Any], **kwargs) bool
Check that key-values in
toml_subdictare valid.This method is defined to keep an implementation of the original method even when
validateis overriden by a monkey patch.
- _post_treat(toml_subdict: dict[str, Any], **kwargs) None
Edit some values, create new ones. To call after validation.
Note
In general, the edited values will not be validated. To handle with care.
- _make_paths_absolute(toml_subdict: dict[str, Any], toml_folder: Path | None = None, **kwargs) None
Transform the paths to their absolute resolved version.
- _mandatory_keys_are_present(toml_keys: Collection[str]) bool
Ensure that all the mandatory parameters are defined.
- _remove_overriden_keys(specs: Collection[KeyValConfSpec]) list[KeyValConfSpec]
Remove the
KeyValConfSpecobjects to override.Todo
Not Pythonic at all.