pyaml.configuration.factory#

Build PyAML objects from configuration dictionaries and lists.

The factory resolves class paths, optionally validates configuration with Pydantic models, recursively builds nested values, and registers constructed accelerator elements.

Classes

BuildInfo(module, config_cls, class_cls, ...)

Store the resolved information required to construct one object.

ElementRegistry()

Singleton registry of all instantiated Elements.

PyAMLFactory()

Construct PyAML objects from recursively nested configuration data.

class pyaml.configuration.factory.BuildInfo(module, config_cls, class_cls, control_modes, config)#

Bases: object

Store the resolved information required to construct one object.

Attributes

module

Module containing the target class.

config_cls

Optional configuration model used to validate the object data.

class_cls

Class to instantiate.

control_modes

Control-system modes for creating an UnboundElement.

config

Remaining constructor configuration.

class pyaml.configuration.factory.ElementRegistry#

Bases: object

Singleton registry of all instantiated Elements.

Elements are registered by name and can later be retrieved individually, by wildcard pattern, or by type.

Methods

register()

Register an Element by name.

get()

Return an Element by name.

get_by_name()

Return all elements whose name matches a wildcard pattern.

get_by_type()

Return all registered elements of the given type.

clear()

Remove all registered elements.

clear()#

Remove all registered elements.

get(name)#

Return an Element by name.

Parameters:

name (str) – Element name.

Returns:

Element – Registered element.

Raises:

PyAMLConfigException – If the element is not registered.

Return type:

Element

get_by_name(wildcard)#

Return all elements whose name matches a wildcard pattern.

Parameters:

wildcard (str) – Wildcard expression compatible with fnmatch.

Returns:

list[Element] – Matching elements.

Return type:

list[Element]

get_by_type(element_type)#

Return all registered elements of the given type.

Parameters:

element_type (type[Element]) – Element type to match.

Returns:

list[TElement] – Matching elements.

Return type:

list[TElement]

register(element)#

Register an Element by name.

Parameters:

element (Element) – Element to register.

Raises:

PyAMLConfigException – If the object is not an Element or if another element with the same name is already registered.

class pyaml.configuration.factory.PyAMLFactory#

Bases: object

Construct PyAML objects from recursively nested configuration data.

Methods

build()

Build objects from a top-level mapping or sequence.

clear()

Remove all registered elements from the global registry.

build(data, ignore_external=False)#

Build objects from a top-level mapping or sequence.

Parameters:
  • data (dict | list) – Configuration dictionary or list to resolve.

  • ignore_external (bool) – If True, ignore unavailable external modules.

Returns:

Any – Built object, list, or recursively processed mapping.

Return type:

Any

clear()#

Remove all registered elements from the global registry.