Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 808189e

Browse files
authoredMay 14, 2025··
Merge pull request #221 from adafruit/use_ruff
change to ruff
2 parents 2ddf9fa + 2be7aad commit 808189e

23 files changed

+259
-637
lines changed
 

‎.gitattributes

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
4+
5+
.py text eol=lf
6+
.rst text eol=lf
7+
.txt text eol=lf
8+
.yaml text eol=lf
9+
.toml text eol=lf
10+
.license text eol=lf
11+
.md text eol=lf

‎.pre-commit-config.yaml

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,21 @@
1-
# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò
1+
# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries
22
#
33
# SPDX-License-Identifier: Unlicense
44

55
repos:
6-
- repo: https://github.com/python/black
7-
rev: 23.3.0
8-
hooks:
9-
- id: black
10-
- repo: https://github.com/fsfe/reuse-tool
11-
rev: v1.1.2
12-
hooks:
13-
- id: reuse
146
- repo: https://github.com/pre-commit/pre-commit-hooks
15-
rev: v4.4.0
7+
rev: v4.5.0
168
hooks:
179
- id: check-yaml
1810
- id: end-of-file-fixer
1911
- id: trailing-whitespace
20-
- repo: https://github.com/pycqa/pylint
21-
rev: v3.3.1
12+
- repo: https://github.com/astral-sh/ruff-pre-commit
13+
rev: v0.3.4
2214
hooks:
23-
- id: pylint
24-
name: pylint (library code)
25-
types: [python]
26-
args:
27-
- --disable=consider-using-f-string,too-many-arguments,too-many-positional-arguments
28-
exclude: "^(docs/|examples/|tests/|setup.py$)"
29-
- id: pylint
30-
name: pylint (example code)
31-
description: Run pylint rules on "examples/*.py" files
32-
types: [python]
33-
files: "^examples/"
34-
args:
35-
- --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code
36-
- id: pylint
37-
name: pylint (test code)
38-
description: Run pylint rules on "tests/*.py" files
39-
types: [python]
40-
files: "^tests/"
41-
args:
42-
- --disable=missing-docstring,consider-using-f-string,duplicate-code
15+
- id: ruff-format
16+
- id: ruff
17+
args: ["--fix"]
18+
- repo: https://github.com/fsfe/reuse-tool
19+
rev: v3.0.1
20+
hooks:
21+
- id: reuse

‎.pylintrc

Lines changed: 0 additions & 399 deletions
This file was deleted.

‎README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ Introduction
1313
:target: https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI/actions/
1414
:alt: Build Status
1515

16-
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
17-
:target: https://github.com/psf/black
18-
:alt: Code Style: Black
16+
.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
17+
:target: https://github.com/astral-sh/ruff
18+
:alt: Code Style: Ruff
1919

