From 9ee402f556db5369318286fa16fb47c50407cb9b Mon Sep 17 00:00:00 2001 From: Mark Wolfman Date: Sun, 8 Sep 2024 12:06:25 -0500 Subject: [PATCH 1/4] Ophyd-async support now also register child devices. --- pyproject.toml | 2 +- src/ophydregistry/registry.py | 23 +++++++++++++++---- .../tests/test_instrument_registry.py | 8 +++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 582197d..ff1d042 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ dependencies = ["ophyd"] [project.optional-dependencies] -dev = ["black", "isort", "pytest", "build", "twine", "flake8", "ruff", "pytest-mock", "caproto"] +dev = ["ophyd_async", "black", "isort", "pytest", "build", "twine", "flake8", "ruff", "pytest-mock", "caproto"] [project.urls] "Homepage" = "https://github.com/spc-group/ophyd-registry" diff --git a/src/ophydregistry/registry.py b/src/ophydregistry/registry.py index 905af9f..e40a94a 100644 --- a/src/ophydregistry/registry.py +++ b/src/ophydregistry/registry.py @@ -3,7 +3,7 @@ import warnings from collections import OrderedDict from itertools import chain -from typing import Hashable, List, Mapping, Optional, Tuple, Sequence +from typing import Hashable, List, Mapping, Optional, Sequence, Tuple from weakref import WeakSet, WeakValueDictionary from ophyd import ophydobj @@ -126,7 +126,11 @@ class Registry: use_typhos: bool keep_references: bool _auto_register: bool - _valid_classes: Tuple[type] = (ophydobj.OphydObject, _AggregateSignalState, AsyncDevice) + _valid_classes: Tuple[type] = ( + ophydobj.OphydObject, + _AggregateSignalState, + AsyncDevice, + ) # components: Sequence _objects_by_name: Mapping @@ -255,7 +259,9 @@ def pop_disconnected(self, timeout: float = 0.0) -> List: timeout_reached = False while not timeout_reached: # Remove any connected devices for the running list - remaining = [dev for dev in remaining if not getattr(dev, "connected", True)] + remaining = [ + dev for dev in remaining if not getattr(dev, "connected", True) + ] if len(remaining) == 0: # All devices are connected, so just end early. break @@ -584,7 +590,14 @@ def register( typhos.plugins.register_signal(component) # Recusively register sub-components - sub_signals = getattr(component, "_signals", {}) - for cpt_name, cpt in sub_signals.items(): + if hasattr(component, "_signals"): + # Vanilla ophyd device + sub_signals = component._signals.items() + elif hasattr(component, "children"): + # Ophyd-async device + sub_signals = component.children() + else: + sub_signals = [] + for cpt_name, cpt in sub_signals: self.register(cpt) return component diff --git a/src/ophydregistry/tests/test_instrument_registry.py b/src/ophydregistry/tests/test_instrument_registry.py index 54590f2..6293efe 100644 --- a/src/ophydregistry/tests/test_instrument_registry.py +++ b/src/ophydregistry/tests/test_instrument_registry.py @@ -6,6 +6,7 @@ import pytest from ophyd import Device, EpicsMotor, sim +from ophyd_async.epics.motor import Motor from ophydregistry import ComponentNotFound, MultipleComponentsFound, Registry @@ -143,6 +144,13 @@ def test_find_component(registry): result = registry.find(label="ion_chamber") +def test_find_async_children(registry): + """Check that the child components of an async device get registered.""" + motor = Motor(prefix="255idcVME:m1", name="m1") + registry.register(motor) + assert registry.find(motor.user_setpoint.name) is motor.user_setpoint + + def test_find_name_by_dot_notation(registry): # Create a simulated component cptA = sim.SynGauss( From a099f01c4c231f28a7e5f210b575e52a4c7c99f2 Mon Sep 17 00:00:00 2001 From: Mark Wolfman Date: Sun, 8 Sep 2024 12:27:25 -0500 Subject: [PATCH 2/4] Removed python<3.10 from CI since ophyd-async doesn't support it. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a14572e..a21609d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] + python-version: ["3.10", "3.11"] steps: - uses: actions/checkout@v3 From 5ab98bf2669b02c8be9176ca643816d34867a584 Mon Sep 17 00:00:00 2001 From: Mark Wolfman Date: Sun, 8 Sep 2024 12:40:10 -0500 Subject: [PATCH 3/4] Updated test to not require aioca. --- src/ophydregistry/tests/test_instrument_registry.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ophydregistry/tests/test_instrument_registry.py b/src/ophydregistry/tests/test_instrument_registry.py index 6293efe..9bc0ae6 100644 --- a/src/ophydregistry/tests/test_instrument_registry.py +++ b/src/ophydregistry/tests/test_instrument_registry.py @@ -6,7 +6,7 @@ import pytest from ophyd import Device, EpicsMotor, sim -from ophyd_async.epics.motor import Motor +from ophyd_async.core import Device as AsyncDevice, soft_signal_rw from ophydregistry import ComponentNotFound, MultipleComponentsFound, Registry @@ -146,9 +146,14 @@ def test_find_component(registry): def test_find_async_children(registry): """Check that the child components of an async device get registered.""" - motor = Motor(prefix="255idcVME:m1", name="m1") - registry.register(motor) - assert registry.find(motor.user_setpoint.name) is motor.user_setpoint + class MyDevice(AsyncDevice): + def __init__(self, name): + self.signal = soft_signal_rw() + super().__init__(name=name) + + device = MyDevice(name="m1") + registry.register(device) + assert registry.find(device.signal.name) is device.signal def test_find_name_by_dot_notation(registry): From 5cd440e4a27438d345ace1aa4b75c66926cf1fa1 Mon Sep 17 00:00:00 2001 From: Mark Wolfman Date: Sun, 8 Sep 2024 12:42:14 -0500 Subject: [PATCH 4/4] Version bump to 1.3.3 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ff1d042..a7c7c03 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "ophyd-registry" -version = "1.3.2" +version = "1.3.3" authors = [ { name="Mark Wolfman", email="wolfman@anl.gov" }, ]