Skip to content

Commit b0e2124

Browse files
committed
"Update ruff pre-commit hook
"
1 parent ec1d2e6 commit b0e2124

11 files changed

Lines changed: 29 additions & 29 deletions

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repos:
1010
- id: end-of-file-fixer
1111
- id: trailing-whitespace
1212
- repo: https://github.com/astral-sh/ruff-pre-commit
13-
rev: v0.3.4
13+
rev: v0.15.8
1414
hooks:
1515
- id: ruff-format
1616
- id: ruff

adafruit_esp32spi/PWMOut.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(self, esp, pwm_pin, *, frequency=500, duty_cycle=0, variable_freque
3030
if pwm_pin in self.ESP32_PWM_PINS:
3131
self._pwm_pin = pwm_pin
3232
else:
33-
raise AttributeError("Pin %d is not a valid ESP32 GPIO Pin." % pwm_pin)
33+
raise AttributeError(f"Pin {pwm_pin} is not a valid ESP32 GPIO Pin.")
3434
self._esp = esp
3535
self._duty_cycle = duty_cycle
3636
self._freq = frequency

adafruit_esp32spi/adafruit_esp32spi.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def _send_command(self, cmd, params=None, *, param_len_16=False):
319319
ptr = 3
320320
for i, param in enumerate(params):
321321
if self._debug >= 2:
322-
print("\tSending param #%d is %d bytes long" % (i, len(param)))
322+
print(f"\tSending param #{i} is {len(param)} bytes long")
323323
if param_len_16:
324324
self._sendbuf[ptr] = (len(param) >> 8) & 0xFF
325325
ptr += 1
@@ -399,14 +399,14 @@ def _wait_response_cmd(self, cmd, num_responses=None, *, param_len_16=False):
399399
param_len <<= 8
400400
param_len |= self._read_byte(spi)
401401
if self._debug >= 2:
402-
print("\tParameter #%d length is %d" % (num, param_len))
402+
print(f"\tParameter #{num} length is {param_len}")
403403
response = bytearray(param_len)
404404
self._read_bytes(spi, response)
405405
responses.append(response)
406406
self._check_data(spi, _END_CMD)
407407

408408
if self._debug >= 2:
409-
print("Read %d: " % len(responses[0]), responses)
409+
print(f"Read {len(responses[0])}: ", responses)
410410
return responses
411411

412412
def _send_command_get_response(
@@ -776,7 +776,7 @@ def get_socket(self):
776776
if resp == 255:
777777
raise OSError(23) # ENFILE - File table overflow
778778
if self._debug:
779-
print("Allocated socket #%d" % resp)
779+
print(f"Allocated socket #{resp}")
780780
return resp
781781

782782
def socket_open(self, socket_num, dest, port, conn_mode=TCP_MODE):
@@ -850,7 +850,7 @@ def socket_write(self, socket_num, buffer, conn_mode=TCP_MODE):
850850
if conn_mode == self.UDP_MODE:
851851
# UDP verifies chunks on write, not bytes
852852
if sent != total_chunks:
853-
raise ConnectionError("Failed to write %d chunks (sent %d)" % (total_chunks, sent))
853+
raise ConnectionError(f"Failed to write {total_chunks} chunks (sent {sent})")
854854
# UDP needs to finalize with this command, does the actual sending
855855
resp = self._send_command_get_response(_SEND_UDP_DATA_CMD, self._socknum_ll)
856856
if resp[0][0] != 1:
@@ -859,7 +859,7 @@ def socket_write(self, socket_num, buffer, conn_mode=TCP_MODE):
859859

860860
if sent != len(buffer):
861861
self.socket_close(socket_num)
862-
raise ConnectionError("Failed to send %d bytes (sent %d)" % (len(buffer), sent))
862+
raise ConnectionError(f"Failed to send {len(buffer)} bytes (sent {sent})")
863863

864864
resp = self._send_command_get_response(_DATA_SENT_TCP_CMD, self._socknum_ll)
865865
if resp[0][0] != 1:
@@ -873,15 +873,14 @@ def socket_available(self, socket_num):
873873
resp = self._send_command_get_response(_AVAIL_DATA_TCP_CMD, self._socknum_ll)
874874
reply = struct.unpack("<H", resp[0])[0]
875875
if self._debug:
876-
print("ESPSocket: %d bytes available" % reply)
876+
print(f"ESPSocket: {reply} bytes available")
877877
return reply
878878

879879
def socket_read(self, socket_num, size):
880880
"""Read up to 'size' bytes from the socket number. Returns a bytes"""
881881
if self._debug:
882882
print(
883-
"Reading %d bytes from ESP socket with status %d"
884-
% (size, self.socket_status(socket_num))
883+
f"Reading {size} bytes from ESP socket with status {self.socket_status(socket_num)}"
885884
)
886885
self._socknum_ll[0][0] = socket_num
887886
resp = self._send_command_get_response(
@@ -917,7 +916,7 @@ def socket_connect(self, socket_num, dest, port, conn_mode=TCP_MODE):
917916
def socket_close(self, socket_num):
918917
"""Close a socket using the ESP32's internal reference number"""
919918
if self._debug:
920-
print("*** Closing socket #%d" % socket_num)
919+
print(f"*** Closing socket #{socket_num}")
921920
self._socknum_ll[0][0] = socket_num
922921
try:
923922
self._send_command_get_response(_STOP_CLIENT_TCP_CMD, self._socknum_ll)

adafruit_esp32spi/adafruit_esp32spi_wifimanager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def connect(self):
101101
print("Firmware vers.", self.esp.firmware_version)
102102
print("MAC addr:", [hex(i) for i in self.esp.MAC_address])
103103
for access_pt in self.esp.scan_networks():
104-
print("\t%s\t\tRSSI: %d" % (access_pt.ssid, access_pt.rssi))
104+
print(f"\t{access_pt.ssid}\t\tRSSI: {access_pt.rssi}")
105105
if self._connection_type == WiFiManager.NORMAL:
106106
self.connect_normal()
107107
elif self._connection_type == WiFiManager.ENTERPRISE:

adafruit_esp32spi/digitalio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(self, esp_pin, esp):
4545
if esp_pin in self.ESP32_GPIO_PINS:
4646
self.pin_id = esp_pin
4747
else:
48-
raise AttributeError("Pin %d is not a valid ESP32 GPIO Pin." % esp_pin)
48+
raise AttributeError(f"Pin {esp_pin} is not a valid ESP32 GPIO Pin.")
4949
self._esp = esp
5050

5151
def init(self, mode=IN):
@@ -201,6 +201,6 @@ def drive_mode(self, mode):
201201
Either PUSH_PULL or OPEN_DRAIN
202202
"""
203203
if mode is DriveMode.OPEN_DRAIN:
204-
raise NotImplementedError("Drive mode %s not implemented in ESP32SPI." % mode)
204+
raise NotImplementedError(f"Drive mode {mode} not implemented in ESP32SPI.")
205205
if mode is DriveMode.PUSH_PULL:
206206
self._pin.init(mode=Pin.OUT)

examples/esp32spi_aio_post.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
)
7373
print(response.json())
7474
response.close()
75-
counter = counter + 1
75+
counter += 1
7676
print("OK")
7777
except OSError as e:
7878
print("Failed to get data, retrying\n", e)

examples/esp32spi_simpletest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@
6060
if esp.status == adafruit_esp32spi.WL_IDLE_STATUS:
6161
print("ESP32 found and in idle mode")
6262
print("Firmware vers.", esp.firmware_version)
63-
print("MAC addr:", ":".join("%02X" % byte for byte in esp.MAC_address))
63+
print("MAC addr:", ":".join(f"{byte:02X}" for byte in esp.MAC_address))
6464

6565
for ap in esp.scan_networks():
66-
print("\t%-23s RSSI: %d" % (ap.ssid, ap.rssi))
66+
print(f"\t{ap.ssid:<23} RSSI: {ap.rssi}")
6767

6868
print("Connecting to AP...")
6969
while not esp.is_connected:
@@ -74,8 +74,8 @@
7474
continue
7575
print("Connected to", esp.ap_info.ssid, "\tRSSI:", esp.ap_info.rssi)
7676
print("My IP address is", esp.ipv4_address)
77-
print("IP lookup adafruit.com: %s" % esp.pretty_ip(esp.get_host_by_name("adafruit.com")))
78-
print("Ping google.com: %d ms" % esp.ping("google.com"))
77+
print(f"IP lookup adafruit.com: {esp.pretty_ip(esp.get_host_by_name('adafruit.com'))}")
78+
print(f"Ping google.com: {esp.ping('google.com')} ms")
7979

8080
# esp._debug = True
8181
print("Fetching text from", TEXT_URL)

examples/esp32spi_simpletest_rp2040.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
print("MAC addr:", [hex(i) for i in esp.MAC_address])
4343

4444
for ap in esp.scan_networks():
45-
print("\t%s\t\tRSSI: %d" % (ap.ssid, ap.rssi))
45+
print(f"\t{ap.ssid}\t\tRSSI: {ap.rssi}")
4646

4747
print("Connecting to AP...")
4848
while not esp.is_connected:
@@ -53,8 +53,8 @@
5353
continue
5454
print("Connected to", esp.ap_info.ssid, "\tRSSI:", esp.ap_info.rssi)
5555
print("My IP address is", esp.ipv4_address)
56-
print("IP lookup adafruit.com: %s" % esp.pretty_ip(esp.get_host_by_name("adafruit.com")))
57-
print("Ping google.com: %d ms" % esp.ping("google.com"))
56+
print(f"IP lookup adafruit.com: {esp.pretty_ip(esp.get_host_by_name('adafruit.com'))}")
57+
print(f"Ping google.com: {esp.ping('google.com')} ms")
5858

5959
# esp._debug = True
6060
print("Fetching text from", TEXT_URL)

examples/esp32spi_wpa2ent_aio_post.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
)
8787
print(response.json())
8888
response.close()
89-
counter = counter + 1
89+
counter += 1
9090
print("OK")
9191
except OSError as e:
9292
print("Failed to get data, retrying\n", e)

examples/esp32spi_wpa2ent_simpletest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ def normalize(v):
6969

7070
# WPA2 Enterprise support was added in fw ver 1.3.0. Check that the ESP32
7171
# is running at least that version, otherwise, bail out
72-
assert (
73-
version_compare(esp.firmware_version, "1.3.0") >= 0
74-
), "Incorrect ESP32 firmware version; >= 1.3.0 required."
72+
assert version_compare(esp.firmware_version, "1.3.0") >= 0, (
73+
"Incorrect ESP32 firmware version; >= 1.3.0 required."
74+
)
7575

7676
# Set up the SSID you would like to connect to
7777
# Note that we need to call wifi_set_network prior
@@ -101,7 +101,7 @@ def normalize(v):
101101
print("")
102102
print("Connected to", esp.ap_info.ssid, "\tRSSI:", esp.ap_info.rssi)
103103
print("My IP address is", esp.ipv4_address)
104-
print("IP lookup adafruit.com: %s" % esp.pretty_ip(esp.get_host_by_name("adafruit.com")))
105-
print("Ping google.com: %d ms" % esp.ping("google.com"))
104+
print(f"IP lookup adafruit.com: {esp.pretty_ip(esp.get_host_by_name('adafruit.com'))}")
105+
print(f"Ping google.com: {esp.ping('google.com')} ms")
106106

107107
print("Done!")

0 commit comments

Comments
 (0)