Skip to content

Commit

Permalink
Merge pull request #166 from spc-group/black
Browse files Browse the repository at this point in the history
Enforce black formatting during CI.
  • Loading branch information
canismarko authored Feb 15, 2024
2 parents b49189a + c0d218c commit 688141f
Show file tree
Hide file tree
Showing 34 changed files with 203 additions and 137 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ jobs:
isort --check src/
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Enforce formatting with black
run: |
black --check src/
- name: Licensing
run: |
# Check that the license snippet is in each python source
find src/ -type f -name "*.py" -exec grep -H -c 'Copyright © 2023, UChicago Argonne, LLC' {} \; | grep 0$ | cut -d':' -f1
- name: Test with pytest in Xvfb
run: xvfb-run python -m pytest -vv --timeout=120
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies:
- numba>=0.56 # Ensures 0.53 (broken) isn't installed

# --- testing and quality assurance
- black >=22.1
- black >=24
- flake8
- pre-commit
- pylint
Expand Down
14 changes: 9 additions & 5 deletions src/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,15 @@ def blade_slits(sim_registry):
def aperture_slits(sim_registry):
"""A fake slit assembling using the rotary aperture design."""
FakeSlits = make_fake_device(ApertureSlits)
slits = FakeSlits( prefix="255ida:slits:US:",
name="whitebeam_slits", pitch_motor="m3",
yaw_motor="m4",
horizontal_motor="m1",
diagonal_motor="m2", labels={"slits"})
slits = FakeSlits(
prefix="255ida:slits:US:",
name="whitebeam_slits",
pitch_motor="m3",
yaw_motor="m4",
horizontal_motor="m1",
diagonal_motor="m2",
labels={"slits"},
)
sim_registry.register(slits)
return slits

Expand Down
3 changes: 1 addition & 2 deletions src/firefly/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,7 @@ def show_device_window(
FireflyMainWindow,
ui_dir / ui_file,
name=f"FireflyMainWindow_{device_label}_{device_pyname}",
macros={device_key: device.name,
f"{device_key}_TITLE": device_title},
macros={device_key: device.name, f"{device_key}_TITLE": device_title},
)

def show_status_window(self, stylesheet_path=None):
Expand Down
4 changes: 3 additions & 1 deletion src/firefly/area_detector_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@


class AreaDetectorViewerDisplay(display.FireflyDisplay):
caqtdm_ui_file: str = "/APSshare/epics/synApps_6_2_1/support/areaDetector-R3-12-1/ADAravis/aravisApp/op/ui/autoconvert/ADAravis.ui"
caqtdm_ui_file: str = (
"/APSshare/epics/synApps_6_2_1/support/areaDetector-R3-12-1/ADAravis/aravisApp/op/ui/autoconvert/ADAravis.ui"
)
image_is_new: bool = True

def customize_device(self):
Expand Down
13 changes: 10 additions & 3 deletions src/firefly/beamline_components_rc.py
Original file line number Diff line number Diff line change
Expand Up @@ -37515,18 +37515,25 @@
\x00\x00\x01\x8c\x36\xca\xef\xee\
"

qt_version = [int(v) for v in QtCore.qVersion().split('.')]
qt_version = [int(v) for v in QtCore.qVersion().split(".")]
if qt_version < [5, 8, 0]:
rcc_version = 1
qt_resource_struct = qt_resource_struct_v1
else:
rcc_version = 2
qt_resource_struct = qt_resource_struct_v2


def qInitResources():
QtCore.qRegisterResourceData(rcc_version, qt_resource_struct, qt_resource_name, qt_resource_data)
QtCore.qRegisterResourceData(
rcc_version, qt_resource_struct, qt_resource_name, qt_resource_data
)


def qCleanupResources():
QtCore.qUnregisterResourceData(rcc_version, qt_resource_struct, qt_resource_name, qt_resource_data)
QtCore.qUnregisterResourceData(
rcc_version, qt_resource_struct, qt_resource_name, qt_resource_data
)


qInitResources()
5 changes: 3 additions & 2 deletions src/firefly/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ class FireflyDisplay(Display):
status_message_changed = Signal(str, int)

def __init__(self, parent=None, args=None, macros=None, ui_filename=None, **kwargs):
super().__init__(parent=parent, args=args, macros=macros,
ui_filename=ui_filename, **kwargs )
super().__init__(
parent=parent, args=args, macros=macros, ui_filename=ui_filename, **kwargs
)
self.customize_device()
self.customize_ui()
self.prepare_caqtdm_actions()
Expand Down
8 changes: 6 additions & 2 deletions src/firefly/ion_chamber.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ class IonChamberDisplay(display.FireflyDisplay):
"""A GUI window for changing settings in an ion chamber."""

caqtdm_scaler_ui_file: str = "/net/s25data/xorApps/ui/scaler32_full_offset.ui"
caqtdm_mcs_ui_file: str = "/APSshare/epics/synApps_6_2_1/support/mca-R7-9//mcaApp/op/ui/autoconvert/SIS38XX.ui"
caqtdm_preamp_ui_file: str = "/net/s25data/xorApps/epics/synApps_6_2_1/support/ip-GIT/ipApp/op/ui/autoconvert/SR570.ui"
caqtdm_mcs_ui_file: str = (
"/APSshare/epics/synApps_6_2_1/support/mca-R7-9//mcaApp/op/ui/autoconvert/SIS38XX.ui"
)
caqtdm_preamp_ui_file: str = (
"/net/s25data/xorApps/epics/synApps_6_2_1/support/ip-GIT/ipApp/op/ui/autoconvert/SR570.ui"
)

def customize_device(self):
self._device = registry.find(self.macros()["IC"])
Expand Down
24 changes: 14 additions & 10 deletions src/firefly/kb_mirrors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class KBMirrorsDisplay(SlitsDisplay):

@property
def caqtdm_ui_file(self):
# Go up the class list until we find a class that is recognized
Expand Down Expand Up @@ -37,9 +36,10 @@ def launch_caqtdm(self):
KB = pieces[-1]
KBH = self.device.horiz.prefix.replace(P, "").strip(":")
KBV = self.device.vert.prefix.replace(P, "").strip(":")

def suffix(signal):
return signal.prefix.split(":")[-1]

caqtdm_macros = {
"P": f"{P}",
"PM": P,
Expand All @@ -58,16 +58,20 @@ def suffix(signal):
# Macros for each mirror's bender motors
horiz = self.device.horiz
if horiz.bendable:
caqtdm_macros.update({
"HBUS": suffix(horiz.bender_upstream),
"HBDS": suffix(horiz.bender_downstream),
})
caqtdm_macros.update(
{
"HBUS": suffix(horiz.bender_upstream),
"HBDS": suffix(horiz.bender_downstream),
}
)
vert = self.device.vert
if vert.bendable:
caqtdm_macros.update({
"VBUS": suffix(vert.bender_upstream),
"VBDS": suffix(vert.bender_downstream),
})
caqtdm_macros.update(
{
"VBUS": suffix(vert.bender_upstream),
"VBDS": suffix(vert.bender_downstream),
}
)
# Launch the caQtDM panel
super(SlitsDisplay, self).launch_caqtdm(macros=caqtdm_macros)

Expand Down
2 changes: 1 addition & 1 deletion src/firefly/plans/count.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def queue_plan(self, *args, **kwargs):
delay = self.ui.delay_spinbox.value()
detectors = self.ui.detectors_list.selected_detectors()
# Build the queue item

item = BPlan("count", delay=delay, num=num_readings, detectors=detectors)
# Submit the item to the queueserver
from firefly.application import FireflyApplication
Expand Down
4 changes: 3 additions & 1 deletion src/firefly/pydm_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
class HavenConnection(SignalConnection):
def __init__(self, channel, address, protocol=None, parent=None):
# Create base connection
super(SignalConnection, self).__init__(channel, address, protocol=protocol, parent=parent)
super(SignalConnection, self).__init__(
channel, address, protocol=protocol, parent=parent
)
self._connection_open = True
self.signal_type = None
self.is_float = False
Expand Down
17 changes: 10 additions & 7 deletions src/firefly/slits.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ def caqtdm_ui_file(self):
except KeyError:
continue
# We didn't find any supported classes of slits
msg = ("Could not find caQtDM filename for optic "
f"{self.device.name} ({self.device.__class__}).")
msg = (
"Could not find caQtDM filename for optic "
f"{self.device.name} ({self.device.__class__})."
)
warnings.warn(msg)
log.warning(msg)
return ""


def launch_caqtdm(self):
# Sort out the prefix from the slit designator
Expand All @@ -56,10 +57,12 @@ def launch_caqtdm(self):
"SLITS": SLIT,
}
# Add extra motors if applicable
motors = {"HOR": "horizontal",
"DIAG": "diagonal",
"YAW": "yaw",
"PITCH": "pitch"}
motors = {
"HOR": "horizontal",
"DIAG": "diagonal",
"YAW": "yaw",
"PITCH": "pitch",
}
for key, attr in motors.items():
print(key, attr)
if not hasattr(self.device, attr):
Expand Down
32 changes: 20 additions & 12 deletions src/firefly/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
from firefly import display


class CaQtDMBase():
class CaQtDMBase:
"""caQtDM parameters for the given table.
Different table geometries require different caQtDM
configurations.
"""

ui_file: str = ""
macros: Mapping = {}
table: Table
Expand All @@ -33,6 +34,7 @@ def motor_attrs(self):

class TwoLegCaQtDM(CaQtDMBase):
"""caQtDM parameters for a table with two ."""

ui_file = "/net/s25data/xorApps/ui/table_2leg.ui"

@property
Expand All @@ -53,6 +55,7 @@ def macros(self):

class SingleMotorCaQtDM(CaQtDMBase):
"""caQtDM parameters for a table with only a single motor."""

ui_file = "/APSshare/epics/synApps_6_2_1/support/motor-R7-2-2//motorApp/op/ui/autoconvert/motorx.ui"

