-
Notifications
You must be signed in to change notification settings - Fork 26
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
Make name separator configurable #675
Conversation
Remove the stripping of underscore while we're at it, this can be done by overriding set_name if required
|
This is fine for us at ISIS, and corresponds with my understanding of the dev meeting yesterday. If I was going to use a custom separator it would be useful to have it mentioned briefly in the docs somewhere. |
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.
Generally looks good but I think we need something in the docs about the tradeoffs of setting it and the reasoning behind making it different by default
Thinking a bit more about this, I'm wondering if we should remove the ability to set name from device = MyDevice("PV_PRE", name="foo") we would do device = MyDevice("PV_PRE").named("foo") This would make it obvious where to put the separator if we wanted to override it without having to thread it through init: device = MyDevice("PV_PRE").named("foo", separator="_")
I'm not convinced, I think the name adds something, maybe it should be @tacaswell @DominicOram @Tom-Willemsen thoughts? |
That's a bigger change than originally proposed - that'll need every Under that model our instantiation wrappers for lots of devices at ISIS would basically look like: # When bluesky name is related to PV name (which is common for us at ISIS)
def my_device_1(some, args, name):
return MyDevice1(some, args, name).named(name)
# Or for when we want to have a default name for the device,
# only overridden in special cases (99% of the time "THING" is correct).
def my_device_2(some, args, name="THING"):
return MyDevice2(some, args).named(name) I don't necessarily mind doing that, the above is quite simple if a bit repetitive, but especially in the second case it's an extra layer of indirection that we need to set up as a consumer of We could live with either case, but I'd say I slightly prefer the existing approach. |
I like keyword only as comparing obj.set_name('foo', '-')
obj.set_name('foo', separator='-')
obj.set_name('foo', child_name_separator='-') the first is pretty unclear. I like the longer name, but at NSLS-II we have the rule "Don't let Tom name things". There is a gentle path to adding |
True, but we are about to move to a model where the name of the instantiation function is also used for the returned device, so shouldn't be used in more than a handful of cases...
Ok, I hear the message about a gentle path, but I would also like to get 1.0 out soon and passing I suggest:
What do you reckon? |
@DiamondJoseph what's happening with the device factory wrapper in dodal? Am I right in thinking that this wouldn't cause us too much pain? |
The device_factory decorator is back in, and can name the device if it has not been named prior to this when called - which is almost certainly done prior to connect? We can modify this call however we want to. It's only in use on i22, training_rigs, with PRs for non-MX beamlines open while I track down the state of those beamlines. |
Ok, a slight modification to the suggestion:
Then we can still write our one-liner if we need to: device = named_device(MyDevice("PV_PRE"), "foo", child_name_separator="_") |
@coretl does the utility function allow us to set the child separator for all ophyd-async devices in a particular environment? Or is the intention we have to do it per instance or per class definition? Sorry I've not had enough time to follow this discussion in depth after the call in Monday. |
Per instance
No, but we can make with DeviceCollector(set_name=True, child_name_separator="_"):
foo = MyDevice("PREFIX1")
bar = MyDevice("PREFIX2")
assert foo.child.name == "foo_child"
assert bar.another_child.name == "bar_another_child" |
Then for me, this works |
I baulked at the sheer number of tests that would have to change if we deprecated passing |
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.
Minor comment, take it or leave it, otherwise all good from my perspective.
Remove the stripping of underscore while we're at it, this can be done by overriding set_name if required.
Fixes #666