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
(De)serialization rework #4
Comments
Here's a sketch of how the 3 would work, with on demand importing implemented: The downsides:
What do you reckon? |
I reckon that looks good! Got a few questions though:
Also had a thought over the weekend, we could change |
VSCode YAML plugin supports a JSON schema to give you hints and validation when editing YAML files. I'd like tickit to be able to produce a JSON schema for its config file, but to do this we need the deserialization to be defined statically using those unions rather than dynamically as it encounters each key. Then you can create the schema like this: https://github.com/epics-containers/ibek/blob/8397dc972e9164c511a96f4035f652c49739f5d4/ibek/__main__.py#L43
I'll defer this question until I actually make some of these classes. I intend to make these classes manually, then only automate if we need to. Having only looked at the cryocooler so far, it doesn't seem complicated enough to have to generate the config class, so I was going to make it manually.
Sounds good, I'll do that |
* Try to fix #4 for cryostream only * Fix the mypy error for raise_interrupt * Try to fix #4 for cryostream only * Fix the mypy error for raise_interrupt * Ported everything apart from nested and tests * Support SystemSimulation * Fixed remaining tests * Fix docs * Update tickit/core/management/event_router.py Co-authored-by: Garry O'Donnell <56754322+garryod@users.noreply.github.com> * Update tickit/cli.py Co-authored-by: Garry O'Donnell <56754322+garryod@users.noreply.github.com> * Update tickit/cli.py Co-authored-by: Garry O'Donnell <56754322+garryod@users.noreply.github.com> * Update tickit/core/components/system_simulation.py Co-authored-by: Garry O'Donnell <56754322+garryod@users.noreply.github.com> * Update tickit/core/components/device_simulation.py Co-authored-by: Garry O'Donnell <56754322+garryod@users.noreply.github.com> * Fix event_router indentation * Add test for as_tagged_union and fix bug * Rename lifetime_runnable to runner * Fix test_runner to use correct mock library Co-authored-by: Garry O'Donnell <56754322+garryod@users.noreply.github.com> Co-authored-by: Garry O'Donnell <garry.o'donnell@diamond.ac.uk>
The current (de)serialization system is clunky, it requires significant rework to improve usability of the library.
Current System
The current system operates by defining "config" classes for each interface (e.g.
DeviceConfig
forDevice(Protocol)
); such classes act as anapischema
tagged union of derived "config" classes. User classes are made configurable by the addition of a nested "config" class (via a decorator or inheritance of a type which applies the decorator), which joins the tagged union of it's template.At deserilization time, all classes referenced by the configuration file must be loaded prior to
apischema
deserialzation such that the nested config classes can be created. This necessitates an ugly two stage process in which the config file is first parsed for fully qualified names to load them, and then parsed again to perform deserialization.On the end user front, this requires the following boilerplate:
Such that
MyDevice
can be given a nested classMyDeviceConfig
which subtypesDeviceConfig
, allowing forapischema
deserialization by tagged union where the qualified name ofMyDevice
.Target System
An ideal system would have the following benefits over the current system:
Proposed System
I expect deserialization would likely operate as follows, though I would love to hear suggestions of alternatives:
The primary issue with this system stems from the fact that we wish to inject some init arguments during the instantiation process, there exist several possible solutions to this problem, the merits of which must be weighed:
build()
method which takes injected arguments__init__
, instead pass them to methods such asrun_forever()
build()
method which takes injected argumentsThe text was updated successfully, but these errors were encountered: