manager#
manager.py
Configuration aggregation helpers for Accelerator.
This module provides ConfigurationManager, a lightweight service used
to collect configuration fragments before runtime objects are built.
Typical usage is:
load one or more accelerator configuration fragments
inspect or query the aggregated state
build the final
Accelerator
- class ConfigurationManager[source]#
Bases:
objectAggregate accelerator configuration fragments before runtime build.
ConfigurationManagerstores configuration fragments as plain dictionaries and exposes convenience helpers to inspect, query and update them before constructing the final runtime object graph.Notes
The manager only accepts accelerator-root fragments and merges named categories such as
controls,simulators,arraysanddevices.Examples
Load a base configuration and inspect it:
>>> from pyaml.configuration import ConfigurationManager >>> manager = ConfigurationManager() >>> manager.add("tests/config/config_manager_base.yaml") >>> manager.categories() ['simulators']
Build the final accelerator:
>>> sr = manager.build() >>> sr.design.name() 'design'
- classmethod root_fields()[source]#
Return the ordered root fields supported by the accelerator model.
The field order is derived from
ConfigModel.- Returns:
tuple[str, …]
Examples
>>> ConfigurationManager.root_fields()
- static strip_internal_metadata(value)[source]#
Remove additionnal internal informations info from value
- static strip_runtime_internal_metadata(value)[source]#
Remove additionnal internal informations info from value
- __dir__()[source]#
Extend
dir()with attribute-friendly entry names.Examples
>>> "HCORR" in dir(manager)
- __getattr__(name)[source]#
Provide attribute-style access for categories and unambiguous entry names.
Examples
>>> manager.simulators
>>> manager.HCORR
- __repr__()[source]#
Return a human-readable overview of the aggregated configuration.
Examples
>>> repr(manager)
- __str__()[source]#
Return the same overview as
__repr__().Examples
>>> print(manager)
- add(payload, **kwargs)[source]#
Add a configuration fragment from a dict or a YAML/JSON file.
- Parameters:
payload (dict or str or os.PathLike) – Fragment to merge into the current aggregated state.
source_name (str, optional) – Explicit source label to associate with the fragment.
use_fast_loader (bool, optional) – Forwarded to the configuration loader.
Examples
>>> manager.add("tests/config/config_manager_base.yaml")
>>> manager.add( ... { ... "facility": "ESRF", ... "machine": "sr", ... "energy": 6e9, ... "data_folder": "/data/store", ... "devices": [], ... } ... )
- build(ignore_external=False)[source]#
Build an Accelerator from the aggregated configuration snapshot.
- Parameters:
ignore_external (bool, optional) – Forwarded to
pyaml.accelerator.Accelerator.from_dict().- Returns:
Accelerator
Examples
>>> sr = manager.build()
- categories()[source]#
Return categories that currently contain entries.
- Returns:
list[str]
Examples
>>> manager.categories()
- clear(category=None)[source]#
Clear the aggregated state, or a single root field/category.
- Parameters:
category (str, optional) – If provided, only that category or root field is cleared.
Examples
>>> manager.clear("simulators")
>>> manager.clear()
- find(pattern, category=None)[source]#
Search entry names using wildcards or regular expressions.
- Parameters:
- Returns:
list[str]
Examples
>>> manager.find("BPM_C04*")
>>> manager.find("re:^QF1.*$")
- get(category, name)[source]#
Return a named configuration entry.
Examples
>>> manager.get("simulators", "design")
- has(category, name)[source]#
Check whether a named entry exists.
Examples
>>> manager.has("simulators", "design") True
- keys(category=None)[source]#
Return known entry names.
- Parameters:
category (str, optional) – Restrict the result to one category.
- Returns:
list[str]
Examples
>>> manager.keys()
>>> manager.keys("simulators")
- remove(category, name)[source]#
Remove a named entry from an aggregated category.
Examples
>>> manager.remove("simulators", "tracking")
- replace(category, element)[source]#
Replace an existing named entry in an aggregated category.
- Parameters:
Examples
>>> manager.replace( ... "simulators", ... { ... "type": "pyaml.lattice.simulator", ... "name": "design", ... "lattice": "tests/config/sr/lattices/ebs.mat", ... }, ... )
- settings()[source]#
Return aggregated scalar accelerator settings.
- Returns:
dict[str, Any]
Examples
>>> manager.settings()
- to_dict()[source]#
Return the aggregated configuration as a plain dictionary.
- Returns:
dict[str, Any]
Examples
>>> snapshot = manager.to_dict()
- DEFAULT_TYPE = 'pyaml.accelerator'#
- NAMED_CATEGORIES = ('controls', 'simulators', 'arrays', 'devices')#
- class UnsupportedConfigurationRootError(message)[source]#
Bases:
PyAMLConfigExceptionRaised when a fragment root is outside ConfigurationManager scope.