Skip to content

Commit

Permalink
Merge pull request #79 from hnez/ruff-up
Browse files Browse the repository at this point in the history
usbsdmux: add ruff "UP" rules to config and fix issues automatically
  • Loading branch information
SmithChart authored May 8, 2024
2 parents dac872b + f8e040b commit 5b51d45
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ exclude = [
]

[tool.ruff.lint]
select = ["B", "E", "F", "I", "SIM"]
select = ["B", "E", "F", "I", "SIM", "UP"]
2 changes: 1 addition & 1 deletion usbsdmux/ctypehelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def to_pretty_hex(buffer):
temp_buf = temp_buf[8:]
res += "0x{:02X}\t{} {}\n".format(
offs,
" ".join(["{:02X}".format(x) for x in window]),
" ".join([f"{x:02X}" for x in window]),
" ".join([chr(x) if chr(x) in string.printable.split(" ")[0] else "." for x in window]),
)
offs += 8
Expand Down
2 changes: 1 addition & 1 deletion usbsdmux/i2c_gpio.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from .usb2642 import Usb2642


class I2cGpio(object):
class I2cGpio:
# Registers inside the supported GPIO expanders
_register_inputPort = 0x00
_register_outputPort = 0x01
Expand Down
2 changes: 1 addition & 1 deletion usbsdmux/mqtthelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self, configfile):

def _read_file(filename):
try:
with open(filename, "r") as f:
with open(filename) as f:
return f.read()
except FileNotFoundError:
return None
Expand Down
10 changes: 5 additions & 5 deletions usbsdmux/usb2642.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class SDTransactionFailed(Exception):
pass


class Usb2642(object):
class Usb2642:
"""
This class provides an interface to interact with devices on a Microchip
USB2642 auxiliary I2C Bus and to write configuration to an EEPROM on the
Expand Down Expand Up @@ -342,7 +342,7 @@ def _call_IOCTL(self, command, sg_dxfer, databuffer):
with open(self.sg, "r+b", buffering=0) as fh:
rc = fcntl.ioctl(fh, self._SG_IO, sgio)
if rc != 0:
raise IoctlFailed("SG_IO ioctl() failed with non-zero exit-code {}".format(rc))
raise IoctlFailed(f"SG_IO ioctl() failed with non-zero exit-code {rc}")
return databuffer, sense, sgio

def write_config(self, data):
Expand Down Expand Up @@ -417,7 +417,7 @@ def write_read_to(self, i2cAddr, writeData, readLength):

if sgio.status != 0:
raise I2cTransactionFailed(
"SCSI-Transaction ended with status {}. I2C-Transaction has probably failed.".format(sgio.status)
f"SCSI-Transaction ended with status {sgio.status}. I2C-Transaction has probably failed."
)

return list(data[:readLength])
Expand Down Expand Up @@ -453,7 +453,7 @@ def write_to(self, i2cAddr, data):

if sgio.status != 0:
raise I2cTransactionFailed(
"SCSI-Transaction ended with status {}. I2C-Transaction has probably failed.".format(sgio.status)
f"SCSI-Transaction ended with status {sgio.status}. I2C-Transaction has probably failed."
)

def _read_register(self, reg, size, retries=5):
Expand All @@ -472,7 +472,7 @@ def _read_register(self, reg, size, retries=5):

if sgio.status != 0:
raise SDTransactionFailed(
"SCSI Transaction ended with status {}. SD Transaction has probably failed.".format(sgio.status)
f"SCSI Transaction ended with status {sgio.status}. SD Transaction has probably failed."
)

break
Expand Down
2 changes: 1 addition & 1 deletion usbsdmux/usb2642eeprom.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class VerificationFailedException(Exception):
pass


class USB2642Eeprom(object):
class USB2642Eeprom:
"""
Provides an interface to write the configuration EEPROM of a USB2642.
"""
Expand Down
2 changes: 1 addition & 1 deletion usbsdmux/usbsdmux.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def autoselect_driver(sg):
sg_name = os.path.basename(base_sg)
model_filename = f"/sys/class/scsi_generic/{sg_name}/device/model"
try:
with open(model_filename, "r") as fh:
with open(model_filename) as fh:
model = fh.read().strip()
if model == "sdmux HS-SD/MMC":
return UsbSdMuxClassic(sg)
Expand Down

0 comments on commit 5b51d45

Please sign in to comment.