lir.registry module
- class lir.registry.ClassLoader[source]
Bases:
ConfigParserLoaderA configuration parser loader that uses reflection to resolve class names.
- get(key: str, default_config_parser: Callable[[Any], ConfigParser] | None = None, search_path: list[str] | None = None) ConfigParser[source]
Get the accompanying config parser class from the registry.
- Parameters:
key (str) – The key name to resolve, expected to be a full class name (for example: ‘lir.transform.base.BaseTransform’).
default_config_parser (Callable[[Any], ConfigParser] | None, optional) – A function that returns a ConfigParser if the key does not resolve to a ConfigParser, by default None.
search_path (list[str] | None, optional) – The domain of the search query, by default None.
- Returns:
A ConfigParser object.
- Return type:
- exception lir.registry.ComponentNotFoundError[source]
Bases:
ValueErrorRepresentation of an error when a component class cannot be found.
- class lir.registry.ConfigParserLoader[source]
-
Base class for a configuration parser loader.
A configuration parser is able to interpret a dictionary-style configuration loaded from a YAML. Sub classes are expected to implement the get() method.
- abstractmethod get(key: str, default_config_parser: Callable[[Any], ConfigParser] | None = None, search_path: list[str] | None = None) ConfigParser[source]
Retrieve a value for a given key name.
The key may resolve to a ConfigParser class, or it is passed as an argument to default_config_parser, which in turn returns a ConfigParser class.
- Parameters:
key (str) – The key name to resolve.
default_config_parser (Callable[[Any], ConfigParser] | None, optional) – A function that returns a ConfigParser if the key does not resolve to a ConfigParser, by default None.
search_path (list[str] | None, optional) – The domain of the search query, by default None.
- Returns:
A ConfigParser object.
- Return type:
- class lir.registry.FederatedLoader(registries: list[ConfigParserLoader])[source]
Bases:
ConfigParserLoaderA configuration parser loader that delegates resolution to other loaders.
- Parameters:
registries (list[ConfigParserLoader]) – A list of configuration parser loaders to delegate to, in order of priority.
- get(key: str, default_config_parser: ~collections.abc.Callable[[~typing.Any], ~lir.config.base.ConfigParser] | None = <class 'lir.config.base.GenericConfigParser'>, search_path: list[str] | None = None) ConfigParser[source]
Get the accompanying config parser class from the registry.
- Parameters:
key (str) – The key name to resolve.
default_config_parser (Callable[[Any], ConfigParser] | None, optional) – A function that returns a ConfigParser if the key does not resolve to a ConfigParser.
search_path (list[str] | None, optional) – The domain of the search query, by default None.
- Returns:
A ConfigParser object.
- Return type:
- exception lir.registry.InvalidRegistryEntryError[source]
Bases:
ValueErrorRepresentation of an invalid registry entry.
- class lir.registry.YamlRegistry(cfg: Configuration)[source]
Bases:
ConfigParserLoaderRepresentation of a YAML-based registry.
The YAML registry is organized into sections as the lop=level key names. Each section can have registry entries. A registry entry is a configuration parser. It can be used in an experiment setup to materialize a component and initialize it with its configuration.
This registry parses this YAML mapping and provides access to registry antries through a
get()method.A registry entry can take the following arguments:
class: a
strthat can be resolved to a ConfigParserargs: the arguments passed to the config parser
Example:
section: entry: class: package.ClassName args: foo: some init argument bar: another init argument
If the configuration parser only has a
classargument, the alternative notation can be used where the class is passed as a string value to the entry directly. Example:section: entry: package.ClassName
The class of each entry may be a
ConfigParser. If it is not, the registry parser will attempt to use a default configuration parser, depending on the context, and the default configuration parser will be initialized with the object of the registry entry.- Parameters:
cfg (confidence.Configuration) – The configuration object containing the registry entries.
- get(key: str, default_config_parser: Callable[[Any], ConfigParser] | None = None, search_path: list[str] | None = None) ConfigParser[source]
Retrieve a value for a given key name from the YAML-based registry.
An entry can take the following forms, available under the keys
path.to.key1andpath.to.key2respectively:path.to.key1: ObjectName path.to.key2: class: ObjectName
In the example,
ObjectNamerefers to a Python object available in the current runtime.- Parameters:
key (str) – The key name to resolve.
default_config_parser (Callable[[Any], ConfigParser] | None, optional) – A function that returns a ConfigParser if the key does not resolve to a ConfigParser, by default None.
search_path (list[str] | None, optional) – The domain of the search query, by default None.
- Returns:
A ConfigParser object.
- Return type:
- lir.registry.get(name: str, default_config_parser: Callable[[Any], ConfigParser] | None = None, search_path: list[str] | None = None) ConfigParser[source]
Retrieve corresponding value for a given key name from the central registry.
- Parameters:
name (str) – The key name to resolve.
default_config_parser (Callable[[Any], ConfigParser] | None, optional) – A function that returns a ConfigParser if the key does not resolve to a ConfigParser, by default None.
search_path (list[str] | None, optional) – The domain of the search query, by default None.
- Returns:
A ConfigParser object.
- Return type:
- lir.registry.registry() ConfigParserLoader[source]
Provide access to a centralized registry of available configuration options.
- Returns:
A configuration parser loader that can be used to retrieve configuration parsers for various components.
- Return type: