lisa.conf.Configurable#

class lisa.conf.Configurable[source]#

Bases: ABC

Pair a regular class with a configuration class.

The pairing is achieved by inheriting from Configurable and setting CONF_CLASS attribute. The benefits are:

  • The docstring of the class is processed as a string template and {configurable_params} is replaced with a Sphinx-compliant list of parameters. The help and type of each parameter is extracted from the configuration class.

  • The DEFAULT_SRC attribute of the configuration class is updated with non-None default values of the class __init__ parameters.

  • The conf_to_init_kwargs() method allows turning a configuration object into a dictionary suitable for passing to __init__ as **kwargs.

  • The check_init_param() method allows checking types of __init__ parameters according to what is specified in the configuration class.

Most of the time, the configuration keys and __init__ parameters have the same name (modulo underscore/dashes which are handled automatically). In that case, the mapping between config keys and __init__ parameters is done without user intervention. When that is not the case, the INIT_KWARGS_KEY_MAP class attribute can be used.

Note

A given configuration class must be paired to only one class. Otherwise, the DEFAULT_SRC conf class attribute will be updated multiple times, leading to unexpected results.

Note

Some services offered by Configurable are not extended to subclasses of a class using it. For example, it would not make sense to update DEFAULT_SRC using a subclass __init__ parameters.

Attributes

CONF_CLASS

Configuration class associated with the current class.

INIT_KWARGS_KEY_MAP

Dictionary of __init__ parameter names to configuration key path.

Methods

check_init_param()

Take the same parameters as __init__, and check their types according to what is specified in the configuration class.

conf_to_init_kwargs()

Turn a configuration object into a dictionary suitable for passing to __init__ as **kwargs.

Attributes#

Configurable.CONF_CLASS = None#

Configuration class associated with the current class.

Configurable.INIT_KWARGS_KEY_MAP = {}#

Dictionary of __init__ parameter names to configuration key path.

That path is a list of strings to take into account sublevels like ['level-key', 'sublevel', 'foo'].

Methods#

classmethod Configurable.check_init_param(**kwargs)[source]#

Take the same parameters as __init__, and check their types according to what is specified in the configuration class.

Raises:

TypeError – When the wrong type is detected for a parameter.

classmethod Configurable.conf_to_init_kwargs(conf)[source]#

Turn a configuration object into a dictionary suitable for passing to __init__ as **kwargs.