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

description_

Text to display before the argument help

env_prefix_

Prefix for automatically derived environment variable names

ini_relaxed_sections_

Names of sections to parse in configuration files, with unknown keys ignored

ini_strict_sections_

Names of additional sections to parse in configuration files, unknown keys error

prog_

Program name

Methods

from_command_line_

Parses multiple information sources into a configuration and display help on error

get_argument_parser_

Returns an argparse.ArgumentParser for documentation purposes

ini_sections_

Returns a sequence of INI file sections to parse

parse_command_line_

Parses multiple information sources, returns a configuration, a command or an error

parse_ini_contents_

Parses the contents of an INI file into a configuration

parse_ini_file_

Parses an INI file into a configuration

processor_

Returns a processor for this configuration

validators_

Returns all validators present in the given subclass of this class

version_

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_ and ini_strict_sections_. Otherwise, override this method.

Return type

Sequence[IniSection]

prog_: ClassVar[Optional[str]] = None

Program name

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

Return type

Optional[str]

Returns

Version number as a string

env_prefix_: ClassVar[str] = ''

Prefix for automatically derived environment variable names

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_.

Return type

Sequence[Callable[[TypeVar(_Config, bound= Config)], Optional[Err]]]

Returns

A sequence of all validators

classmethod processor_()[source]

Returns a processor for this configuration

Return type

Processor[TypeVar(_Config, bound= Config)]

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.

Parameters

ini_contents (str) – Multiline string describing the configuration contents

Return type

Union[TypeVar(_Config, bound= Config), Err]

Returns

A parsed configuration or an error

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.

Parameters

ini_file_path (Path) – Path to an INI file

Return type

Union[TypeVar(_Config, bound= Config), Err]

Returns

A parsed configuration or an error

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.

Parameters
Return type

TypeVar(_Config, bound= Config)

Returns

A parsed configuration

classmethod get_argument_parser_()[source]

Returns an argparse.ArgumentParser for documentation purposes

This 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

ArgumentParser

__init__()