configconfig.configvar

class ConfigVar(raw_config_vars: Dict[str, Any])[source]

Base class for YAML configuration values.

The class docstring should be the description of the config var, with an example, and the name of the class should be the variable name.

Alternatively, for a more Pythonic naming approach, the variable name can be set with the name class variable.

Example:

class platforms(ConfigVar):
    """
    A case-insensitive list of platforms to perform tests for.

    Example:

    .. code-block:: yaml

        platforms:
          - Windows
          - Linux

    These values determine the GitHub test workflows to enable,
    and the Trove classifiers used on PyPI.
    """

    dtype = List[Literal["Windows", "macOS", "Linux"]]
    default: List[str] = ["Windows", "macOS", "Linux"]
    category: str = "packaging"

Attributes:

category

The category the ConfigVar is listed under in the documentation.

default

The default value of the configuration value if it is optional.

dtype

The allowed type or types in the YAML configuration file.

required

Flag to indicate whether the configuration value is required.

rtype

The variable type passed to Jinja2.

Methods:

get([raw_config_vars])

Returns the value of this ConfigVar.

make_documentation()

Returns the reStructuredText documentation for the ConfigVar.

validate([raw_config_vars])

Validate the value obtained from the YAML file and coerce into the appropriate return type.

validator(value)

Function to call to validate the values.

category = 'other'

Type:    str

The category the ConfigVar is listed under in the documentation.

default = ''

Type:    Union[Callable[[Dict[str, Any]], Any], Any]

The default value of the configuration value if it is optional. Defaults to '' if unset.

May also be set to a callable which returns a dynamic or mutable default value.

dtype = typing.Any

Type:    Type

The allowed type or types in the YAML configuration file.

classmethod get(raw_config_vars=None)[source]

Returns the value of this ConfigVar.

Parameters

raw_config_vars (Optional[Dict[str, Any]]) – Dictionary to obtain the value from. Default None.

Return type

See the rtype attribute.

classmethod make_documentation()[source]

Returns the reStructuredText documentation for the ConfigVar.

Return type

str

required = False

Type:    bool

Flag to indicate whether the configuration value is required. Default False.

rtype = typing.Any

Type:    Type

The variable type passed to Jinja2. If None dtype is used. Ignored for dtype=bool.

classmethod validate(raw_config_vars=None)[source]

Validate the value obtained from the YAML file and coerce into the appropriate return type.

Parameters

raw_config_vars (Optional[Dict[str, Any]]) – Dictionary to obtain the value from. Default None.

Return type

See the rtype attribute.

classmethod validator(value)[source]

Function to call to validate the values.

  • The callable must have a single required argument (the value).

  • Should raise ValueError if values are invalid, and return the values if they are valid.

  • May change the values (e.g. make lowercase) before returning.

Return type

Any