-
Notifications
You must be signed in to change notification settings - Fork 8
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
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice functools use
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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=True
we 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 one
I'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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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). |
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}