key_val_conf_spec module
Define the base objects constraining values/types of config parameters.
- class KeyValConfSpec(key, types, description, default_value, allowed_values=None, is_mandatory=True, is_a_path_that_must_exists=False, action=None, warning_message=None, error_message=None, overrides_previously_defined=False, derived=False)[source]
Bases:
objectSet specifications for a single key-value pair.
- Parameters:
key (
str) – Name of the attribute.types (
tuple[type,...]) – Allowed types for the value. Used to check validity of input. When creating a configTOMLfile, the first type of the tuple is used for proper formatting. Prefer giving a tuple of types, even if there is only one possible type.description (
str) – A markdown string to describe the property. Will be displayed in the documentation.default_value (
Any) – A default value for the property. Used when generating dummy configurations; also used if the property is not mandatory and was not provided.allowed_values (
Collection[Any] |None, default:None) – A set of allowed values, or range of allowed values. The default is None, in which case no checking is performed.is_mandatory (
bool, default:True) – If the property must be given.is_a_path_that_must_exists (
bool, default:False) – If the property is a string/path and its existence must be checked before running the code.action (
Literal['store_true','store_false'] |None, default:None) – on/off flag, also check theargparsedocumentation. Will skip testing over type and allowed values.warning_message (
str|None, default:None) – If provided, using current key will print a warning with this message.error_message (
str|None, default:None) – If provided, using current key will raise an IOError with this error message.overrides_previously_defined (
bool, default:False) – If the current object should remove a previously definedKeyValConfSpecwith the same name.derived (
bool, default:False) – If the property is calculated from other properties. The default is False, in which case it must be set by the user. Note that derived keys will not appear in theTOMLoutput strings.
- allowed_values: Collection[Any] | None = None
- path_exists(toml_value, toml_folder=None, **kwargs)[source]
Check that the given path exists if necessary.
- to_toml_string(toml_value=None, original_toml_folder=None, **kwargs)[source]
Convert the value into a line that can be put in a
TOML.- Parameters:
- Return type:
- Returns:
The
TOMLline corresponding to current object.
- to_csv_line()[source]
Convert object to a line for the documentation
CSV.Todo
Better display of allowed values
- __init__(key, types, description, default_value, allowed_values=None, is_mandatory=True, is_a_path_that_must_exists=False, action=None, warning_message=None, error_message=None, overrides_previously_defined=False, derived=False)
- Parameters:
key (
str)description (
str)default_value (
Any)allowed_values (
Collection[Any] |None, default:None)is_mandatory (
bool, default:True)is_a_path_that_must_exists (
bool, default:False)action (
Literal['store_true','store_false'] |None, default:None)overrides_previously_defined (
bool, default:False)derived (
bool, default:False)
- Return type:
None