Skip to content

Commit

Permalink
Merge pull request #312 from spc-group/guarneri
Browse files Browse the repository at this point in the history
Things fixed to work with Guarneri

Also, removed the ``devices`` module and related code.
  • Loading branch information
canismarko authored Dec 5, 2024
2 parents c2697e9 + f8959a5 commit 0ed8d8b
Show file tree
Hide file tree
Showing 41 changed files with 228 additions and 1,619 deletions.
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies:
- pytest-mongodb
- StrEnum
- ophyd-registry >= 1.3.3
- guarneri >= 0.2.0
- xraydb >=4.5.0
- pytest-timeout # Get rid of this if tests are not hanging
- git+https://github.com/pcdshub/pcdsdevices
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ keywords = ["synchrotron", "xray", "bluesky"]
dependencies = ["aioca", "aiokafka", "bluesky", "ophyd", "ophyd-async>=0.8.0a5", "databroker", "apsbss", "xraydb",
"mergedeep", "xrayutilities", "bluesky-queueserver-api", "tomlkit",
"apstools", "databroker", "ophyd-registry", "caproto", "pcdsdevices",
"strenum", "bluesky-adaptive", "tiled[client]"]
"strenum", "bluesky-adaptive", "tiled[client]", "guarneri"]

[project.optional-dependencies]

Expand Down
9 changes: 1 addition & 8 deletions src/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from tiled.server.app import build_app

import haven
from haven._iconfig import beamline_connected as _beamline_connected
from haven.catalog import Catalog
from haven.devices.aps import ApsMachine
from haven.devices.area_detector import AravisDetector
Expand Down Expand Up @@ -44,16 +43,10 @@
)


@pytest.fixture()
def beamline_connected():
with _beamline_connected(True):
yield


@pytest.fixture()
def sim_registry(monkeypatch):
# Save the registry so we can restore it later
registry = haven.beamline.registry
registry = haven.beamline.devices
objects_by_name = registry._objects_by_name
objects_by_label = registry._objects_by_label
registry.clear()
Expand Down
2 changes: 1 addition & 1 deletion src/firefly/area_detector_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AreaDetectorViewerDisplay(display.FireflyDisplay):

def customize_device(self):
device_name = name = self.macros()["AD"]
device = beamline.registry.find(device_name)
device = beamline.devices[device_name]
self.device = device
img_pv = device.pva.pv_name.get(as_string=True)
addr = f"pva://{img_pv}"
Expand Down
6 changes: 3 additions & 3 deletions src/firefly/bss.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def customize_ui(self):
self.ui.refresh_models_button.setIcon(qta.icon("fa5s.sync"))

def customize_device(self):
self._device = beamline.registry.find("beamline_manager")
self._device = beamline.devices["beamline_manager"]

def proposals(self):
config = load_config()
Expand Down Expand Up @@ -143,7 +143,7 @@ def select_proposal(self, current, previous):
def update_proposal(self):
new_id = self._proposal_id
# Change the proposal in the EPICS record
bss = beamline.registry.find("beamline_manager.bss")
bss = beamline.devices["beamline_manager.bss"]
bss.proposal.proposal_id.set(new_id).wait()
# Notify any interested parties that the proposal has been changed
self.proposal_changed.emit()
Expand All @@ -160,7 +160,7 @@ def select_esaf(self, current, previous):
def update_esaf(self):
new_id = self._esaf_id
# Change the esaf in the EPICS record
bss = beamline.registry.find("beamline_manager.bss")
bss = beamline.devices["beamline_manager.bss"]
bss.wait_for_connection()
bss.esaf.esaf_id.set(new_id).wait(timeout=5)
# Notify any interested parties that the esaf has been changed
Expand Down
11 changes: 6 additions & 5 deletions src/firefly/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from qtpy.QtWidgets import QAction, QErrorMessage

from haven import beamline, load_config
from haven.device import titelize
from haven.exceptions import ComponentNotFound, InvalidConfiguration
from haven.utils import titleize

from .action import Action, ActionsRegistry, WindowAction
from .kafka_client import KafkaClient
Expand Down Expand Up @@ -77,7 +77,7 @@ def __init__(self, parent=None, display="status", use_main_window=False):
self.actions = ActionsRegistry()
self.windows = OrderedDict()
self.queue_re_state_changed.connect(self.enable_queue_controls)
self.registry = beamline.registry
self.registry = beamline.devices
# An error message dialog for later use
self.error_message = QErrorMessage()