2020
CircuitPython driver library for using ESP32 as WiFi co-processor using SPI.
2121
The companion firmware `is available on GitHub

‎adafruit_esp32spi/PWMOut.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ class PWMOut:
2626
[0, 1, 2, 4, 5, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 25, 26, 27, 32, 33]
2727
)
2828

29-
def __init__(
30-
self, esp, pwm_pin, *, frequency=500, duty_cycle=0, variable_frequency=False
31-
):
29+
def __init__(self, esp, pwm_pin, *, frequency=500, duty_cycle=0, variable_frequency=False):
3230
if pwm_pin in self.ESP32_PWM_PINS:
3331
self._pwm_pin = pwm_pin
3432
else:

‎adafruit_esp32spi/adafruit_esp32spi.py

Lines changed: 37 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@
2929
import struct
3030
import time
3131
import warnings
32-
from micropython import const
32+
3333
from adafruit_bus_device.spi_device import SPIDevice
3434
from digitalio import Direction
35+
from micropython import const
3536

3637
__version__ = "0.0.0+auto.0"
3738
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI.git"
@@ -129,13 +130,11 @@
129130
ADC_ATTEN_DB_6 = const(2)
130131
ADC_ATTEN_DB_11 = const(3)
131132

132-
# pylint: disable=too-many-lines
133-
134133

135134
class Network:
136135
"""A wifi network provided by a nearby access point."""
137136

138-
def __init__( # pylint: disable=too-many-arguments
137+
def __init__(
139138
self,
140139
esp_spi_control=None,
141140
raw_ssid=None,
@@ -154,9 +153,7 @@ def __init__( # pylint: disable=too-many-arguments
154153
self._raw_authmode = raw_authmode
155154

156155
def _get_response(self, cmd):
157-
respose = self._esp_spi_control._send_command_get_response( # pylint: disable=protected-access
158-
cmd, [b"\xFF"]
159-
)
156+
respose = self._esp_spi_control._send_command_get_response(cmd, [b"\xff"])
160157
return respose[0]
161158

162159
@property
@@ -221,15 +218,14 @@ def authmode(self):
221218
return "UNKNOWN"
222219

223220

224-
class ESP_SPIcontrol: # pylint: disable=too-many-public-methods, too-many-instance-attributes
221+
class ESP_SPIcontrol:
225222
"""A class that will talk to an ESP32 module programmed with special firmware
226223
that lets it act as a fast an efficient WiFi co-processor"""
227224

228225
TCP_MODE = const(0)
229226
UDP_MODE = const(1)
230227
TLS_MODE = const(2)
231228

232-
# pylint: disable=too-many-arguments
233229
def __init__(
234230
self,
235231
spi,
@@ -297,7 +293,6 @@ def _wait_for_ready(self):
297293
if self._debug >= 3:
298294
print()
299295

300-
# pylint: disable=too-many-branches
301296
def _send_command(self, cmd, params=None, *, param_len_16=False):
302297
"""Send over a command with a list of parameters"""
303298
if not params:
@@ -342,14 +337,10 @@ def _send_command(self, cmd, params=None, *, param_len_16=False):
342337
break
343338
else:
344339
raise TimeoutError("ESP32 timed out on SPI select")
345-
spi.write(
346-
self._sendbuf, start=0, end=packet_len
347-
) # pylint: disable=no-member
340+
spi.write(self._sendbuf, start=0, end=packet_len)
348341
if self._debug >= 3:
349342
print("Wrote: ", [hex(b) for b in self._sendbuf[0:packet_len]])
350343

351-
# pylint: disable=too-many-branches
352-
353344
def _read_byte(self, spi):
354345
"""Read one byte from SPI"""
355346
spi.readinto(self._pbuf)
@@ -380,7 +371,7 @@ def _check_data(self, spi, desired):
380371
"""Read a byte and verify its the value we want"""
381372
r = self._read_byte(spi)
382373
if r != desired:
383-
raise BrokenPipeError("Expected %02X but got %02X" % (desired, r))
374+
raise BrokenPipeError(f"Expected {desired:02X} but got {r:02X}")
384375

385376
def _wait_response_cmd(self, cmd, num_responses=None, *, param_len_16=False):
386377
"""Wait for ready, then parse the response"""
@@ -417,7 +408,7 @@ def _wait_response_cmd(self, cmd, num_responses=None, *, param_len_16=False):
417408
print("Read %d: " % len(responses[0]), responses)
418409
return responses
419410

420-
def _send_command_get_response( # pylint: disable=too-many-arguments
411+
def _send_command_get_response(
421412
self,
422413
cmd,
423414
params=None,
@@ -428,9 +419,7 @@ def _send_command_get_response( # pylint: disable=too-many-arguments
428419
):
429420
"""Send a high level SPI command, wait and return the response"""
430421
self._send_command(cmd, params, param_len_16=sent_param_len_16)
431-
return self._wait_response_cmd(
432-
cmd, reply_params, param_len_16=recv_param_len_16
433-
)
422+
return self._wait_response_cmd(cmd, reply_params, param_len_16=recv_param_len_16)
434423

435424
@property
436425
def status(self):
@@ -452,15 +441,15 @@ def firmware_version(self):
452441
return resp[0].decode("utf-8").replace("\x00", "")
453442

454443
@property
455-
def MAC_address(self): # pylint: disable=invalid-name
444+
def MAC_address(self):
456445
"""A bytearray containing the MAC address of the ESP32"""
457446
if self._debug:
458447
print("MAC address")
459-
resp = self._send_command_get_response(_GET_MACADDR_CMD, [b"\xFF"])
448+
resp = self._send_command_get_response(_GET_MACADDR_CMD, [b"\xff"])
460449
return resp[0]
461450

462451
@property
463-
def MAC_address_actual(self): # pylint: disable=invalid-name
452+
def MAC_address_actual(self):
464453
"""A bytearray containing the actual MAC address of the ESP32"""
465454
return bytearray(reversed(self.MAC_address))
466455

@@ -485,7 +474,7 @@ def get_scan_networks(self):
485474
self._send_command(_SCAN_NETWORKS)
486475
names = self._wait_response_cmd(_SCAN_NETWORKS)
487476
# print("SSID names:", names)
488-
APs = [] # pylint: disable=invalid-name
477+
APs = []
489478
for i, name in enumerate(names):
490479
bssid = self._send_command_get_response(_GET_IDX_BSSID_CMD, ((i,),))[0]
491480
rssi = self._send_command_get_response(_GET_IDX_RSSI_CMD, ((i,),))[0]
@@ -509,13 +498,13 @@ def scan_networks(self):
509498
self.start_scan_networks()
510499
for _ in range(10): # attempts
511500
time.sleep(2)
512-
APs = self.get_scan_networks() # pylint: disable=invalid-name
501+
APs = self.get_scan_networks()
513502
if APs:
514503
return APs
515504
return None
516505

517506
def set_ip_config(self, ip_address, gateway, mask="255.255.255.0"):
518-
"""Tells the ESP32 to set ip, gateway and network mask b"\xFF"
507+
"""Tells the ESP32 to set ip, gateway and network mask b"\xff"
519508
520509
:param str ip_address: IP address (as a string).
521510
:param str gateway: Gateway (as a string).
@@ -598,9 +587,7 @@ def _wifi_set_ap_network(self, ssid, channel):
598587

599588
def _wifi_set_ap_passphrase(self, ssid, passphrase, channel):
600589
"""Creates an Access point with SSID, passphrase, and Channel"""
601-
resp = self._send_command_get_response(
602-
_SET_AP_PASSPHRASE_CMD, [ssid, passphrase, channel]
603-
)
590+
resp = self._send_command_get_response(_SET_AP_PASSPHRASE_CMD, [ssid, passphrase, channel])
604591
if resp[0][0] != 1:
605592
raise OSError("Failed to setup AP password")
606593

@@ -616,9 +603,7 @@ def ap_info(self):
616603
def network_data(self):
617604
"""A dictionary containing current connection details such as the 'ip_addr',
618605
'netmask' and 'gateway'"""
619-
resp = self._send_command_get_response(
620-
_GET_IPADDR_CMD, [b"\xFF"], reply_params=3
621-
)
606+
resp = self._send_command_get_response(_GET_IPADDR_CMD, [b"\xff"], reply_params=3)
622607
return {"ip_addr": resp[0], "netmask": resp[1], "gateway": resp[2]}
623608

624609
@property
@@ -671,7 +656,7 @@ def connect(self, ssid, password=None, timeout=10):
671656
ssid, password = ssid["ssid"], ssid.get("password")
672657
self.connect_AP(ssid, password, timeout_s=timeout)
673658

674-
def connect_AP(self, ssid, password, timeout_s=10): # pylint: disable=invalid-name
659+
def connect_AP(self, ssid, password, timeout_s=10):
675660
"""Connect to an access point with given name and password.
676661
Will wait until specified timeout seconds and return on success
677662
or raise an exception on failure.
@@ -699,15 +684,13 @@ def connect_AP(self, ssid, password, timeout_s=10): # pylint: disable=invalid-n
699684
if stat == WL_CONNECTED:
700685
return stat
701686
time.sleep(0.05)
702-
if stat in (WL_CONNECT_FAILED, WL_CONNECTION_LOST, WL_DISCONNECTED):
687+
if stat in {WL_CONNECT_FAILED, WL_CONNECTION_LOST, WL_DISCONNECTED}:
703688
raise ConnectionError("Failed to connect to ssid", ssid)
704689
if stat == WL_NO_SSID_AVAIL:
705690
raise ConnectionError("No such ssid", ssid)
706-
raise OSError("Unknown error 0x%02X" % stat)
691+
raise OSError(f"Unknown error 0x{stat:02X}")
707692

708-
def create_AP(
709-
self, ssid, password, channel=1, timeout=10
710-
): # pylint: disable=invalid-name
693+
def create_AP(self, ssid, password, channel=1, timeout=10):
711694
"""Create an access point with the given name, password, and channel.
712695
Will wait until specified timeout seconds and return on success
713696
or raise an exception on failure.
@@ -743,18 +726,18 @@ def create_AP(
743726
time.sleep(0.05)
744727
if stat == WL_AP_FAILED:
745728
raise ConnectionError("Failed to create AP", ssid)
746-
raise OSError("Unknown error 0x%02x" % stat)
729+
raise OSError(f"Unknown error 0x{stat:02x}")
747730

748731
@property
749732
def ipv4_address(self):
750733
"""IP address of the station when connected to an access point."""
751734
return self.pretty_ip(self.ip_address)
752735

753-
def pretty_ip(self, ip): # pylint: disable=no-self-use, invalid-name
736+
def pretty_ip(self, ip): # noqa: PLR6301
754737
"""Converts a bytearray IP address to a dotted-quad string for printing"""
755-
return "%d.%d.%d.%d" % (ip[0], ip[1], ip[2], ip[3])
738+
return f"{ip[0]}.{ip[1]}.{ip[2]}.{ip[3]}"
756739

757-
def unpretty_ip(self, ip): # pylint: disable=no-self-use, invalid-name
740+
def unpretty_ip(self, ip): # noqa: PLR6301
758741
"""Converts a dotted-quad string to a bytearray IP address"""
759742
octets = [int(x) for x in ip.split(".")]
760743
return bytes(octets)
@@ -834,9 +817,7 @@ def socket_status(self, socket_num):
834817
SOCKET_FIN_WAIT_2, SOCKET_CLOSE_WAIT, SOCKET_CLOSING, SOCKET_LAST_ACK, or
835818
SOCKET_TIME_WAIT"""
836819
self._socknum_ll[0][0] = socket_num
837-
resp = self._send_command_get_response(
838-
_GET_CLIENT_STATE_TCP_CMD, self._socknum_ll
839-
)
820+
resp = self._send_command_get_response(_GET_CLIENT_STATE_TCP_CMD, self._socknum_ll)
840821
return resp[0][0]
841822

842823
def socket_connected(self, socket_num):
@@ -867,9 +848,7 @@ def socket_write(self, socket_num, buffer, conn_mode=TCP_MODE):
867848
if conn_mode == self.UDP_MODE:
868849
# UDP verifies chunks on write, not bytes
869850
if sent != total_chunks:
870-
raise ConnectionError(
871-
"Failed to write %d chunks (sent %d)" % (total_chunks, sent)
872-
)
851+
raise ConnectionError("Failed to write %d chunks (sent %d)" % (total_chunks, sent))
873852
# UDP needs to finalize with this command, does the actual sending
874853
resp = self._send_command_get_response(_SEND_UDP_DATA_CMD, self._socknum_ll)
875854
if resp[0][0] != 1:
@@ -878,9 +857,7 @@ def socket_write(self, socket_num, buffer, conn_mode=TCP_MODE):
878857

879858
if sent != len(buffer):
880859
self.socket_close(socket_num)
881-
raise ConnectionError(
882-
"Failed to send %d bytes (sent %d)" % (len(buffer), sent)
883-
)
860+
raise ConnectionError("Failed to send %d bytes (sent %d)" % (len(buffer), sent))
884861

885862
resp = self._send_command_get_response(_DATA_SENT_TCP_CMD, self._socknum_ll)
886863
if resp[0][0] != 1:
@@ -945,9 +922,7 @@ def socket_close(self, socket_num):
945922
if socket_num == self._tls_socket:
946923
self._tls_socket = None
947924

948-
def start_server(
949-
self, port, socket_num, conn_mode=TCP_MODE, ip=None
950-
): # pylint: disable=invalid-name
925+
def start_server(self, port, socket_num, conn_mode=TCP_MODE, ip=None): # pylint: disable=invalid-name
951926
"""Opens a server on the specified port, using the ESP32's internal reference number"""
952927
if self._debug:
953928
print("*** starting server")
@@ -1003,9 +978,7 @@ def set_digital_write(self, pin, value):
1003978
:param int pin: ESP32 GPIO pin to write to.
1004979
:param bool value: Value for the pin.
1005980
"""
1006-
resp = self._send_command_get_response(
1007-
_SET_DIGITAL_WRITE_CMD, ((pin,), (value,))
1008-
)
981+
resp = self._send_command_get_response(_SET_DIGITAL_WRITE_CMD, ((pin,), (value,)))
1009982
if resp[0][0] != 1:
1010983
raise OSError("Failed to write to pin")
1011984

@@ -1016,9 +989,7 @@ def set_analog_write(self, pin, analog_value):
1016989
:param float value: 0=off 1.0=full on
1017990
"""
1018991
value = int(255 * analog_value)
1019-
resp = self._send_command_get_response(
1020-
_SET_ANALOG_WRITE_CMD, ((pin,), (value,))
1021-
)
992+
resp = self._send_command_get_response(_SET_ANALOG_WRITE_CMD, ((pin,), (value,)))
1022993
if resp[0][0] != 1:
1023994
raise OSError("Failed to write to pin")
1024995

@@ -1036,9 +1007,7 @@ def set_digital_read(self, pin):
10361007
return False
10371008
if resp[0] == 1:
10381009
return True
1039-
raise OSError(
1040-
"_SET_DIGITAL_READ response error: response is not boolean", resp[0]
1041-
)
1010+
raise OSError("_SET_DIGITAL_READ response error: response is not boolean", resp[0])
10421011

10431012
def set_analog_read(self, pin, atten=ADC_ATTEN_DB_11):
10441013
"""Get the analog input value of pin. Returns an int between 0 and 65536.
@@ -1053,9 +1022,7 @@ def set_analog_read(self, pin, atten=ADC_ATTEN_DB_11):
10531022
resp = self._send_command_get_response(_SET_ANALOG_READ_CMD, ((pin,), (atten,)))
10541023
resp_analog = struct.unpack("<i", resp[0])
10551024
if resp_analog[0] < 0:
1056-
raise ValueError(
1057-
"_SET_ANALOG_READ parameter error: invalid pin", resp_analog[0]
1058-
)
1025+
raise ValueError("_SET_ANALOG_READ parameter error: invalid pin", resp_analog[0])
10591026
if self._debug:
10601027
print(resp, resp_analog, resp_analog[0], 16 * resp_analog[0])
10611028
return 16 * resp_analog[0]
@@ -1068,10 +1035,8 @@ def get_time(self):
10681035
if resp_time == (0,):
10691036
raise OSError("_GET_TIME returned 0")
10701037
return resp_time
1071-
if self.status in (WL_AP_LISTENING, WL_AP_CONNECTED):
1072-
raise OSError(
1073-
"Cannot obtain NTP while in AP mode, must be connected to internet"
1074-
)
1038+
if self.status in {WL_AP_LISTENING, WL_AP_CONNECTED}:
1039+
raise OSError("Cannot obtain NTP while in AP mode, must be connected to internet")
10751040
raise OSError("Must be connected to WiFi before obtaining NTP.")
10761041

10771042
def set_certificate(self, client_certificate):
@@ -1083,9 +1048,7 @@ def set_certificate(self, client_certificate):
10831048
if self._debug:
10841049
print("** Setting client certificate")
10851050
if self.status == WL_CONNECTED:
1086-
raise ValueError(
1087-
"set_certificate must be called BEFORE a connection is established."
1088-
)
1051+
raise ValueError("set_certificate must be called BEFORE a connection is established.")
10891052
if isinstance(client_certificate, str):
10901053
client_certificate = bytes(client_certificate, "utf-8")
10911054
if "-----BEGIN CERTIFICATE" not in client_certificate:
@@ -1106,9 +1069,7 @@ def set_private_key(self, private_key):
11061069
if self._debug:
11071070
print("** Setting client's private key.")
11081071
if self.status == WL_CONNECTED:
1109-
raise ValueError(
1110-
"set_private_key must be called BEFORE a connection is established."
1111-
)
1072+
raise ValueError("set_private_key must be called BEFORE a connection is established.")
11121073
if isinstance(private_key, str):
11131074
private_key = bytes(private_key, "utf-8")
11141075
if "-----BEGIN RSA" not in private_key:

‎adafruit_esp32spi/adafruit_esp32spi_socketpool.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,24 @@
1010
1111
* Author(s): ladyada
1212
"""
13+
1314
from __future__ import annotations
1415

1516
try:
1617
from typing import TYPE_CHECKING, Optional
1718

1819
if TYPE_CHECKING:
19-
from esp32spi.adafruit_esp32spi import ESP_SPIcontrol
20+
from esp32spi.adafruit_esp32spi import ESP_SPIcontrol # noqa: UP007
2021
except ImportError:
2122
pass
2223

2324

2425
import errno
25-
import time
2626
import gc
27+
import time
28+
2729
from micropython import const
30+
2831
from adafruit_esp32spi import adafruit_esp32spi as esp32spi
2932

3033
_global_socketpool = {}
@@ -49,17 +52,15 @@ def __new__(cls, iface: ESP_SPIcontrol):
4952
def __init__(self, iface: ESP_SPIcontrol):
5053
self._interface = iface
5154

52-
def getaddrinfo( # pylint: disable=too-many-arguments,unused-argument
53-
self, host, port, family=0, socktype=0, proto=0, flags=0
54-
):
55+
def getaddrinfo(self, host, port, family=0, socktype=0, proto=0, flags=0):
5556
"""Given a hostname and a port name, return a 'socket.getaddrinfo'
5657
compatible list of tuples. Honestly, we ignore anything but host & port"""
5758
if not isinstance(port, int):
5859
raise ValueError("Port must be an integer")
5960
ipaddr = self._interface.get_host_by_name(host)
6061
return [(SocketPool.AF_INET, socktype, proto, "", (ipaddr, port))]
6162

62-
def socket( # pylint: disable=redefined-builtin
63+
def socket(
6364
self,
6465
family=AF_INET,
6566
type=SOCK_STREAM,
@@ -74,13 +75,13 @@ class Socket:
7475
"""A simplified implementation of the Python 'socket' class, for connecting
7576
through an interface to a remote device"""
7677

77-
def __init__( # pylint: disable=redefined-builtin,too-many-arguments,unused-argument
78+
def __init__(
7879
self,
7980
socket_pool: SocketPool,
8081
family: int = SocketPool.AF_INET,
8182
type: int = SocketPool.SOCK_STREAM,
8283
proto: int = 0,
83-
fileno: Optional[int] = None,
84+
fileno: Optional[int] = None, # noqa: UP007
8485
):
8586
if family != SocketPool.AF_INET:
8687
raise ValueError("Only AF_INET family supported")
@@ -110,9 +111,7 @@ def connect(self, address, conntype=None):
110111
if self._type == SocketPool.SOCK_DGRAM
111112
else self._interface.TCP_MODE
112113
)
113-
if not self._interface.socket_connect(
114-
self._socknum, host, port, conn_mode=conntype
115-
):
114+
if not self._interface.socket_connect(self._socknum, host, port, conn_mode=conntype):
116115
raise ConnectionError("Failed to connect to host", host)
117116
self._buffer = b""
118117

@@ -159,9 +158,7 @@ def recv_into(self, buffer, nbytes: int = 0):
159158
# esp32spi_wsgiserver: socket_readline
160159
if len(self._buffer) > 0:
161160
bytes_to_read = min(num_to_read, len(self._buffer))
162-
buffer[num_read : num_read + bytes_to_read] = self._buffer[
163-
:bytes_to_read
164-
]
161+
buffer[num_read : num_read + bytes_to_read] = self._buffer[:bytes_to_read]
165162
num_read += bytes_to_read
166163
num_to_read -= bytes_to_read
167164
self._buffer = self._buffer[bytes_to_read:]
@@ -171,9 +168,7 @@ def recv_into(self, buffer, nbytes: int = 0):
171168
num_avail = self._available()
172169
if num_avail > 0:
173170
last_read_time = time.monotonic()
174-
bytes_read = self._interface.socket_read(
175-
self._socknum, min(num_to_read, num_avail)
176-
)
171+
bytes_read = self._interface.socket_read(self._socknum, min(num_to_read, num_avail))
177172
buffer[num_read : num_read + len(bytes_read)] = bytes_read
178173
num_read += len(bytes_read)
179174
num_to_read -= len(bytes_read)
@@ -194,9 +189,7 @@ def settimeout(self, value):
194189
def _available(self):
195190
"""Returns how many bytes of data are available to be read (up to the MAX_PACKET length)"""
196191
if self._socknum != SocketPool.NO_SOCKET_AVAIL:
197-
return min(
198-
self._interface.socket_available(self._socknum), SocketPool.MAX_PACKET
199-
)
192+
return min(self._interface.socket_available(self._socknum), SocketPool.MAX_PACKET)
200193
return 0
201194

202195
def _connected(self):
@@ -206,7 +199,7 @@ def _connected(self):
206199
if self._available():
207200
return True
208201
status = self._interface.socket_status(self._socknum)
209-
result = status not in (
202+
result = status not in {
210203
esp32spi.SOCKET_LISTEN,
211204
esp32spi.SOCKET_CLOSED,
212205
esp32spi.SOCKET_FIN_WAIT_1,
@@ -215,7 +208,7 @@ def _connected(self):
215208
esp32spi.SOCKET_SYN_SENT,
216209
esp32spi.SOCKET_SYN_RCVD,
217210
esp32spi.SOCKET_CLOSE_WAIT,
218-
)
211+
}
219212
if not result:
220213
self.close()
221214
self._socknum = SocketPool.NO_SOCKET_AVAIL

‎adafruit_esp32spi/adafruit_esp32spi_wifimanager.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,16 @@
1111
* Author(s): Melissa LeBlanc-Williams, ladyada
1212
"""
1313

14-
# pylint: disable=no-name-in-module
15-
1614
import warnings
1715
from time import sleep
18-
from micropython import const
16+
1917
import adafruit_connection_manager
2018
import adafruit_requests
19+
from micropython import const
20+
2121
from adafruit_esp32spi import adafruit_esp32spi
2222

2323

24-
# pylint: disable=too-many-instance-attributes
2524
class WiFiManager:
2625
"""
2726
A class to help manage the Wifi connection
@@ -30,7 +29,6 @@ class WiFiManager:
3029
NORMAL = const(1)
3130
ENTERPRISE = const(2)
3231

33-
# pylint: disable=too-many-arguments
3432
def __init__(
3533
self,
3634
esp,
@@ -112,9 +110,7 @@ def connect(self):
112110
raise TypeError("Invalid WiFi connection type specified")
113111

114112
def _get_next_ap(self):
115-
if isinstance(self.ssid, (tuple, list)) and isinstance(
116-
self.password, (tuple, list)
117-
):
113+
if isinstance(self.ssid, (tuple, list)) and isinstance(self.password, (tuple, list)):
118114
if not self.ssid or not self.password:
119115
raise ValueError("SSID and Password should contain at least 1 value")
120116
if len(self.ssid) != len(self.password):
@@ -124,9 +120,7 @@ def _get_next_ap(self):
124120
if self._ap_index >= len(self.ssid):
125121
self._ap_index = 0
126122
return access_point
127-
if isinstance(self.ssid, (tuple, list)) or isinstance(
128-
self.password, (tuple, list)
129-
):
123+
if isinstance(self.ssid, (tuple, list)) or isinstance(self.password, (tuple, list)):
130124
raise NotImplementedError(
131125
"If using multiple passwords, both SSID and Password should be lists or tuples"
132126
)
@@ -168,9 +162,7 @@ def create_ap(self):
168162
print("Waiting for AP to be initialized...")
169163
self.pixel_status((100, 0, 0))
170164
if self.password:
171-
self.esp.create_AP(
172-
bytes(self.ssid, "utf-8"), bytes(self.password, "utf-8")
173-
)
165+
self.esp.create_AP(bytes(self.ssid, "utf-8"), bytes(self.password, "utf-8"))
174166
else:
175167
self.esp.create_AP(bytes(self.ssid, "utf-8"), None)
176168
failure_count = 0
@@ -182,7 +174,7 @@ def create_ap(self):
182174
failure_count = 0
183175
self.reset()
184176
continue
185-
print("Access Point created! Connect to ssid:\n {}".format(self.ssid))
177+
print(f"Access Point created! Connect to ssid:\n {self.ssid}")
186178

187179
def connect_enterprise(self):
188180
"""
@@ -197,9 +189,7 @@ def connect_enterprise(self):
197189
while not self.esp.is_connected:
198190
try:
199191
if self.debug:
200-
print(
201-
"Waiting for the ESP32 to connect to the WPA2 Enterprise AP..."
202-
)
192+
print("Waiting for the ESP32 to connect to the WPA2 Enterprise AP...")
203193
self.pixel_status((100, 0, 0))
204194
sleep(1)
205195
failure_count = 0
@@ -356,13 +346,11 @@ def signal_strength(self):
356346
return self.esp.ap_info.rssi
357347

358348

359-
# pylint: disable=too-many-instance-attributes
360349
class ESPSPI_WiFiManager(WiFiManager):
361350
"""
362351
A legacy class to help manage the Wifi connection. Please update to using WiFiManager
363352
"""
364353

365-
# pylint: disable=too-many-arguments
366354
def __init__(
367355
self,
368356
esp,

‎adafruit_esp32spi/digitalio.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
https://github.com/adafruit/Adafruit_Blinka/blob/master/src/adafruit_blinka/microcontroller/bcm283x/pin.py
1414
https://github.com/adafruit/Adafruit_Blinka/blob/master/src/digitalio.py
1515
"""
16+
1617
from micropython import const
1718

1819

@@ -28,7 +29,6 @@ class Pin:
2829
or the use of internal pull-up resistors.
2930
"""
3031

31-
# pylint: disable=invalid-name
3232
IN = const(0x00)
3333
OUT = const(0x01)
3434
LOW = const(0x00)
@@ -78,15 +78,12 @@ def value(self, val=None):
7878
else:
7979
raise ValueError("Invalid value for pin")
8080
else:
81-
raise NotImplementedError(
82-
"digitalRead not currently implemented in esp32spi"
83-
)
81+
raise NotImplementedError("digitalRead not currently implemented in esp32spi")
8482

8583
def __repr__(self):
8684
return str(self.pin_id)
8785

8886

89-
# pylint: disable = too-few-public-methods
9087
class DriveMode:
9188
"""DriveMode Enum."""
9289

@@ -118,7 +115,6 @@ class DigitalInOut:
118115

119116
_pin = None
120117

121-
# pylint: disable = attribute-defined-outside-init
122118
def __init__(self, esp, pin):
123119
self._esp = esp
124120
self._pin = Pin(pin, self._esp)
@@ -149,9 +145,7 @@ def switch_to_input(self, pull=None):
149145
150146
:param Pull pull: Pull configuration for the input.
151147
"""
152-
raise NotImplementedError(
153-
"Digital reads are not currently supported in ESP32SPI."
154-
)
148+
raise NotImplementedError("Digital reads are not currently supported in ESP32SPI.")
155149

156150
@property
157151
def direction(self):
@@ -207,8 +201,6 @@ def drive_mode(self, mode):
207201
Either PUSH_PULL or OPEN_DRAIN
208202
"""
209203
if mode is DriveMode.OPEN_DRAIN:
210-
raise NotImplementedError(
211-
"Drive mode %s not implemented in ESP32SPI." % mode
212-
)
204+
raise NotImplementedError("Drive mode %s not implemented in ESP32SPI." % mode)
213205
if mode is DriveMode.PUSH_PULL:
214206
self._pin.init(mode=Pin.OUT)

‎docs/api.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
.. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py)
55
.. use this format as the module name: "adafruit_foo.foo"
66
7+
API Reference
8+
#############
9+
710
.. automodule:: adafruit_esp32spi.adafruit_esp32spi
811
:members:
912

‎docs/conf.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
# -*- coding: utf-8 -*-
2-
31
# SPDX-FileCopyrightText: 2019 ladyada for Adafruit Industries
42
#
53
# SPDX-License-Identifier: MIT
64

5+
import datetime
76
import os
87
import sys
9-
import datetime
108

119
sys.path.insert(0, os.path.abspath(".."))
1210

@@ -52,9 +50,7 @@
5250
creation_year = "2019"
5351
current_year = str(datetime.datetime.now().year)
5452
year_duration = (
55-
current_year
56-
if current_year == creation_year
57-
else creation_year + " - " + current_year
53+
current_year if current_year == creation_year else creation_year + " - " + current_year
5854
)
5955
copyright = year_duration + " ladyada"
6056
author = "ladyada"

‎examples/esp32spi_aio_post.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33

44
import time
55
from os import getenv
6+
67
import board
78
import busio
8-
from digitalio import DigitalInOut
99
import neopixel
10+
from digitalio import DigitalInOut
11+
1012
from adafruit_esp32spi import adafruit_esp32spi
1113
from adafruit_esp32spi.adafruit_esp32spi_wifimanager import WiFiManager
1214

@@ -60,11 +62,7 @@
6062
feed = "test"
6163
payload = {"value": data}
6264
response = wifi.post(
63-
"https://io.adafruit.com/api/v2/"
64-
+ aio_username
65-
+ "/feeds/"
66-
+ feed
67-
+ "/data",
65+
"https://io.adafruit.com/api/v2/" + aio_username + "/feeds/" + feed + "/data",
6866
json=payload,
6967
headers={"X-AIO-KEY": aio_key},
7068
)

‎examples/esp32spi_cheerlights.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
import time
55
from os import getenv
6+
7+
import adafruit_fancyled.adafruit_fancyled as fancy
68
import board
79
import busio
8-
from digitalio import DigitalInOut
9-
1010
import neopixel
11-
import adafruit_fancyled.adafruit_fancyled as fancy
11+
from digitalio import DigitalInOut
1212

1313
from adafruit_esp32spi import adafruit_esp32spi
1414
from adafruit_esp32spi.adafruit_esp32spi_wifimanager import WiFiManager

‎examples/esp32spi_ipconfig.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33

44
import time
55
from os import getenv
6+
67
import board
78
import busio
89
from digitalio import DigitalInOut
10+
911
import adafruit_esp32spi.adafruit_esp32spi_socketpool as socketpool
1012
from adafruit_esp32spi import adafruit_esp32spi
1113

‎examples/esp32spi_localtime.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33

44
import time
55
from os import getenv
6+
67
import board
78
import busio
8-
from digitalio import DigitalInOut
99
import neopixel
1010
import rtc
11+
from digitalio import DigitalInOut
12+
1113
from adafruit_esp32spi import adafruit_esp32spi
1214
from adafruit_esp32spi.adafruit_esp32spi_wifimanager import WiFiManager
1315

@@ -66,18 +68,16 @@
6668
json = response.json()
6769
current_time = json["datetime"]
6870
the_date, the_time = current_time.split("T")
69-
year, month, mday = [int(x) for x in the_date.split("-")]
71+
year, month, mday = (int(x) for x in the_date.split("-"))
7072
the_time = the_time.split(".")[0]
71-
hours, minutes, seconds = [int(x) for x in the_time.split(":")]
73+
hours, minutes, seconds = (int(x) for x in the_time.split(":"))
7274

7375
# We can also fill in these extra nice things
7476
year_day = json["day_of_year"]
7577
week_day = json["day_of_week"]
7678
is_dst = json["dst"]
7779

78-
now = time.struct_time(
79-
(year, month, mday, hours, minutes, seconds, week_day, year_day, is_dst)
80-
)
80+
now = time.struct_time((year, month, mday, hours, minutes, seconds, week_day, year_day, is_dst))
8181
print(now)
8282
the_rtc.datetime = now
8383

‎examples/esp32spi_simpletest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
# SPDX-License-Identifier: MIT
33

44
from os import getenv
5+
6+
import adafruit_connection_manager
7+
import adafruit_requests
58
import board
69
import busio
710
from digitalio import DigitalInOut
8-
import adafruit_connection_manager
9-
import adafruit_requests
11+
1012
from adafruit_esp32spi import adafruit_esp32spi
1113

1214
# Get wifi details and more from a settings.toml file
@@ -69,9 +71,7 @@
6971
continue
7072
print("Connected to", esp.ap_info.ssid, "\tRSSI:", esp.ap_info.rssi)
7173
print("My IP address is", esp.ipv4_address)
72-
print(
73-
"IP lookup adafruit.com: %s" % esp.pretty_ip(esp.get_host_by_name("adafruit.com"))
74-
)
74+
print("IP lookup adafruit.com: %s" % esp.pretty_ip(esp.get_host_by_name("adafruit.com")))
7575
print("Ping google.com: %d ms" % esp.ping("google.com"))
7676

7777
# esp._debug = True

‎examples/esp32spi_simpletest_rp2040.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
# SPDX-License-Identifier: MIT
33

44
from os import getenv
5+
6+
import adafruit_connection_manager
7+
import adafruit_requests
58
import board
69
import busio
710
from digitalio import DigitalInOut
8-
import adafruit_connection_manager
9-
import adafruit_requests
11+
1012
from adafruit_esp32spi import adafruit_esp32spi
1113

1214
# Get wifi details and more from a settings.toml file
@@ -48,9 +50,7 @@
4850
continue
4951
print("Connected to", esp.ap_info.ssid, "\tRSSI:", esp.ap_info.rssi)
5052
print("My IP address is", esp.ipv4_address)
51-
print(
52-
"IP lookup adafruit.com: %s" % esp.pretty_ip(esp.get_host_by_name("adafruit.com"))
53-
)
53+
print("IP lookup adafruit.com: %s" % esp.pretty_ip(esp.get_host_by_name("adafruit.com")))
5454
print("Ping google.com: %d ms" % esp.ping("google.com"))
5555

5656
# esp._debug = True

‎examples/esp32spi_tcp_client.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
# SPDX-License-Identifier: MIT
33

44
from os import getenv
5+
56
import board
67
import busio
78
from digitalio import DigitalInOut
8-
from adafruit_esp32spi import adafruit_esp32spi
9+
910
import adafruit_esp32spi.adafruit_esp32spi_socketpool as socketpool
11+
from adafruit_esp32spi import adafruit_esp32spi
1012

1113
# Get wifi details and more from a settings.toml file
1214
# tokens used by this Demo: CIRCUITPY_WIFI_SSID, CIRCUITPY_WIFI_PASSWORD
@@ -21,11 +23,10 @@
2123
# Secondary (SCK1) SPI used to connect to WiFi board on Arduino Nano Connect RP2040
2224
if "SCK1" in dir(board):
2325
spi = busio.SPI(board.SCK1, board.MOSI1, board.MISO1)
26+
elif "SPI" in dir(board):
27+
spi = board.SPI()
2428
else:
25-
if "SPI" in dir(board):
26-
spi = board.SPI()
27-
else:
28-
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
29+
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
2930
# PyPortal or similar; edit pins as needed
3031
esp32_cs = DigitalInOut(board.ESP_CS)
3132
esp32_ready = DigitalInOut(board.ESP_BUSY)

‎examples/esp32spi_udp_client.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
import struct
55
import time
66
from os import getenv
7+
78
import board
89
import busio
910
from digitalio import DigitalInOut
10-
from adafruit_esp32spi import adafruit_esp32spi
11+
1112
import adafruit_esp32spi.adafruit_esp32spi_socketpool as socketpool
13+
from adafruit_esp32spi import adafruit_esp32spi
1214

1315
# Get wifi details and more from a settings.toml file
1416
# tokens used by this Demo: CIRCUITPY_WIFI_SSID, CIRCUITPY_WIFI_PASSWORD
@@ -24,11 +26,10 @@
2426
# Secondary (SCK1) SPI used to connect to WiFi board on Arduino Nano Connect RP2040
2527
if "SCK1" in dir(board):
2628
spi = busio.SPI(board.SCK1, board.MOSI1, board.MISO1)
29+
elif "SPI" in dir(board):
30+
spi = board.SPI()
2731
else:
28-
if "SPI" in dir(board):
29-
spi = board.SPI()
30-
else:
31-
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
32+
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
3233
# PyPortal or similar; edit pins as needed
3334
esp32_cs = DigitalInOut(board.ESP_CS)
3435
esp32_ready = DigitalInOut(board.ESP_BUSY)

‎examples/esp32spi_wpa2ent_aio_post.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33

44
import time
55
from os import getenv
6+
67
import board
78
import busio
8-
from digitalio import DigitalInOut
99
import neopixel
10+
from digitalio import DigitalInOut
11+
1012
from adafruit_esp32spi import adafruit_esp32spi
1113
from adafruit_esp32spi.adafruit_esp32spi_wifimanager import WiFiManager
1214

@@ -74,11 +76,7 @@
7476
feed = "test"
7577
payload = {"value": data}
7678
response = wifi.post(
77-
"https://io.adafruit.com/api/v2/"
78-
+ aio_username
79-
+ "/feeds/"
80-
+ feed
81-
+ "/data",
79+
"https://io.adafruit.com/api/v2/" + aio_username + "/feeds/" + feed + "/data",
8280
json=payload,
8381
headers={"X-AIO-KEY": aio_key},
8482
)

‎examples/esp32spi_wpa2ent_simpletest.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111

1212
import re
1313
import time
14+
15+
import adafruit_connection_manager
16+
import adafruit_requests
1417
import board
1518
import busio
1619
from digitalio import DigitalInOut
17-
import adafruit_connection_manager
18-
import adafruit_requests
20+
1921
from adafruit_esp32spi import adafruit_esp32spi
2022

2123

@@ -26,9 +28,7 @@ def version_compare(version1, version2):
2628
def normalize(v):
2729
return [int(x) for x in re.sub(r"(\.0+)*$", "", v).split(".")]
2830

29-
return (normalize(version1) > normalize(version2)) - (
30-
normalize(version1) < normalize(version2)
31-
)
31+
return (normalize(version1) > normalize(version2)) - (normalize(version1) < normalize(version2))
3232

3333

3434
print("ESP32 SPI WPA2 Enterprise test")
@@ -98,9 +98,7 @@ def normalize(v):
9898
print("")
9999
print("Connected to", esp.ap_info.ssid, "\tRSSI:", esp.ap_info.rssi)
100100
print("My IP address is", esp.ipv4_address)
101-
print(
102-
"IP lookup adafruit.com: %s" % esp.pretty_ip(esp.get_host_by_name("adafruit.com"))
103-
)
101+
print("IP lookup adafruit.com: %s" % esp.pretty_ip(esp.get_host_by_name("adafruit.com")))
104102
print("Ping google.com: %d ms" % esp.ping("google.com"))
105103

106104
print("Done!")

‎examples/gpio/esp32spi_gpio.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5-
import time
65
import random
6+
import time
7+
78
import board
8-
from digitalio import DigitalInOut, Direction
99
import pulseio
10-
from adafruit_esp32spi import adafruit_esp32spi
10+
from digitalio import DigitalInOut, Direction
1111

12+
from adafruit_esp32spi import adafruit_esp32spi
1213

1314
# ESP32SPI Digital and Analog Pin Reads & Writes
1415

@@ -69,11 +70,7 @@ def esp_init_pin_modes(din, dout):
6970

7071
print("ESP32 Firmware:", esp.firmware_version)
7172

72-
print(
73-
"ESP32 MAC: {5:02X}:{4:02X}:{3:02X}:{2:02X}:{1:02X}:{0:02X}".format(
74-
*esp.MAC_address
75-
)
76-
)
73+
print("ESP32 MAC: {5:02X}:{4:02X}:{3:02X}:{2:02X}:{1:02X}:{0:02X}".format(*esp.MAC_address))
7774

7875
# initial digital write values
7976
m4_d_w_val = False
@@ -113,7 +110,7 @@ def esp_init_pin_modes(din, dout):
113110
"Potentiometer --> ESP read: ",
114111
esp_a_r_val,
115112
" (",
116-
"{:1.1f}".format(esp_a_r_val * 3.3 / 65536),
113+
f"{esp_a_r_val * 3.3 / 65536:1.1f}",
117114
"v)",
118115
sep="",
119116
)
@@ -128,12 +125,12 @@ def esp_init_pin_modes(din, dout):
128125
esp.set_analog_write(ESP_A_W_PIN, esp_a_w_val)
129126
print(
130127
"ESP wrote: ",
131-
"{:1.2f}".format(esp_a_w_val),
128+
f"{esp_a_w_val:1.2f}",
132129
" (",
133-
"{:d}".format(int(esp_a_w_val * 65536)),
130+
f"{int(esp_a_w_val * 65536):d}",
134131
")",
135132
" (",
136-
"{:1.1f}".format(esp_a_w_val * 3.3),
133+
f"{esp_a_w_val * 3.3:1.1f}",
137134
"v)",
138135
sep="",
139136
end=" ",
@@ -149,12 +146,12 @@ def esp_init_pin_modes(din, dout):
149146
duty = M4_A_R_PIN[0] / (M4_A_R_PIN[0] + M4_A_R_PIN[1])
150147
print(
151148
"--> M4 read: ",
152-
"{:1.2f}".format(duty),
149+
f"{duty:1.2f}",
153150
" (",
154-
"{:d}".format(int(duty * 65536)),
151+
f"{int(duty * 65536):d}",
155152
")",
156153
" (",
157-
"{:1.1f}".format(duty * 3.3),
154+
f"{duty * 3.3:1.1f}",
158155
"v)",
159156
" [len=",
160157
len(M4_A_R_PIN),

‎ruff.toml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
target-version = "py38"
6+
line-length = 100
7+
8+
[lint]
9+
preview = true
10+
select = ["I", "PL", "UP"]
11+
12+
extend-select = [
13+
"D419", # empty-docstring
14+
"E501", # line-too-long
15+
"W291", # trailing-whitespace
16+
"PLC0414", # useless-import-alias
17+
"PLC2401", # non-ascii-name
18+
"PLC2801", # unnecessary-dunder-call
19+
"PLC3002", # unnecessary-direct-lambda-call
20+
"E999", # syntax-error
21+
"PLE0101", # return-in-init
22+
"F706", # return-outside-function
23+
"F704", # yield-outside-function
24+
"PLE0116", # continue-in-finally
25+
"PLE0117", # nonlocal-without-binding
26+
"PLE0241", # duplicate-bases
27+
"PLE0302", # unexpected-special-method-signature
28+
"PLE0604", # invalid-all-object
29+
"PLE0605", # invalid-all-format
30+
"PLE0643", # potential-index-error
31+
"PLE0704", # misplaced-bare-raise
32+
"PLE1141", # dict-iter-missing-items
33+
"PLE1142", # await-outside-async
34+
"PLE1205", # logging-too-many-args
35+
"PLE1206", # logging-too-few-args
36+
"PLE1307", # bad-string-format-type
37+
"PLE1310", # bad-str-strip-call
38+
"PLE1507", # invalid-envvar-value
39+
"PLE2502", # bidirectional-unicode
40+
"PLE2510", # invalid-character-backspace
41+
"PLE2512", # invalid-character-sub
42+
"PLE2513", # invalid-character-esc
43+
"PLE2514", # invalid-character-nul
44+
"PLE2515", # invalid-character-zero-width-space
45+
"PLR0124", # comparison-with-itself
46+
"PLR0202", # no-classmethod-decorator
47+
"PLR0203", # no-staticmethod-decorator
48+
"UP004", # useless-object-inheritance
49+
"PLR0206", # property-with-parameters
50+
"PLR0904", # too-many-public-methods
51+
"PLR0911", # too-many-return-statements
52+
"PLR0912", # too-many-branches
53+
"PLR0913", # too-many-arguments
54+
"PLR0914", # too-many-locals
55+
"PLR0915", # too-many-statements
56+
"PLR0916", # too-many-boolean-expressions
57+
"PLR1702", # too-many-nested-blocks
58+
"PLR1704", # redefined-argument-from-local
59+
"PLR1711", # useless-return
60+
"C416", # unnecessary-comprehension
61+
"PLR1733", # unnecessary-dict-index-lookup
62+
"PLR1736", # unnecessary-list-index-lookup
63+
64+
# ruff reports this rule is unstable
65+
#"PLR6301", # no-self-use
66+
67+
"PLW0108", # unnecessary-lambda
68+
"PLW0120", # useless-else-on-loop
69+
"PLW0127", # self-assigning-variable
70+
"PLW0129", # assert-on-string-literal
71+
"B033", # duplicate-value
72+
"PLW0131", # named-expr-without-context
73+
"PLW0245", # super-without-brackets
74+
"PLW0406", # import-self
75+
"PLW0602", # global-variable-not-assigned
76+
"PLW0603", # global-statement
77+
"PLW0604", # global-at-module-level
78+
79+
# fails on the try: import typing used by libraries
80+
#"F401", # unused-import
81+
82+
"F841", # unused-variable
83+
"E722", # bare-except
84+
"PLW0711", # binary-op-exception
85+
"PLW1501", # bad-open-mode
86+
"PLW1508", # invalid-envvar-default
87+
"PLW1509", # subprocess-popen-preexec-fn
88+
"PLW2101", # useless-with-lock
89+
"PLW3301", # nested-min-max
90+
]
91+
92+
ignore = [
93+
"PLR2004", # magic-value-comparison
94+
"UP030", # format literals
95+
"PLW1514", # unspecified-encoding
96+
"PLR0913", # too-many-arguments
97+
"PLR0915", # too-many-statements
98+
"PLR0917", # too-many-positional-arguments
99+
"PLR0904", # too-many-public-methods
100+
"PLR0912", # too-many-branches
101+
"PLR0916", # too-many-boolean-expressions
102+
]
103+
104+
[format]
105+
line-ending = "lf"

0 commit comments

Comments
 (0)
Please sign in to comment.