@property
Expand All @@ -69,20 +72,21 @@ class MultipleMotorCaQtDM(CaQtDMBase):

@property
def ui_file(self):
ui_dir = Path("/APSshare/epics/synApps_6_2_1/support/motor-R7-2-2//motorApp/op/ui/autoconvert/")
ui_dir = Path(
"/APSshare/epics/synApps_6_2_1/support/motor-R7-2-2//motorApp/op/ui/autoconvert/"
)
num_motors = len(self.motor_attrs())
ui_path = ui_dir / f"motor{num_motors}x.ui"
return str(ui_path)


@property
def macros(self):
# Look for which motor is present on this table device
macros = {}
for idx, name in enumerate(self.motor_attrs()):
component = getattr(self.table.__class__, name)
key = f"M{idx+1}"
macros[key] = component.suffix
macros[key] = component.suffix
return macros


Expand All @@ -95,9 +99,11 @@ def customize_device(self):
elif self.num_motors == 1:
self.caqtdm = SingleMotorCaQtDM(table=self.device)
elif self.num_motors > 1:
self.caqtdm = MultipleMotorCaQtDM(table=self.device)
self.caqtdm = MultipleMotorCaQtDM(table=self.device)
else:
warnings.warn(f"Could not determine caQtDM parameters for device: {self.device}.")
warnings.warn(
f"Could not determine caQtDM parameters for device: {self.device}."
)
self.caqtdm = CaQtDMBase(table=self.device)

def ui_filename(self):
Expand All @@ -106,7 +112,7 @@ def ui_filename(self):
@property
def caqtdm_ui_file(self):
return self.caqtdm.ui_file

@property
def num_legs(self):
"""How motorized legs does this table have?
Expand All @@ -119,14 +125,14 @@ def num_legs(self):
leg_names = {"upstream", "downstream"}
num_legs = len(list(set(self.device.component_names) & leg_names))
return num_legs

@property
def num_motors(self):
"""How many motors does this table have?
Does not include the pseudo motors produce through the
sum2Diff EPICS record.
"""
motor_names = {"horizontal", "vertical", "upstream", "downstream"}
num_motors = len(list(set(self.device.component_names) & motor_names))
Expand All @@ -136,8 +142,10 @@ def customize_ui(self):
# Disable motor controls if the given axis is not available
self.ui.pitch_embedded_display.setEnabled(hasattr(self.device, "pitch"))
self.ui.vertical_embedded_display.setEnabled(hasattr(self.device, "vertical"))
self.ui.horizontal_embedded_display.setEnabled(hasattr(self.device, "horizontal"))

self.ui.horizontal_embedded_display.setEnabled(
hasattr(self.device, "horizontal")
)

def launch_caqtdm(self):
# Sort out the prefix from the slit designator
prefix = self.device.prefix.strip(":")
Expand Down
1 change: 0 additions & 1 deletion src/firefly/tests/test_kb_mirrors.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def test_bender_widgets(ffapp, kb_bendable_mirrors):
assert disp.ui.horizontal_downstream_display.isEnabled()
assert disp.ui.vertical_upstream_display.isEnabled()
assert disp.ui.vertical_downstream_display.isEnabled()



def test_kb_mirrors_caqtdm(display, kb_mirrors):
Expand Down
4 changes: 3 additions & 1 deletion src/firefly/tests/test_motor_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ def fake_motors(sim_registry):
motor_names = ["motorA", "motorB", "motorC"]
motors = []
for name in motor_names:
this_motor = make_fake_device(motor.HavenMotor)(name=name, labels={"extra_motors"})
this_motor = make_fake_device(motor.HavenMotor)(
name=name, labels={"extra_motors"}
)
sim_registry.register(this_motor)
motors.append(this_motor)
print(sim_registry.device_names)
Expand Down
8 changes: 5 additions & 3 deletions src/firefly/tests/test_pydm_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@

from firefly.pydm_plugin import HavenPlugin


def test_plugin_registered(ffapp):
assert "haven" in ffapp.plugins.keys()
plugin = plugin_for_address("haven://")
assert isinstance(plugin, HavenPlugin)


def test_signal_connection(qapp, qtbot, sim_registry):
# Create a signal and attach our listener
sig = Signal(name='my_signal', value=1)
sig = Signal(name="my_signal", value=1)
sim_registry.register(sig)
widget = PyDMLineEdit()
qtbot.addWidget(widget)
widget.channel = 'haven://my_signal'
widget.channel = "haven://my_signal"
listener = widget.channels()[0]
# If PyDMChannel can not connect, we need to connect it ourselves
# In PyDM > 1.5.0 this will not be neccesary as the widget will be
# connected after we set the channel name
if not hasattr(listener, 'connect'):
if not hasattr(listener, "connect"):
pydm.utilities.establish_widget_connections(widget)
# Check that our widget receives the initial value
qapp.processEvents()
Expand Down
Loading

0 comments on commit 688141f

Please sign in to comment.