table_spec module
Define the base objects constraining values/types of config parameters.
- class TableConfSpec(configured_object, table_entry, specs, is_mandatory=True, can_have_untested_keys=False, selectkey_n_default=None, monkey_patches=None)[source]
Bases:
objectSet specifications for a table, which holds several key-value pairs.
Note
This object can be subclassed for specific configuration needs, eg
BeamTableConfSpec.- Parameters:
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, default:True)can_have_untested_keys (
bool, default:False)selectkey_n_default (
tuple[str,str|bool] |None, default:None)monkey_patches (
dict[str,dict[str,Callable]] |dict[bool,dict[str,Callable]] |None, default:None)
- __init__(configured_object, table_entry, specs, is_mandatory=True, can_have_untested_keys=False, selectkey_n_default=None, monkey_patches=None)[source]
Set a table of properties. Correspond to a [table] in the
TOML.- Parameters:
configured_object (
Literal['beam','beam_calculator','beam_calculator_post','design_space','evaluators','files','plots','wtf']) – Name of the object that will receive associated parameters.table_entry (
str) – Name of the table in theTOMLfile, without brackets.specs (
Collection[KeyValConfSpec] |dict[str,Collection[KeyValConfSpec]] |dict[bool,Collection[KeyValConfSpec]]) – TheKeyValConfSpecobjects 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, default:True) – If the current table must be provided. The default is True.can_have_untested_keys (
bool, default:False) – If LightWin should remain calm when some keys are provided in theTOMLbut do not correspond to anyKeyValConfSpec. The default is False.selectkey_n_default (
tuple[str,str|bool] |None, default:None) – Must be given ifspecsis 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, default:None) – Same keys asspecs, to override some default methods. The default is None.
- _get_specs(toml_subdict=None)[source]
Get the proper list of
KeyValConfSpec.Used when we need to read the value of
_selectkey_n_defaultin theTOMLto choose precisely which configuration we should match.- Parameters:
toml_subdict (
dict[str,Any] |None, default:None) – The content of the toml file. We use it only ifself._specsis not already a Collection. We look for the value ofself._selectkey_n_default[0]and use it to select the proper table. If not provided, we fall back on a default value.- Return type:
- _set_specs_as_dict(toml_subdict=None)[source]
Set the dict of specifications.
Used when we need to read the value of
_selectkey_n_defaultin theTOMLto choose precisely which configuration we should match. Iftoml_subdictis not provided, we use a default value.
- _get_proper_spec(spec_name)[source]
Get the specification for the property named
spec_name.- Parameters:
spec_name (
str)- Return type:
- to_toml_strings(toml_subdict, original_toml_folder=None, **kwargs)[source]
Convert the given dict in string that can be put in a
TOML.- Parameters:
- Returns:
All the
TOMLlines corresponding to the table under study.- Return type:
- _pre_treat(toml_subdict, **kwargs)[source]
Edit some values, create new ones. To call before validation.
Note
In general, the edited values will undergo the validation process.
- _validate(toml_subdict, **kwargs)[source]
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, **kwargs)[source]
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, toml_folder=None, **kwargs)[source]
Transform the paths to their absolute resolved version.
- _mandatory_keys_are_present(toml_keys)[source]
Ensure that all the mandatory parameters are defined.
- Parameters:
toml_keys (
Collection[str])- Return type:
- _remove_overriden_keys(specs)[source]
Remove the
KeyValConfSpecobjects to override.Todo
Not Pythonic at all.
- Parameters:
specs (
Collection[KeyValConfSpec])- Return type: