Skip to content

Commit

Permalink
latest ruff checks fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesknap committed Nov 18, 2024
1 parent bb4d0b6 commit cb9df61
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 36 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ line-length = 88
# ignoring line to long for the moment to avoid signficant changes to the code
lint.ignore = [
"E501", # line too long
"E721", # use isinstance instead of compare to type
]
lint.select = [
"B", # flake8-bugbear - https://docs.astral.sh/ruff/rules/#flake8-bugbear-b
Expand Down
6 changes: 3 additions & 3 deletions src/dls_pmac_control/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def remoteConnect(self):
# Find out the type of the PMAC
pmac_model_str = self.pmac.getPmacModel()
if pmac_model_str:
self.setWindowTitle("Delta Tau motor controller - %s" % pmac_model_str)
self.setWindowTitle(f"Delta Tau motor controller - {pmac_model_str}")
else:
QMessageBox.information(self, "Error", "Could not determine PMAC model")
return
Expand Down Expand Up @@ -434,7 +434,7 @@ def killMotor(self):
# see TURBO SRM page 289
def killAllMotors(self):
# print "killing all motors!"
command = "\x0B"
command = "\x0b"
(returnString, status) = self.pmac.sendCommand(command)
self.addToTxtShell("CTRL-K")

Expand Down Expand Up @@ -860,7 +860,7 @@ def updateIdentity(self, id):
if subdomainNum != 0:
text += "%02d" % subdomainNum
text += self.subdomainLetters[domain][subdomainLetter]
text += " %s " % self.pmac.getShortModelName()
text += f" {self.pmac.getShortModelName()} "
text += "%d" % pmacNum
self.lblIdentity.setText(text)

Expand Down
2 changes: 1 addition & 1 deletion src/dls_pmac_control/axissettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def setAxisSetupDirect(self, directCmd, newValue):
self.setAxisSetupVars(varStr, newValue)

def setAxisSetupVars(self, varStr, newValue):
cmd = ("Motor[%d]." % self.currentMotor) + varStr + ("=%s" % newValue)
cmd = ("Motor[%d]." % self.currentMotor) + varStr + (f"={newValue}")
(retStr, success) = self.parent.pmac.sendCommand(cmd)
if success:
self.axisUpdate()
Expand Down
21 changes: 8 additions & 13 deletions src/dls_pmac_control/commsThread.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def updateFunc(self):
self.gen.close()
self.sendComplete("Download cancelled by the user")
else:
print("WARNING: don't know what to do with cmd %s" % cmd)
print(f"WARNING: don't know what to do with cmd {cmd}")
if self.parent.pmac is None or not self.parent.pmac.isConnectionOpen:
time.sleep(0.1)
return
Expand Down Expand Up @@ -143,18 +143,15 @@ def updateFunc(self):
if isinstance(self.parent.pmac, PmacSerialInterface) and self.max_pollrate:
if time.time() - self.parent.pmac.last_comm_time < 1.0 / self.max_pollrate:
return
cmd = "i65???&%s??%%" % self.CSNum
cmd = f"i65???&{self.CSNum}??%"
# Send a different command for the Power PMAC
if isinstance(self.parent.pmac, PPmacSshInterface):
# The %% is because % needs escaping - only one % is actually sent
# There has to be a space before the first BrickLV string to avoid its B being interpreted as a 'begin' command
cmd = (
"i65?&%s?%% BrickLV.BusUnderVoltage BrickLV.BusOverVoltage BrickLV.OverTemp"
% self.CSNum
)
cmd = f"i65?&{self.CSNum}?% BrickLV.BusUnderVoltage BrickLV.BusOverVoltage BrickLV.OverTemp"
elif isinstance(self.parent.pmac, PmacEthernetInterface):
# Add the 7 segment display status query
cmd = "i65???&%s??%%" % self.CSNum
cmd = f"i65???&{self.CSNum}??%"
axes = self.parent.pmac.getNumberOfAxes() + 1
for motorNo in range(1, axes):
cmd = cmd + "#" + str(motorNo) + "?PVF "
Expand Down Expand Up @@ -199,9 +196,7 @@ def updateFunc(self):
# fourth is the PMAC identity
if valueList[0].startswith("\x07"):
# error, probably in buffer
print(
"i65 returned %s, sending CLOSE command" % valueList[0].__repr__()
)
print(f"i65 returned {valueList[0].__repr__()}, sending CLOSE command")
self.parent.pmac.sendCommand("CLOSE")
return

Expand All @@ -217,9 +212,9 @@ def updateFunc(self):
# Global status
self.resultQueue.put([valueList[1], 0, 0, 0, 0, 0, "G"])
# CS status
self.resultQueue.put([valueList[2], 0, 0, 0, 0, 0, "CS%s" % self.CSNum])
self.resultQueue.put([valueList[2], 0, 0, 0, 0, 0, f"CS{self.CSNum}"])
# Fedrate
self.resultQueue.put([valueList[3], 0, 0, 0, 0, 0, "FEED%s" % self.CSNum])
self.resultQueue.put([valueList[3], 0, 0, 0, 0, 0, f"FEED{self.CSNum}"])

if isinstance(self.parent.pmac, PPmacSshInterface):
# Brick Under Voltage Status
Expand All @@ -241,5 +236,5 @@ def updateFunc(self):
evUpdatesReady = CustomEvent(self.parent.updatesReadyEventType, None)
QCoreApplication.postEvent(self.parent, evUpdatesReady)
else:
print('WARNING: Could not poll PMAC for motor status ("%s")' % retStr)
print(f'WARNING: Could not poll PMAC for motor status ("{retStr}")')
time.sleep(0.1)
6 changes: 3 additions & 3 deletions src/dls_pmac_control/gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def gatherConfig(self):
tmpIvar |= 0x01 << bit
if tmpIvar == 0:
return False
cmd = "i5051=0 i5050=$%x" % tmpIvar
cmd = f"i5051=0 i5050=${tmpIvar:x}"
self.parent.pmac.sendCommand(cmd)

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

# ############## button clicked slots from here
Expand Down Expand Up @@ -447,6 +447,6 @@ def saveClicked(self):
for lineNo, lineData in enumerate(zip(*dataLists)):
line = "%d," % lineNo
for data_point in lineData:
line += "%f," % data_point
line += f"{data_point:f},"
fptr.write(line + "\n")
fptr.close()
12 changes: 5 additions & 7 deletions src/dls_pmac_control/gatherchannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def getDataInfo(self):
self.dataWidth = LONGWORD
self.dataType = float
else:
print("### Error: Could not get data width and type from: %s" % (retStr))
print(f"### Error: Could not get data width and type from: {retStr}")

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

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

Expand Down Expand Up @@ -227,7 +226,7 @@ def getScalingFactor(self):
ivar = partIvar % self.axisNo
(retStr, status) = self.pmac.sendCommand(ivar)
if not status:
print("### Error: did not receive response to: %s" % ivar)
print(f"### Error: did not receive response to: {ivar}")
return None
# if hex value...
if retStr[0] == "$":
Expand All @@ -245,8 +244,7 @@ def getScalingFactor(self):
self.scalingFactor = eval(algorithm)
except Exception:
print(
"### Error: did not evaluate expression correctly. Expr: %s"
% (algorithm)
f"### Error: did not evaluate expression correctly. Expr: {algorithm}"
)
return None

Expand Down
4 changes: 2 additions & 2 deletions src/dls_pmac_control/ppmacgather.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def calcSampleTime(self):
# gathering function
self.sampleTime = self.nServoCyclesGather * self.servoCycleTime
realSampleFreq = 1.0 / self.sampleTime
self.txtLblFreq.setText("%.3f kHz" % realSampleFreq)
self.txtLblFreq.setText(f"{realSampleFreq:.3f} kHz")
self.txtLblSignalLen.setText("%.2f ms" % (self.sampleTime * self.nGatherPoints))

# ############## button clicked slots from here
Expand Down Expand Up @@ -362,6 +362,6 @@ def saveClicked(self):
for lineNo, lineData in enumerate(zip(*dataLists)):
line = "%d," % lineNo
for data_point in lineData:
line += "%f," % data_point
line += f"{data_point:f},"
fptr.write(line + "\n")
fptr.close()
12 changes: 6 additions & 6 deletions src/dls_pmac_control/watches.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def addWatch(self):
assert isinstance(varName, str)
varName = varName.lower()
if varName in unsafeCommands:
raise ValueError("%s is an unsafe command" % varName)
raise ValueError(f"{varName} is an unsafe command")
if re.search(r"[\+\-=\^/]", varName) is not None:
raise ValueError("%s is not a valid variable" % varName)
raise ValueError(f"{varName} is not a valid variable")
if varName in self._watches:
raise ValueError("There is already a watch for %s" % varName)
raise ValueError(f"There is already a watch for {varName}")
# create watch object
watch = Watch(self.parent.pmac, varName)
except ValueError as e:
Expand All @@ -50,7 +50,7 @@ def getWatch(self, varName):
try:
watch = self._watches[varName]
except KeyError as e:
print('There is no watch for variable "%s"' % varName)
print(f'There is no watch for variable "{varName}"')
raise ValueError() from e
return watch

Expand All @@ -76,7 +76,7 @@ def removeWatch(self):
del self._watches[varName]
self.parent.commsThread.remove_watch(varName)
except KeyError as e:
print('There is no watch for variable "%s"' % varName)
print(f'There is no watch for variable "{varName}"')
raise ValueError() from e
try:
self.table.removeRow(row)
Expand Down Expand Up @@ -167,4 +167,4 @@ def _sendPMACCommand(self, command):
# Check whether PMAC doesn't reply with an ERRxx type response
matchObject = re.match(r"^\x07(ERR\d+)\r$", s)
if matchObject or "error" in s:
raise ValueError('Error: cannot set value for "%s"' % self.varName)
raise ValueError(f'Error: cannot set value for "{self.varName}"')
2 changes: 1 addition & 1 deletion tests/test_gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def test_parse_data(self):
def test_calc_sample_time(self):
self.obj.nServoCyclesGather = 1
self.obj.nGatherPoints = 1
attrs = {"sendCommand.return_value": ("$8388608\x0D", True)}
attrs = {"sendCommand.return_value": ("$8388608\x0d", True)}
self.obj.parent.pmac.configure_mock(**attrs)
self.obj.calcSampleTime()
assert self.obj.servoCycleTime == 1.0
Expand Down

0 comments on commit cb9df61

Please sign in to comment.