From 304d852d0268647e3d2576115730c51a53b435e4 Mon Sep 17 00:00:00 2001 From: Charles Titus Date: Wed, 10 Apr 2024 15:45:13 -0400 Subject: [PATCH 1/6] Added long name to OphydObject and Signal --- ophyd/ophydobj.py | 25 +++++++++++++++++++++++-- ophyd/signal.py | 3 ++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/ophyd/ophydobj.py b/ophyd/ophydobj.py index 471ffedd6..71c0f4aaa 100644 --- a/ophyd/ophydobj.py +++ b/ophyd/ophydobj.py @@ -148,7 +148,16 @@ class OphydObject: __any_instantiated = False subscriptions: ClassVar[FrozenSet[str]] = frozenset() - def __init__(self, *, name=None, attr_name="", parent=None, labels=None, kind=None): + def __init__( + self, + *, + name=None, + attr_name="", + parent=None, + labels=None, + kind=None, + long_name=None, + ): if labels is None: labels = set() self._ophyd_labels_ = set(labels) @@ -166,7 +175,7 @@ def __init__(self, *, name=None, attr_name="", parent=None, labels=None, kind=No raise ValueError("name must be a string.") self._name = name self._parent = parent - + self._long_name = long_name # dictionary of wrapped callbacks self._callbacks = {k: {} for k in self.subscriptions} # this is to maintain api on clear_sub @@ -331,6 +340,18 @@ def name(self): def name(self, name): self._name = name + @property + def long_name(self): + """name of the device""" + if self._long_name is not None: + return self._long_name + else: + return self._name + + @name.setter + def long_name(self, name): + self._long_name = name + @property def attr_name(self): return self._attr_name diff --git a/ophyd/signal.py b/ophyd/signal.py index f01180dbd..20e95c03f 100644 --- a/ophyd/signal.py +++ b/ophyd/signal.py @@ -105,10 +105,11 @@ def __init__( metadata=None, cl=None, attr_name="", + long_name=None, ): super().__init__( - name=name, parent=parent, kind=kind, labels=labels, attr_name=attr_name + name=name, parent=parent, kind=kind, labels=labels, attr_name=attr_name, long_name=long_name ) if cl is None: From 87118ae6d0e8dc423ab4d88df7e909cd365e1742 Mon Sep 17 00:00:00 2001 From: Charles Titus Date: Wed, 10 Apr 2024 17:40:39 -0400 Subject: [PATCH 2/6] fixed long_name setter --- ophyd/ophydobj.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ophyd/ophydobj.py b/ophyd/ophydobj.py index 71c0f4aaa..9f3df4592 100644 --- a/ophyd/ophydobj.py +++ b/ophyd/ophydobj.py @@ -348,7 +348,7 @@ def long_name(self): else: return self._name - @name.setter + @long_name.setter def long_name(self, name): self._long_name = name From 43ac00e76bd0526e123ea555fa06f6863662a48c Mon Sep 17 00:00:00 2001 From: Charles Titus Date: Wed, 10 Apr 2024 17:57:56 -0400 Subject: [PATCH 3/6] STY: Ran Black formatter --- ophyd/ophydobj.py | 1 - ophyd/signal.py | 9 ++++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ophyd/ophydobj.py b/ophyd/ophydobj.py index 9f3df4592..234b75d20 100644 --- a/ophyd/ophydobj.py +++ b/ophyd/ophydobj.py @@ -36,7 +36,6 @@ class IFBase(IntFlag, boundary=KEEP): ... except ImportError: - IFBase = IntFlag diff --git a/ophyd/signal.py b/ophyd/signal.py index 20e95c03f..8df2eecb9 100644 --- a/ophyd/signal.py +++ b/ophyd/signal.py @@ -107,9 +107,13 @@ def __init__( attr_name="", long_name=None, ): - super().__init__( - name=name, parent=parent, kind=kind, labels=labels, attr_name=attr_name, long_name=long_name + name=name, + parent=parent, + kind=kind, + labels=labels, + attr_name=attr_name, + long_name=long_name, ) if cl is None: @@ -1719,7 +1723,6 @@ def __init__( name=None, **kwargs, ): - self._write_pv = None self._use_limits = bool(limits) self._put_complete = put_complete From 50a5362584ad1c8cf99f0283bcb1412a99b229ec Mon Sep 17 00:00:00 2001 From: Charles Titus Date: Mon, 15 Jul 2024 15:14:53 -0400 Subject: [PATCH 4/6] long_name added to signal class --- ophyd/signal.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ophyd/signal.py b/ophyd/signal.py index 8df2eecb9..5721ad182 100644 --- a/ophyd/signal.py +++ b/ophyd/signal.py @@ -487,6 +487,7 @@ def describe(self): "source": "SIM:{}".format(self.name), "dtype": data_type(val), "shape": data_shape(val), + "long_name": self.long_name, } } except ValueError as ve: @@ -1491,6 +1492,7 @@ def describe(self): units=self._metadata["units"], lower_ctrl_limit=lower_ctrl_limit, upper_ctrl_limit=upper_ctrl_limit, + long_name=self.long_name, ) if self.precision is not None: @@ -2271,6 +2273,7 @@ def describe(self): "source": "PY:{}.{}".format(self.parent.name, self.full_attr), "dtype": data_type(value), "shape": data_shape(value), + "long_name": self.long_name } return {self.name: desc} From 9451e6b48a55781f8aba173577ae95863984ac99 Mon Sep 17 00:00:00 2001 From: Charles Titus Date: Thu, 1 Aug 2024 10:00:10 -0400 Subject: [PATCH 5/6] Propagating Long Name through components, test for name propagation added to test_device --- ophyd/device.py | 5 ++++- ophyd/tests/test_device.py | 14 +++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ophyd/device.py b/ophyd/device.py index 86c43345c..9badcf228 100644 --- a/ophyd/device.py +++ b/ophyd/device.py @@ -258,6 +258,10 @@ def create_component(self, instance): attr_name=self.attr, ) + _long_name = kwargs.get("long_name", self.attr) + _parent_long_name = getattr(instance, "long_name", instance.name) + kwargs["long_name"] = f"{_parent_long_name} {_long_name}" + for kw, val in list(kwargs.items()): kwargs[kw] = self.maybe_add_prefix(instance, kw, val) @@ -1785,7 +1789,6 @@ def wrapped(self, *args, **kwargs): def _wait_for_connection_context(value, doc): @contextlib.contextmanager def wrapped(dev): - orig = dev.lazy_wait_for_connection dev.lazy_wait_for_connection = value try: diff --git a/ophyd/tests/test_device.py b/ophyd/tests/test_device.py index c3d8b464c..e3ef54bf7 100644 --- a/ophyd/tests/test_device.py +++ b/ophyd/tests/test_device.py @@ -768,14 +768,14 @@ def test_dotted_name(): from ophyd.sim import SynSignal class Inner(Device): - x = Cpt(SynSignal) + x = Cpt(SynSignal, long_name="Inner X") y = Cpt(SynSignal) class Outer(Device): - a = Cpt(Inner) + a = Cpt(Inner, long_name="Outer A") b = Cpt(Inner) - o = Outer(name="test") + o = Outer(name="test", long_name="Test") assert o.dotted_name == "" assert o.a.dotted_name == "a" @@ -797,6 +797,14 @@ class Outer(Device): assert o.a.y.attr_name == "y" assert o.b.y.attr_name == "y" + assert o.long_name == "Test" + assert o.a.long_name == "Test Outer A" + assert o.b.long_name == "Test b" + assert o.a.x.long_name == "Test Outer A Inner X" + assert o.a.y.long_name == "Test Outer A y" + assert o.b.x.long_name == "Test b Inner X" + assert o.b.y.long_name == "Test b y" + def test_create_device(): components = dict( From 884bf05923b1ac65056d49f81fd6499b1c6a8679 Mon Sep 17 00:00:00 2001 From: Charles Titus Date: Thu, 1 Aug 2024 10:11:25 -0400 Subject: [PATCH 6/6] STY: Fixed comma --- ophyd/signal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ophyd/signal.py b/ophyd/signal.py index 5721ad182..617803928 100644 --- a/ophyd/signal.py +++ b/ophyd/signal.py @@ -2273,7 +2273,7 @@ def describe(self): "source": "PY:{}.{}".format(self.parent.name, self.full_attr), "dtype": data_type(value), "shape": data_shape(value), - "long_name": self.long_name + "long_name": self.long_name, } return {self.name: desc}