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 settingCONF_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, theINIT_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 updateDEFAULT_SRC
using a subclass__init__
parameters.Attributes
Configuration class associated with the current class.
Dictionary of
__init__
parameter names to configuration key path.Methods
Take the same parameters as
__init__
, and check their types according to what is specified in the configuration class.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']
.