Skip to content

Commit cb9df61

Browse files
committed
latest ruff checks fixed
1 parent bb4d0b6 commit cb9df61

File tree

9 files changed

+30
-36
lines changed

9 files changed

+30
-36
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ line-length = 88
104104
# ignoring line to long for the moment to avoid signficant changes to the code
105105
lint.ignore = [
106106
"E501", # line too long
107+
"E721", # use isinstance instead of compare to type
107108
]
108109
lint.select = [
109110
"B", # flake8-bugbear - https://docs.astral.sh/ruff/rules/#flake8-bugbear-b

src/dls_pmac_control/__main__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def remoteConnect(self):
283283
# Find out the type of the PMAC
284284
pmac_model_str = self.pmac.getPmacModel()
285285
if pmac_model_str:
286-
self.setWindowTitle("Delta Tau motor controller - %s" % pmac_model_str)
286+
self.setWindowTitle(f"Delta Tau motor controller - {pmac_model_str}")
287287
else:
288288
QMessageBox.information(self, "Error", "Could not determine PMAC model")
289289
return
@@ -434,7 +434,7 @@ def killMotor(self):
434434
# see TURBO SRM page 289
435435
def killAllMotors(self):
436436
# print "killing all motors!"
437-
command = "\x0B"
437+
command = "\x0b"
438438
(returnString, status) = self.pmac.sendCommand(command)
439439
self.addToTxtShell("CTRL-K")
440440

@@ -860,7 +860,7 @@ def updateIdentity(self, id):
860860
if subdomainNum != 0:
861861
text += "%02d" % subdomainNum
862862
text += self.subdomainLetters[domain][subdomainLetter]
863-
text += " %s " % self.pmac.getShortModelName()
863+
text += f" {self.pmac.getShortModelName()} "
864864
text += "%d" % pmacNum
865865
self.lblIdentity.setText(text)
866866

src/dls_pmac_control/axissettings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def setAxisSetupDirect(self, directCmd, newValue):
391391
self.setAxisSetupVars(varStr, newValue)
392392

393393
def setAxisSetupVars(self, varStr, newValue):
394-
cmd = ("Motor[%d]." % self.currentMotor) + varStr + ("=%s" % newValue)
394+
cmd = ("Motor[%d]." % self.currentMotor) + varStr + (f"={newValue}")
395395
(retStr, success) = self.parent.pmac.sendCommand(cmd)
396396
if success:
397397
self.axisUpdate()

src/dls_pmac_control/commsThread.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def updateFunc(self):
107107
self.gen.close()
108108
self.sendComplete("Download cancelled by the user")
109109
else:
110-
print("WARNING: don't know what to do with cmd %s" % cmd)
110+
print(f"WARNING: don't know what to do with cmd {cmd}")
111111
if self.parent.pmac is None or not self.parent.pmac.isConnectionOpen:
112112
time.sleep(0.1)
113113
return
@@ -143,18 +143,15 @@ def updateFunc(self):
143143
if isinstance(self.parent.pmac, PmacSerialInterface) and self.max_pollrate:
144144
if time.time() - self.parent.pmac.last_comm_time < 1.0 / self.max_pollrate:
145145
return
146-
cmd = "i65???&%s??%%" % self.CSNum
146+
cmd = f"i65???&{self.CSNum}??%"
147147
# Send a different command for the Power PMAC
148148
if isinstance(self.parent.pmac, PPmacSshInterface):
149149
# The %% is because % needs escaping - only one % is actually sent
150150
# There has to be a space before the first BrickLV string to avoid its B being interpreted as a 'begin' command
151-
cmd = (
152-
"i65?&%s?%% BrickLV.BusUnderVoltage BrickLV.BusOverVoltage BrickLV.OverTemp"
153-
% self.CSNum
154-
)
151+
cmd = f"i65?&{self.CSNum}?% BrickLV.BusUnderVoltage BrickLV.BusOverVoltage BrickLV.OverTemp"
155152
elif isinstance(self.parent.pmac, PmacEthernetInterface):
156153
# Add the 7 segment display status query
157-
cmd = "i65???&%s??%%" % self.CSNum
154+
cmd = f"i65???&{self.CSNum}??%"
158155
axes = self.parent.pmac.getNumberOfAxes() + 1
159156
for motorNo in range(1, axes):
160157
cmd = cmd + "#" + str(motorNo) + "?PVF "
@@ -199,9 +196,7 @@ def updateFunc(self):
199196
# fourth is the PMAC identity
200197
if valueList[0].startswith("\x07"):
201198
# error, probably in buffer
202-
print(
203-
"i65 returned %s, sending CLOSE command" % valueList[0].__repr__()
204-
)
199+
print(f"i65 returned {valueList[0].__repr__()}, sending CLOSE command")
205200
self.parent.pmac.sendCommand("CLOSE")
206201
return
207202

@@ -217,9 +212,9 @@ def updateFunc(self):
217212
# Global status
218213
self.resultQueue.put([valueList[1], 0, 0, 0, 0, 0, "G"])
219214
# CS status
220-
self.resultQueue.put([valueList[2], 0, 0, 0, 0, 0, "CS%s" % self.CSNum])
215+
self.resultQueue.put([valueList[2], 0, 0, 0, 0, 0, f"CS{self.CSNum}"])
221216
# Fedrate
222-
self.resultQueue.put([valueList[3], 0, 0, 0, 0, 0, "FEED%s" % self.CSNum])
217+
self.resultQueue.put([valueList[3], 0, 0, 0, 0, 0, f"FEED{self.CSNum}"])
223218

224219
if isinstance(self.parent.pmac, PPmacSshInterface):
225220
# Brick Under Voltage Status
@@ -241,5 +236,5 @@ def updateFunc(self):
241236
evUpdatesReady = CustomEvent(self.parent.updatesReadyEventType, None)
242237
QCoreApplication.postEvent(self.parent, evUpdatesReady)
243238
else:
244-
print('WARNING: Could not poll PMAC for motor status ("%s")' % retStr)
239+
print(f'WARNING: Could not poll PMAC for motor status ("{retStr}")')
245240
time.sleep(0.1)

src/dls_pmac_control/gather.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def gatherConfig(self):
119119
tmpIvar |= 0x01 << bit
120120
if tmpIvar == 0:
121121
return False
122-
cmd = "i5051=0 i5050=$%x" % tmpIvar
122+
cmd = f"i5051=0 i5050=${tmpIvar:x}"
123123
self.parent.pmac.sendCommand(cmd)
124124

125125
# Clear the plot by setting empty plotitems
@@ -336,7 +336,7 @@ def calcSampleTime(self):
336336
# gathering function
337337
self.sampleTime = self.nServoCyclesGather * self.servoCycleTime
338338
realSampleFreq = 1.0 / self.sampleTime
339-
self.txtLblFreq.setText("%.3f kHz" % realSampleFreq)
339+
self.txtLblFreq.setText(f"{realSampleFreq:.3f} kHz")
340340
self.txtLblSignalLen.setText("%.2f ms" % (self.sampleTime * self.nGatherPoints))
341341

342342
# ############## button clicked slots from here
@@ -447,6 +447,6 @@ def saveClicked(self):
447447
for lineNo, lineData in enumerate(zip(*dataLists)):
448448
line = "%d," % lineNo
449449
for data_point in lineData:
450-
line += "%f," % data_point
450+
line += f"{data_point:f},"
451451
fptr.write(line + "\n")
452452
fptr.close()

src/dls_pmac_control/gatherchannel.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def getDataInfo(self):
155155
self.dataWidth = LONGWORD
156156
self.dataType = float
157157
else:
158-
print("### Error: Could not get data width and type from: %s" % (retStr))
158+
print(f"### Error: Could not get data width and type from: {retStr}")
159159

160160
# Figure out what data the address point to
161161
dataAddr = int(retStr[2:-1], 16)
@@ -166,7 +166,7 @@ def getDataInfo(self):
166166
try:
167167
self.axisNo = motorBaseAddrs.index(mBaseAddr) + 1
168168
except Exception:
169-
print("### Error: could not recognise motor base address: %X" % (mBaseAddr))
169+
print(f"### Error: could not recognise motor base address: {mBaseAddr:X}")
170170

171171
# Get the data source info (unit, scaling algorithm and so on)
172172
for dataSrc in pmacDataSources:
@@ -175,8 +175,7 @@ def getDataInfo(self):
175175
break
176176
if not self.dataSourceInfo:
177177
print(
178-
"### Error: could not recognise data source type with reg offset: %X"
179-
% (self.regOffset)
178+
f"### Error: could not recognise data source type with reg offset: {self.regOffset:X}"
180179
)
181180
return
182181

@@ -227,7 +226,7 @@ def getScalingFactor(self):
227226
ivar = partIvar % self.axisNo
228227
(retStr, status) = self.pmac.sendCommand(ivar)
229228
if not status:
230-
print("### Error: did not receive response to: %s" % ivar)
229+
print(f"### Error: did not receive response to: {ivar}")
231230
return None
232231
# if hex value...
233232
if retStr[0] == "$":
@@ -245,8 +244,7 @@ def getScalingFactor(self):
245244
self.scalingFactor = eval(algorithm)
246245
except Exception:
247246
print(
248-
"### Error: did not evaluate expression correctly. Expr: %s"
249-
% (algorithm)
247+
f"### Error: did not evaluate expression correctly. Expr: {algorithm}"
250248
)
251249
return None
252250

src/dls_pmac_control/ppmacgather.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def calcSampleTime(self):
229229
# gathering function
230230
self.sampleTime = self.nServoCyclesGather * self.servoCycleTime
231231
realSampleFreq = 1.0 / self.sampleTime
232-
self.txtLblFreq.setText("%.3f kHz" % realSampleFreq)
232+
self.txtLblFreq.setText(f"{realSampleFreq:.3f} kHz")
233233
self.txtLblSignalLen.setText("%.2f ms" % (self.sampleTime * self.nGatherPoints))
234234

235235
# ############## button clicked slots from here
@@ -362,6 +362,6 @@ def saveClicked(self):
362362
for lineNo, lineData in enumerate(zip(*dataLists)):
363363
line = "%d," % lineNo
364364
for data_point in lineData:
365-
line += "%f," % data_point
365+
line += f"{data_point:f},"
366366
fptr.write(line + "\n")
367367
fptr.close()

src/dls_pmac_control/watches.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ def addWatch(self):
2525
assert isinstance(varName, str)
2626
varName = varName.lower()
2727
if varName in unsafeCommands:
28-
raise ValueError("%s is an unsafe command" % varName)
28+
raise ValueError(f"{varName} is an unsafe command")
2929
if re.search(r"[\+\-=\^/]", varName) is not None:
30-
raise ValueError("%s is not a valid variable" % varName)
30+
raise ValueError(f"{varName} is not a valid variable")
3131
if varName in self._watches:
32-
raise ValueError("There is already a watch for %s" % varName)
32+
raise ValueError(f"There is already a watch for {varName}")
3333
# create watch object
3434
watch = Watch(self.parent.pmac, varName)
3535
except ValueError as e:
@@ -50,7 +50,7 @@ def getWatch(self, varName):
5050
try:
5151
watch = self._watches[varName]
5252
except KeyError as e:
53-
print('There is no watch for variable "%s"' % varName)
53+
print(f'There is no watch for variable "{varName}"')
5454
raise ValueError() from e
5555
return watch
5656

@@ -76,7 +76,7 @@ def removeWatch(self):
7676
del self._watches[varName]
7777
self.parent.commsThread.remove_watch(varName)
7878
except KeyError as e:
79-
print('There is no watch for variable "%s"' % varName)
79+
print(f'There is no watch for variable "{varName}"')
8080
raise ValueError() from e
8181
try:
8282
self.table.removeRow(row)
@@ -167,4 +167,4 @@ def _sendPMACCommand(self, command):
167167
# Check whether PMAC doesn't reply with an ERRxx type response
168168
matchObject = re.match(r"^\x07(ERR\d+)\r$", s)
169169
if matchObject or "error" in s:
170-
raise ValueError('Error: cannot set value for "%s"' % self.varName)
170+
raise ValueError(f'Error: cannot set value for "{self.varName}"')

tests/test_gather.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def test_parse_data(self):
144144
def test_calc_sample_time(self):
145145
self.obj.nServoCyclesGather = 1
146146
self.obj.nGatherPoints = 1
147-
attrs = {"sendCommand.return_value": ("$8388608\x0D", True)}
147+
attrs = {"sendCommand.return_value": ("$8388608\x0d", True)}
148148
self.obj.parent.pmac.configure_mock(**attrs)
149149
self.obj.calcSampleTime()
150150
assert self.obj.servoCycleTime == 1.0

0 commit comments

Comments
 (0)