Skip to content

Commit 7e70257

Browse files
committed
ruff config file. Merge main. remove duplicate 'of'.
1 parent ea7fb41 commit 7e70257

File tree

6 files changed

+125
-60
lines changed

6 files changed

+125
-60
lines changed

adafruit_portalbase/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,7 @@ def create_time_alarm(self, sleep_time):
355355
356356
"""
357357
if self._alarm:
358-
return self._alarm.time.TimeAlarm(
359-
monotonic_time=time.monotonic() + sleep_time
360-
)
358+
return self._alarm.time.TimeAlarm(monotonic_time=time.monotonic() + sleep_time)
361359
raise NotImplementedError(
362360
"Alarms not supported. Make sure you have the latest CircuitPython."
363361
)

adafruit_portalbase/graphics.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ def qrcode(self, qr_data, *, qr_size=1, x=0, y=0, qr_color=0x000000): # noqa: P
136136
palette[1] = qr_color
137137

138138
# bitmap the size of the matrix, plus border, monochrome (2 colors)
139-
qr_bitmap = displayio.Bitmap(
140-
qrcode.matrix.width + 2, qrcode.matrix.height + 2, 2
141-
)
139+
qr_bitmap = displayio.Bitmap(qrcode.matrix.width + 2, qrcode.matrix.height + 2, 2)
142140
for i in range(qr_bitmap.width * qr_bitmap.height):
143141
qr_bitmap[i] = 0
144142

adafruit_portalbase/network.py

Lines changed: 22 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@
3838
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PortalBase.git"
3939

4040
# you'll need to pass in an io username and key
41-
TIME_SERVICE = (
42-
"https://io.adafruit.com/api/v2/%s/integrations/time/strftime?x-aio-key=%s"
43-
)
41+
TIME_SERVICE = "https://io.adafruit.com/api/v2/%s/integrations/time/strftime?x-aio-key=%s"
4442
# our strftime is %Y-%m-%d %H:%M:%S.%L %j %u %z %Z see http://strftime.net/ for decoding details
4543
# See https://apidock.com/ruby/DateTime/strftime for full options
4644
TIME_SERVICE_FORMAT = "%Y-%m-%d %H:%M:%S.%L %j %u %z %Z"
@@ -146,9 +144,7 @@ def _get_setting(self, setting_name, show_error=True):
146144
at a minimum in order to use network related features"""
147145
)
148146
else:
149-
print(
150-
f"{setting_name} not found. Please add this setting to settings.toml."
151-
)
147+
print(f"{setting_name} not found. Please add this setting to settings.toml.")
152148
return None
153149

154150
def neo_status(self, value):
@@ -170,16 +166,12 @@ def json_traverse(json, path):
170166
"""
171167
value = json
172168
if not isinstance(path, (list, tuple)):
173-
raise ValueError(
174-
"The json_path parameter should be enclosed in a list or tuple."
175-
)
169+
raise ValueError("The json_path parameter should be enclosed in a list or tuple.")
176170
for x in path:
177171
try:
178172
value = value[x]
179173
except (TypeError, KeyError, IndexError) as error:
180-
raise ValueError(
181-
"The specified json_path was not found in the results."
182-
) from error
174+
raise ValueError("The specified json_path was not found in the results.") from error
183175
gc.collect()
184176
return value
185177

@@ -206,7 +198,7 @@ def get_strftime(self, time_format, location=None, max_attempts=10):
206198
Fetch a custom strftime relative to your location.
207199
208200
:param str location: Your city and country, e.g. ``"America/New_York"``.
209-
:param max_attempts: The maximum number of of attempts to connect to WiFi before
201+
:param max_attempts: The maximum number of attempts to connect to WiFi before
210202
failing or use None to disable. Defaults to 10.
211203
212204
"""
@@ -218,7 +210,9 @@ def get_strftime(self, time_format, location=None, max_attempts=10):
218210
aio_key = self._get_setting("AIO_KEY")
219211
except KeyError:
220212
raise KeyError(
221-
"\n\nOur time service requires a login/password to rate-limit. Please register for a free adafruit.io account and place the user/key in your secrets file under 'AIO_USERNAME' and 'AIO_KEY'"
213+
"\n\nOur time service requires a login/password to rate-limit. "
214+
"Please register for a free adafruit.io account and place the user/key "
215+
"in your secrets file under 'AIO_USERNAME' and 'AIO_KEY'"
222216
) from KeyError
223217

224218
if location is None:
@@ -238,8 +232,7 @@ def get_strftime(self, time_format, location=None, max_attempts=10):
238232
if response.status_code != 200:
239233
print(response)
240234
error_message = (
241-
"Error connecting to Adafruit IO. The response was: "
242-
+ response.text
235+
"Error connecting to Adafruit IO. The response was: " + response.text
243236
)
244237
self.neo_status(STATUS_HTTP_ERROR)
245238
raise RuntimeError(error_message)
@@ -260,16 +253,15 @@ def get_strftime(self, time_format, location=None, max_attempts=10):
260253