Expand Down Expand Up @@ -112,15 +112,16 @@ async def setup_instrument(self, load_instrument=True):
"""
if load_instrument:
beamline.load()
try:
await beamline.load()
await beamline.connect()
except NotConnected as exc:
log.exception(exc)
msg = (
"One or more devices failed to load. See console logs for details."
)
self.error_message.showMessage(msg)
self.registry_changed.emit(beamline.registry)
self.registry_changed.emit(beamline.devices)
# Make actions for launching other windows
self.setup_window_actions()
# Actions for controlling the bluesky run engine
Expand Down Expand Up @@ -501,7 +502,7 @@ def device_actions(
actions = {
device.name: WindowAction(
name=f"show_{device.name}_action",
text=titelize(device.name),
text=titleize(device.name),
display_file=display_file,
icon=icon,
WindowClass=WindowClass,
Expand Down
2 changes: 1 addition & 1 deletion src/firefly/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def customize_device(self):
# Retrieve the device
device = self.macros().get("DEVICE")
if device is not None:
device = beamline.registry.find(device)
device = beamline.devices[device]
self.device = device
return device

Expand Down
2 changes: 1 addition & 1 deletion src/firefly/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(self, args=None, macros={}, **kwargs):

def customize_device(self):
try:
self.energy_positioner = beamline.registry.find("energy")
self.energy_positioner = beamline.devices["energy"]
except ComponentNotFound:
warnings.warn("Could not find energy positioner.")
log.warning("Could not find energy positioner.")
Expand Down
2 changes: 1 addition & 1 deletion src/firefly/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def ui_filename(self):
return "filters.ui"

def customize_device(self):
filters = beamline.registry.findall(label="filters", allow_none=True)
filters = beamline.devices.findall(label="filters", allow_none=True)
self.filters = sorted(
filters, key=lambda dev: (dev.material.get(), dev.thickness.get())
)
Expand Down
2 changes: 1 addition & 1 deletion src/firefly/iocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def customize_ui(self):
self.iocs_layout.takeAt(idx).widget().deleteLater()
# Add embedded displays for all the ion chambers
self._ioc_displays = []
manager = beamline.registry["beamline_manager"]
manager = beamline.devices["beamline_manager"]

for idx, cpt_name in enumerate(manager.iocs.component_names):
cpt = getattr(manager.iocs, cpt_name)
Expand Down
2 changes: 1 addition & 1 deletion src/firefly/ion_chamber.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class IonChamberDisplay(display.FireflyDisplay):
"""A GUI window for changing settings in an ion chamber."""

def customize_device(self):
self._device = beamline.registry.find(self.macros()["IC"])
self._device = beamline.devices[self.macros()["IC"]]

def customize_ui(self):
# Use qtawesome icons instead of unicode arrows
Expand Down
4 changes: 2 additions & 2 deletions src/firefly/pydm_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def find_signal(self, address: str):
Signal
The Ophyd signal corresponding to the address.
"""
return beamline.registry[address]
return beamline.devices[address]


class HavenConnection(RegistryConnection, SignalConnection):
Expand Down Expand Up @@ -161,7 +161,7 @@ class HavenPlugin(SignalPlugin):
def connection_class(channel, address, protocol):
# Check if we need the synchronous or asynchronous version
try:
sig = beamline.registry[address]
sig = beamline.devices[address]
except KeyError:
sig = None
is_ophyd_async = inspect.iscoroutinefunction(getattr(sig, "connect", None))
Expand Down
2 changes: 1 addition & 1 deletion src/firefly/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def add_shutter_widgets(self):
form.removeRow(self.ui.shutter_A_layout)
form.removeRow(self.ui.shutter_CD_layout)
# Add widgets for shutters
shutters = beamline.registry.findall("shutters", allow_none=True)
shutters = beamline.devices.findall("shutters", allow_none=True)
row_idx = 4
on_color = self.ui.shutter_permit_indicator.onColor
off_color = self.ui.shutter_permit_indicator.offColor
Expand Down
2 changes: 1 addition & 1 deletion src/firefly/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def ui_file(self):

class TableDisplay(display.FireflyDisplay):
def customize_device(self):
self.device = beamline.registry.find(self.macros()["DEVICE"])
self.device = beamline.devices[self.macros()["DEVICE"]]
# Determine which flavor of caQtDM parameters we need
if self.num_legs == 2:
self.caqtdm = TwoLegCaQtDM(table=self.device)
Expand Down
2 changes: 1 addition & 1 deletion src/firefly/xrf_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def handle_new_spectrum(self, new_spectrum, mca_num):
def customize_device(self):
# Load the device from the registry
device_name = self.macros()["DEV"]
self.device = device = beamline.registry.find(device_name)
self.device = device = beamline.devices[device_name]
# Set up data channels
self._spectrum_channels = []
for mca_num in range(self.device.num_elements):
Expand Down
17 changes: 0 additions & 17 deletions src/haven/_iconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import argparse
import logging
import os
from contextlib import contextmanager
from copy import deepcopy
from pathlib import Path
from pprint import pprint
from typing import Optional, Sequence
Expand Down Expand Up @@ -99,21 +97,6 @@ def print_config_value(args: Sequence[str] = None):
print(value)


@contextmanager
def beamline_connected(is_connected=True):
global _local_overrides
# Save old value
old_dict = deepcopy(_local_overrides)
# Set temporary value
if "beamline" not in _local_overrides.keys():
_local_overrides["beamline"] = {}
_local_overrides["beamline"]["hardware_is_present"] = is_connected
# Return to enclosing code
yield
# Restore old value
_local_overrides = old_dict


# -----------------------------------------------------------------------------
# :author: Mark Wolfman
# :email: [email protected]
Expand Down
Loading

0 comments on commit 0ed8d8b

Please sign in to comment.