Skip to content

Commit 4d73c99

Browse files
committed
ruff format and auto fixes
1 parent 8b36dcf commit 4d73c99

File tree

3 files changed

+40
-20
lines changed

3 files changed

+40
-20
lines changed

installation_and_upgrade/calibration_files_updater.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
import subprocess
1010

1111
import git
12+
from epics import caget
1213
from six.moves import input
14+
1315
from ibex_install_utils.file_utils import FileUtils
14-
from epics import caget
1516

1617
FNULL = open(os.devnull, "w")
1718

@@ -77,7 +78,12 @@ def get_instrument_hosts():
7778
"""
7879
Returns: A collection of instrument host names
7980
"""
80-
return (inst["hostName"] for inst in json.loads(FileUtils.dehex_and_decompress(caget("CS:INSTLIST").tobytes().decode().rstrip('\x00'))))
81+
return (
82+
inst["hostName"]
83+
for inst in json.loads(
84+
FileUtils.dehex_and_decompress(caget("CS:INSTLIST").tobytes().decode().rstrip("\x00"))
85+
)
86+
)
8187

8288

8389
def update_instrument(host, username, password, logger, dry_run=False):

installation_and_upgrade/ibex_install_utils/ca_utils.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import json
22
import zlib
33
from ast import literal_eval
4-
from typing import Any
54
from socket import gethostname
5+
from typing import Any
6+
7+
from epics import caget, caput
68

79
from ibex_install_utils.file_utils import FileUtils
810

9-
import epicscorelibs.path.pyepics
10-
from epics import caget, caput
1111

1212
def crc8(value: str) -> str:
1313
"""
@@ -44,6 +44,7 @@ def crc8(value: str) -> str:
4444

4545
return "{0:02X}".format(crc)
4646

47+
4748
def dehex_and_decompress(value: bytes | str) -> str:
4849
"""
4950
Dehex and decompress a string and return it
@@ -65,6 +66,7 @@ def dehex_decompress_and_dejson(value: str | bytes) -> Any: # No known type
6566
"""
6667
return json.loads(dehex_and_decompress(value))
6768

69+
6870
def _get_pv_prefix(instrument: str, is_instrument: bool) -> str:
6971
"""
7072
Create the pv prefix based on instrument name and whether it is an
@@ -89,13 +91,11 @@ def _get_pv_prefix(instrument: str, is_instrument: bool) -> str:
8991
pv_prefix_prefix = "IN"
9092
else:
9193
pv_prefix_prefix = "TE"
92-
return "{prefix}:{instrument}:".format(
93-
prefix=pv_prefix_prefix, instrument=instrument_name
94-
)
94+
return "{prefix}:{instrument}:".format(prefix=pv_prefix_prefix, instrument=instrument_name)
9595

9696

9797
def get_machine_details_from_identifier(
98-
machine_identifier: str | None = None
98+
machine_identifier: str | None = None,
9999
) -> tuple[str, str, str]:
100100
"""
101101
Gets the details of a machine by looking it up in the instrument list first.
@@ -125,26 +125,26 @@ def get_machine_details_from_identifier(
125125
# that's been passed to this function if it is not found instrument_details will be None
126126
instrument_details = None
127127
try:
128-
instrument_list = dehex_decompress_and_dejson(caget("CS:INSTLIST").tobytes().decode().rstrip('\x00'))
128+
instrument_list = dehex_decompress_and_dejson(
129+
caget("CS:INSTLIST").tobytes().decode().rstrip("\x00")
130+
)
129131
instrument_details = next(
130132
(inst for inst in instrument_list if inst["pvPrefix"] == machine_identifier), None
131133
)
132134
except AttributeError:
133-
print(
134-
"Error getting instlist, \nContinuing execution..."
135-
)
135+
print("Error getting instlist, \nContinuing execution...")
136136

137137
if instrument_details is not None:
138138
instrument = instrument_details["name"]
139139
else:
140140
instrument = machine_identifier.upper()
141141
for p in (
142-
[instrument_pv_prefix, test_machine_pv_prefix]
143-
+ instrument_machine_prefixes
144-
+ test_machine_prefixes
142+
[instrument_pv_prefix, test_machine_pv_prefix]
143+
+ instrument_machine_prefixes
144+
+ test_machine_prefixes
145145
):
146146
if machine_identifier.startswith(p):
147-
instrument = machine_identifier.upper()[len(p):].rstrip(":")
147+
instrument = machine_identifier.upper()[len(p) :].rstrip(":")
148148
break
149149

150150
if instrument_details is not None:

installation_and_upgrade/ibex_install_utils/motor_params.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
Script to extract information from motors to be consumed by the motion controls team. Exports data as CSV. To run,
33
load the script into a genie_python console and run as a standard user script.
44
"""
5+
56
import csv
6-
from aioca import caget, CANothing
7+
8+
from aioca import CANothing, caget
9+
710
from ibex_install_utils.ca_utils import get_machine_details_from_identifier
811

912
VELOCITY_UNITS = "EGU per sec"
@@ -106,6 +109,7 @@
106109
TL: "_TL_SP",
107110
}
108111

112+
109113
async def get_params_and_save_to_file(file_reference, num_of_controllers=8):
110114
"""
111115
Gets all the motor parameters and saves them to an open file reference as a csv.
@@ -125,8 +129,18 @@ async def get_params_and_save_to_file(file_reference, num_of_controllers=8):
125129
rows = []
126130

127131
for axis_pv in list_of_axis_pvs:
128-
hr_keys = [axis_pv] + [i for i in all_motor_params.keys()] + [i for i in galil_specific_params.keys()]
129-
hr_values = await caget([axis_pv] + [axis_pv + i for i in all_motor_params.values()] + [axis_pv + i for i in galil_specific_params.values()], throw=False, timeout=0.1)
132+
hr_keys = (
133+
[axis_pv]
134+
+ [i for i in all_motor_params.keys()]
135+
+ [i for i in galil_specific_params.keys()]
136+
)
137+
hr_values = await caget(
138+
[axis_pv]
139+
+ [axis_pv + i for i in all_motor_params.values()]
140+
+ [axis_pv + i for i in galil_specific_params.values()],
141+
throw=False,
142+
timeout=0.1,
143+
)
130144

131145
if all(isinstance(i, CANothing) for i in hr_values):
132146
# All PVs failed to connect so don't bother writing this axis

0 commit comments

Comments
 (0)