261254
def get_local_time(self, location=None, max_attempts=10):
262255
"""
263-
Fetch and "set" the local time of this microcontroller to the local time at the location, using an internet time API.
256+
Fetch and "set" the local time of this microcontroller to the local time at the location,
257+
using an internet time API.
264258
265259
:param str location: Your city and country, e.g. ``"America/New_York"``.
266-
:param max_attempts: The maximum number of of attempts to connect to WiFi before
260+
:param max_attempts: The maximum number of attempts to connect to WiFi before
267261
failing or use None to disable. Defaults to 10.
268262
269263
"""
270-
reply = self.get_strftime(
271-
TIME_SERVICE_FORMAT, location=location, max_attempts=max_attempts
272-
)
264+
reply = self.get_strftime(TIME_SERVICE_FORMAT, location=location, max_attempts=max_attempts)
273265
if reply:
274266
times = reply.split(" ")
275267
the_date = times[0]
@@ -319,9 +311,7 @@ def wget(self, url, filename, *, chunk_size=12000, headers=None):
319311
print("Date: {}".format(headers["date"]))
320312
self.neo_status(STATUS_HTTP_ERROR) # red = http error
321313
raise HttpError(
322-
"Code {}: {}".format(
323-
response.status_code, response.reason.decode("utf-8")
324-
),
314+
"Code {}: {}".format(response.status_code, response.reason.decode("utf-8")),
325315
response,
326316
)
327317

@@ -340,10 +330,7 @@ def wget(self, url, filename, *, chunk_size=12000, headers=None):
340330
remaining -= len(i)
341331
file.write(i)
342332
if self._debug:
343-
print(
344-
"Read %d bytes, %d remaining"
345-
% (content_length - remaining, remaining)
346-
)
333+
print("Read %d bytes, %d remaining" % (content_length - remaining, remaining))
347334
else:
348335
print(".", end="")
349336
if not remaining:
@@ -352,9 +339,7 @@ def wget(self, url, filename, *, chunk_size=12000, headers=None):
352339

353340
response.close()
354341
stamp = time.monotonic() - stamp
355-
print(
356-
"Created file of %d bytes in %0.1f seconds" % (os.stat(filename)[6], stamp)
357-
)
342+
print("Created file of %d bytes in %0.1f seconds" % (os.stat(filename)[6], stamp))
358343
self.neo_status(STATUS_OFF)
359344
if not content_length == os.stat(filename)[6]:
360345
raise RuntimeError
@@ -363,7 +348,7 @@ def connect(self, max_attempts=10):
363348
"""
364349
Connect to WiFi using the settings found in secrets.py
365350
366-
:param max_attempts: The maximum number of of attempts to connect to WiFi before
351+
:param max_attempts: The maximum number of attempts to connect to WiFi before
367352
failing or use None to disable. Defaults to 10.
368353
369354
"""
@@ -392,19 +377,12 @@ def connect(self, max_attempts=10):
392377
while not self._wifi.is_connected:
393378
# secrets dictionary must contain 'ssid' and 'password' at a minimum
394379
print("Connecting to AP", secret_entry["ssid"])
395-
if (
396-
secret_entry["ssid"] == "CHANGE ME"
397-
or secret_entry["password"] == "CHANGE ME"
398-
):
380+
if secret_entry["ssid"] == "CHANGE ME" or secret_entry["password"] == "CHANGE ME":
399381
change_me = "\n" + "*" * 45
400382
change_me += "\nPlease update the 'settings.toml' file on your\n"
401383
change_me += "CIRCUITPY drive to include your local WiFi\n"
402-
change_me += (
403-
"access point SSID name in 'CIRCUITPY_WIFI_SSID' and SSID\n"
404-
)
405-
change_me += (
406-
"password in 'CIRCUITPY_WIFI_PASSWORD'. Then save to reload!\n"
407-
)
384+
change_me += "access point SSID name in 'CIRCUITPY_WIFI_SSID' and SSID\n"
385+
change_me += "password in 'CIRCUITPY_WIFI_PASSWORD'. Then save to reload!\n"
408386
change_me += "*" * 45
409387
raise OSError(change_me)
410388
self._wifi.neo_status(STATUS_NO_CONNECTION) # red = not connected
@@ -425,9 +403,7 @@ def connect(self, max_attempts=10):
425403
if self._wifi.is_connected:
426404
return
427405

428-
raise OSError(
429-
"Maximum number of attempts reached when trying to connect to WiFi"
430-
)
406+
raise OSError("Maximum number of attempts reached when trying to connect to WiFi")
431407

432408
def _get_io_client(self):
433409
if self._io_client is not None:
@@ -609,9 +585,7 @@ def check_response(self, response):
609585
print("Date: {}".format(headers["date"]))
610586
self.neo_status((100, 0, 0)) # red = http error
611587
raise HttpError(
612-
"Code {}: {}".format(
613-
response.status_code, response.reason.decode("utf-8")
614-
),
588+
"Code {}: {}".format(response.status_code, response.reason.decode("utf-8")),
615589
response,
616590
)
617591

adafruit_portalbase/wifi_esp32s2.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ def connect(self, ssid, password):
6262
"""
6363
wifi.radio.connect(ssid, password)
6464
self.pool = socketpool.SocketPool(wifi.radio)
65-
self.requests = adafruit_requests.Session(
66-
self.pool, ssl.create_default_context()
67-
)
65+
self.requests = adafruit_requests.Session(self.pool, ssl.create_default_context())
6866
self._connected = True
6967

7068
def neo_status(self, value):

docs/conf.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@
5858
creation_year = "2020"
5959
current_year = str(datetime.datetime.now().year)
6060
year_duration = (
61-
current_year
62-
if current_year == creation_year
63-
else creation_year + " - " + current_year
61+
current_year if current_year == creation_year else creation_year + " - " + current_year
6462
)
6563
copyright = year_duration + " Melissa LeBlanc-Williams"
6664
author = "Melissa LeBlanc-Williams"

ruff.toml

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

0 commit comments

Comments
 (0)