-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow device classes to be specified as direct imports #6
Comments
The core of this capability comes as each device specification is parsed from the file (using just-added and unrelased if class_name not in self.device_classes:
self.device_classes[class_name] = dynamic_import(class_name) |
Perhaps the most general location for that code is before this line: guarneri/src/guarneri/instrument.py Line 153 in 114d3c1
so, rewriting the insertion: if defn["device_class"] not in self.device_classes:
self.device_classes[defn["device_class"]] = dynamic_import(defn["device_class"]) An exception could be raised from |
To avoid adding an |
I agree. Dependencies get weird otherwise. |
Expected Behavior
It would be nice if we didn't need to always tell the Instrument which devices are fair game. The consumer code can do this if it wants, but to do this for all cases seems like boilerplate.
This should happen after the configuration file is parsed into the common definition list so that it doesn't depend on whether this done in TOML, YAML, or a custom configuration format.
The following example YAML file from @prjemian would then be usable. It would still require that either
parse_config
orparse_yaml_file
is subclassed in order to understand the specific structure of the YAML file, but the device_class parameter would not need special treatment.parse_config()
orparse_yaml_file()
would need to return the following python list:wait_for_connection might not be necessary since this can be handled by
Instrument.connect()
, but we can discuss separately.Current Behavior
Currently,
Instrument
needs a dictionary of device class names and their corresponding Device class or factory:which can then consume this TOML file:
After parsing, the instrument looks up the section heading "motor" in the list of known device classes:
guarneri/src/guarneri/instrument.py
Line 158 in 25dd1c0
Possible Solution
Let's say we have the following TOML:
If the key for the device class (i.e.
"ophyd.EpicsMotor"
) is not indevice_classes
, then the instrument could attempt to import it directly. I believe @prjemian has a way of doing this already so we can perhapsstealgain inspiration from that solution.Context
Having the ability to specify device class names explicitly is useful for customizing the loading operation. But for many use cases this might be considered boiler plate, especially if the device is part of some other library (e.g. apstools) and isn't going to be subclasses or customized. Beamline staff could just add an entry to the configuration file directly using the import path and be done.
The text was updated successfully, but these errors were encountered: