Config
Config¶
- class Config[source]¶
Bases:
abc.ABC
Base class for dataclasses holding configuration data
Example
@dataclass(frozen=True) class Adder(Config): x: Annotated[int, Param.store(types.int_)] y: Annotated[int, Param.store(types.int_, default_value="0")] res = Adder.from_command_line_(args=['x','2', 'y','3'], env={}) res.x + res.y
Attributes
Note: attributes inherited from parent classes are not shown here, if any
Text to display before the argument help
Prefix for automatically derived environment variable names
Names of sections to parse in configuration files, with unknown keys ignored
Names of additional sections to parse in configuration files, unknown keys error
Program name
Methods
Parses multiple information sources into a configuration and display help on error
Returns an
argparse.ArgumentParser
for documentation purposesReturns a sequence of INI file sections to parse
Parses multiple information sources, returns a configuration, a command or an error
Parses the contents of an INI file into a configuration
Parses an INI file into a configuration
Returns a processor for this configuration
Returns all validators present in the given subclass of this class
Returns the version number of this script
List of members of Config
- ini_relaxed_sections_: ClassVar[Sequence[str]] = ['Common', 'COMMON', 'common']¶
Names of sections to parse in configuration files, with unknown keys ignored
- ini_strict_sections_: ClassVar[Sequence[str]] = []¶
Names of additional sections to parse in configuration files, unknown keys error
- classmethod ini_sections_()[source]¶
Returns a sequence of INI file sections to parse
By default, this parses first the relaxed sections and then the strict ones.
First, try to replace the contents of
ini_relaxed_sections_
andini_strict_sections_
. Otherwise, override this method.- Return type
- description_: ClassVar[Optional[str]] = None¶
Text to display before the argument help
If not present, taken from the Config subclass docstring.
- classmethod version_()[source]¶
Returns the version number of this script
Designed to be overridden by a subclass
- classmethod validators_()[source]¶
Returns all validators present in the given subclass of this class
Validators are methods that take no arguments (except self) and return an optional error. Their name starts with
validate_
.
- classmethod parse_ini_contents_(ini_contents)[source]¶
Parses the contents of an INI file into a configuration
This method skips the processing of environment variables and command-line parameters.
- classmethod parse_ini_file_(ini_file_path)[source]¶
Parses an INI file into a configuration
This method skips the processing of environment variables and command-line parameters.
- classmethod parse_command_line_(cwd=None, args=None, env=None)[source]¶
Parses multiple information sources, returns a configuration, a command or an error
Default values are taken from the current working directory, the script command line arguments, and the current environment variables.
- Parameters
- Return type
Union
[TypeVar
(_Config
, bound=Config
),SpecialAction
,Err
]- Returns
A parsed configuration or an error
- classmethod from_command_line_(cwd=None, args=None, env=None)[source]¶
Parses multiple information sources into a configuration and display help on error
Default values are taken from the current working directory, the script command line arguments, and the current environment variables.
- classmethod get_argument_parser_()[source]¶
Returns an
argparse.ArgumentParser
for documentation purposesThis may be removed or deprecated in later versions of configpile, if we write our own help/usage display function, and propose a Sphinx extension.
- Return type
- __init__()¶