configconfig.parser

class Parser(allow_unknown_keys=False)[source]

Base class for YAML configuration parsers.

Custom parsing steps for each configuration variable can be implemented with methods in the form:

def visit_<configuration value name>(
        self,
        raw_config_vars: Dict[str, Any],
        ) -> Any: ...

The method must return the value to set the configuration variable to, or raise an error in the case of invalid input.


A final custom parsing step, useful when several values must be set at once, may be implemented in the custom_parsing method:

def custom_parsing(
        self,
        raw_config_vars: Mapping[str, Any],
        parsed_config_vars: MutableMapping[str, Any],
        filename: PathPlus,
        ) -> MutableMapping[str, Any]: ...

This takes the mapping of raw configuration variables, the mapping of parsed variables (those set with the visit_<configuration value name> method), and the configuration file name. The method must return the parsed_config_vars.

Methods:

custom_parsing(raw_config_vars, …)

Custom parsing step.

run(filename)

Parse configuration from the given file.

custom_parsing(raw_config_vars, parsed_config_vars, filename)[source]

Custom parsing step.

Parameters
  • raw_config_vars (Mapping[str, Any]) – Mapping of raw configuration values loaded from the YAML configuration file.

  • parsed_config_vars (MutableMapping[str, Any]) – Mapping of parsed configuration values.

  • filename (PathPlus) – The filename of the YAML configuration file.

Return type

MutableMapping[str, Any]

run(filename)[source]

Parse configuration from the given file.

Parameters

filename (Union[str, Path, PathLike]) – The filename of the YAML configuration file.

Return type

MutableMapping[str, Any]