lir.registry module

class lir.registry.ClassLoader[source]

Bases: ConfigParserLoader

A 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:

ConfigParser

exception lir.registry.ComponentNotFoundError[source]

Bases: ValueError

Representation of an error when a component class can not be found.

class lir.registry.ConfigParserLoader[source]

Bases: ABC, Iterable

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:

ConfigParser

class lir.registry.FederatedLoader(registries: list[ConfigParserLoader])[source]

Bases: ConfigParserLoader

A 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:

ConfigParser

exception lir.registry.InvalidRegistryEntryError[source]

Bases: ValueError

Representation of an invalid registry entry.

class lir.registry.YamlRegistry(cfg: Configuration)[source]

Bases: ConfigParserLoader

Representation of a YAML-based registry.

The YAML registry is expected to define “sections” as the top-level key names, followed by keys referring to (paths to) classnames or functions.

This registry parses this YAML mapping and provides access to these values through a get() method.

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.key1 and path.to.key2 respectively:

path.to.key1: ObjectName
path.to.key2:
    class: ObjectName

In the example, ObjectName refers 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:

ConfigParser

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:

ConfigParser

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:

ConfigParserLoader