factory#
- class BuildInfo(module, config_cls, class_str, field_locations, location_str)[source]#
Bases:
objectInformation required to construct an object from a configuration dictionary.
- module#
Imported module containing the object class and validation model.
- Type:
ModuleType
- field_locations#
Mapping between configuration fields and their source locations in the configuration file.
- Type:
dict | None
- module: ModuleType#
- class ElementRegistry[source]#
Bases:
objectSingleton registry of all instantiated Elements.
Elements are registered by name and can later be retrieved individually, by wildcard pattern, or by type.
Return the singleton registry instance.
- get(name)[source]#
Return an Element by name.
- Parameters:
name (str) – Element name.
- Returns:
Element – Registered element.
- Raises:
PyAMLConfigException – If the element is not registered.
- get_by_name(wildcard)[source]#
Return all elements whose name matches a wildcard pattern.
- Parameters:
wildcard (str) – Wildcard expression compatible with
fnmatch.- Returns:
list[Element] – Matching elements.
- register(element)[source]#
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 PyAMLFactory[source]#
Bases:
objectFactory for constructing PyAML objects from configuration data.
- build(data, ignore_external)[source]#
Recursively build objects from configuration data.
Lists are traversed recursively and configuration dictionaries are converted into instantiated objects.
- handle_validation_error(exc, type_str, location_str, field_locations)[source]#
Convert a Pydantic validation error into a PyAMLConfigException.
Validation errors are reformatted to include the corresponding configuration field and, when available, the source file location of the field in the configuration file.
- Parameters:
exc (ValidationError) – Pydantic validation error.
type_str (str) – Name of the object type being validated.
location_str (str) – Human-readable location of the object definition in the configuration file.
field_locations (dict | None) – Mapping between field names and their source locations in the configuration file.
- Raises:
PyAMLConfigException – Always raised with a formatted summary of the validation errors. The original Pydantic exception traceback is suppressed.
- resolve_build_info(data, ignore_external)[source]#
Resolve the information required to construct an object.
The configuration dictionary is inspected to determine the module, object class and validation model to use. The referenced module is imported and the corresponding validation class is retrieved.
- Parameters:
- Returns:
BuildInfo | None – Information required to construct the object, or
Nonewhenignore_externalis enabled and the referenced module cannot be imported.- Raises:
PyAMLConfigException – If the configuration is invalid, the referenced class cannot be resolved, or the validation model cannot be found.