Repository navigation
Isolated device factory - #841
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #841 +/- ##
==========================================
+ Coverage 95.12% 95.19% +0.07%
==========================================
Files 120 120
Lines 4899 4976 +77
==========================================
+ Hits 4660 4737 +77
Misses 239 239 ☔ View full report in Codecov by Sentry. |
|
I don't necessarily expect parallel connect to be implemented here but do we have tickets for achieving it? |
for blueapi there's DiamondLightSource/blueapi#440 |
DominicOram
left a comment
There was a problem hiding this comment.
Great, thank you!
Some comments in code, mostly minor. I think a few more tests would also be good. e.g. we can test (assuming these are all desired behavior?):
- A device gets renamed if called again with a different name
- If we call with
connect=False, mock=Truewe can then call again withmock=False
Additionally I think there's a potential pitfall in:
dcm(mock=True)
.... # Lots of code
dcm() # This now fails because it tries to turn the cached mock one into a real oneI'm not 100% sure if this is expected or if you would rather give the cached mocked one, maybe with a warning. We should at least document it but can do so in #780.
DominicOram
left a comment
There was a problem hiding this comment.
Thanks. I'm still a little concerned about the not 100% intuitive behavior of calling the factory twice with different permutations of connect/mock but I thin we can document/fix that later.
@coretl for comments?
A device can be renamed after having a name, so I think it should be allowed. Currently the device_factory name is only used if the device is currently unnamed.
Only when connect is called is the device being mock or not considered. Calling with connect=False, mock=True then later connecting with mock=False would connect to the real signal backend.
Ophyd-async throws an exception if you try and connect a 2nd time with a different value of |
I'm not even sure that is the best answer either. You then end up with the above code connecting you to a |
|
I agree there is no good solution to be honest, caching singletons is hard to do without some hidden magic. Maybe add more logging (but in a separate change). |
This reverts commit 0ba531c.
This reverts commit 0ba531c.
* Revert "Prevent devices connecting as side effect of use elsewhere (#860)" This reverts commit 52848b3. * Revert " Prevent simulated connect from trying to connect to real device (#849)" This reverts commit ecc1a20. * Revert "Add deprecation warning to inject (#854)" This reverts commit 0f8989e. * Revert "Isolated device factory (#841)" This reverts commit 0ba531c.
* Add DeviceFactory decorator * Convert i22 beamline to use DeviceFactory * Documenting potential pitfall with repeated connect/mock
* Add DeviceFactory decorator * Convert i22 beamline to use DeviceFactory * Documenting potential pitfall with repeated connect/mock
* Add DeviceFactory decorator * Convert i22 beamline to use DeviceFactory * Documenting potential pitfall with repeated connect/mock
* Add DeviceFactory decorator * Convert i22 beamline to use DeviceFactory * Documenting potential pitfall with repeated connect/mock
* Add DeviceFactory decorator * Convert i22 beamline to use DeviceFactory * Documenting potential pitfall with repeated connect/mock
* Add DeviceFactory decorator * Convert i22 beamline to use DeviceFactory * Documenting potential pitfall with repeated connect/mock
* Add DeviceFactory decorator * Convert i22 beamline to use DeviceFactory * Documenting potential pitfall with repeated connect/mock
* Add DeviceFactory decorator * Convert i22 beamline to use DeviceFactory * Documenting potential pitfall with repeated connect/mock
Fixes #483
This is a re-implementation of #597 isolated to just the changes necessary to implement the
@device_factory()decorator and have functions decorated with that decorator picked up bymake_all_devices: respecting any configuration passed into the decorator.NB: this is also required for blueapi #647
Instructions to reviewer on how to test:
Checks for reviewer
dodal connect ${BEAMLINE}