diff --git a/README.md b/README.md index e4b202fe0..9936884c7 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ If you want to only tests for your machine and not develop, you shouldn't instal Available packages for bindings: -TANGO: [tango-pyaml](https://github.com/python-accelerator-middle-layer/tango-pyaml) +TANGO: [tango-pyaml](https://github.com/python-accelerator-middle-layer/tango-pyaml) TANGO or EPICS: [pyaml-cs-oa](https://github.com/python-accelerator-middle-layer/pyaml-cs-oa) #### Developer Installation @@ -29,7 +29,7 @@ TANGO or EPICS: [pyaml-cs-oa](https://github.com/python-accelerator-middle-layer pip install -e . ``` 4. Install the development dependencies and pre-commit hooks - + ``` pip install -e .[dev] pre-commit install @@ -37,9 +37,9 @@ TANGO or EPICS: [pyaml-cs-oa](https://github.com/python-accelerator-middle-layer 5. If you want to try the examples using the control system bindings you also need to install those. See: - TANGO: [tango-pyaml](https://github.com/python-accelerator-middle-layer/tango-pyaml) + TANGO: [tango-pyaml](https://github.com/python-accelerator-middle-layer/tango-pyaml) TANGO or EPICS: [pyaml-cs-oa](https://github.com/python-accelerator-middle-layer/pyaml-cs-oa) - + 6. If you want to run tests manually using the TANGO bindings without requiring a live machine you can also install the the Dummy TANGO control system available in tests/dummy-cs/tango. It is a simple emulation that allows to check the interface to the control system. The implemented control system doesn't do anything but it is only intended for tests during the development. diff --git a/pyaml/accelerator.py b/pyaml/accelerator.py index f944a8232..25ebea40a 100644 --- a/pyaml/accelerator.py +++ b/pyaml/accelerator.py @@ -108,6 +108,25 @@ def live(self) -> ControlSystem: def design(self) -> Simulator: return self.__design + @staticmethod + def from_dict(config_dict: dict, ignore_external=False) -> "Accelerator": + """ + Construct an accelerator from a dictionary. + Parameters + ---------- + config_dict : str + Dictionnary conatining accelerator config + ignore_external: bool + Ignore external modules and return None for object that + cannot be created. pydantic schema that support that an + object is not created should handle None fields. + + """ + if ignore_external: + # control systems are external, so remove controls field + config_dict.pop("controls", None) + return Factory.depth_first_build(config_dict, ignore_external) + @staticmethod def load( filename: str, use_fast_loader: bool = False, ignore_external=False @@ -136,8 +155,4 @@ def load( rootfolder = os.path.abspath(os.path.dirname(filename)) set_root_folder(rootfolder) config_dict = load(os.path.basename(filename), None, use_fast_loader) - if ignore_external: - # control systems are external, so remove controls field - config_dict.pop("controls", None) - aml = Factory.depth_first_build(config_dict, ignore_external) - return aml + return Accelerator.from_dict(config_dict)