Skip to content

Commit 1f7b5b1

Browse files
committed
ruff config file. update copyright.
1 parent e67aff8 commit 1f7b5b1

File tree

8 files changed

+115
-41
lines changed

8 files changed

+115
-41
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries
1+
# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò
2+
# SPDX-FileCopyrightText: 2024 Justin Myers
23
#
34
# SPDX-License-Identifier: Unlicense
45

adafruit_pyportal/__init__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,7 @@ def __init__( # noqa: PLR0912,PLR0913,PLR0915 Too many branches,Too many argume
233233
self.set_caption(caption_text, caption_position, caption_color)
234234

235235
if text_font:
236-
if text_position is not None and isinstance(
237-
text_position[0], (list, tuple)
238-
):
236+
if text_position is not None and isinstance(text_position[0], (list, tuple)):
239237
num = len(text_position)
240238
if not text_wrap:
241239
text_wrap = [0] * num
@@ -329,9 +327,7 @@ def fetch(self, refresh_url=None, timeout=10, force_content_type=None): # noqa:
329327
supervisor.reload()
330328

331329
try:
332-
filename, position = self.network.process_image(
333-
json_out, self.peripherals.sd_check()
334-
)
330+
filename, position = self.network.process_image(json_out, self.peripherals.sd_check())
335331
if filename and position is not None:
336332
self.graphics.set_background(filename, position)
337333
except ValueError as error:

adafruit_pyportal/network.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ def image_converter_url(self, image_url, width, height, color_depth=16):
120120
aio_key = self._get_setting("AIO_KEY")
121121
except KeyError as error:
122122
raise KeyError(
123-
"\n\nOur image converter service require 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'"
123+
"\n\nOur image converter service require a login/password to rate-limit. "
124+
"Please register for a free adafruit.io account and place the user/key in "
125+
"your secrets file under 'aio_username' and 'aio_key'"
124126
) from error
125127

126128
return IMAGE_CONVERTER_SERVICE % (
@@ -163,11 +165,7 @@ def process_image(self, json_data, sd_card=False): # noqa: PLR0912 Too many bra
163165
if iwidth < iheight:
164166
image_url = self.image_converter_url(
165167
image_url,
166-
int(
167-
self._image_resize[1]
168-
* self._image_resize[1]
169-
/ self._image_resize[0]
170-
),
168+
int(self._image_resize[1] * self._image_resize[1] / self._image_resize[0]),
171169
self._image_resize[1],
172170
)
173171
else:
@@ -187,16 +185,14 @@ def process_image(self, json_data, sd_card=False): # noqa: PLR0912 Too many bra
187185
self.wget(image_url, filename, chunk_size=chunk_size)
188186
except OSError as error:
189187
raise OSError(
190-
"""\n\nNo writable filesystem found for saving datastream. Insert an SD card or set internal filesystem to be unsafe by setting 'disable_concurrent_write_protection' in the mount options in boot.py"""
188+
"""\n\nNo writable filesystem found for saving datastream.
189+
Insert an SD card or set internal filesystem to be unsafe by
190+
setting 'disable_concurrent_write_protection' in the mount options in boot.py"""
191191
) from error
192192
except RuntimeError as error:
193193
raise RuntimeError("wget didn't write a complete file") from error
194194
if iwidth < iheight:
195-
pwidth = int(
196-
self._image_resize[1]
197-
* self._image_resize[1]
198-
/ self._image_resize[0]
199-
)
195+
pwidth = int(self._image_resize[1] * self._image_resize[1] / self._image_resize[0])
200196
position = (
201197
self._image_position[0] + int((self._image_resize[0] - pwidth) / 2),
202198
self._image_position[1],

adafruit_pyportal/peripherals.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,11 @@ def __init__(self, spi, display, splash_group, debug=False): # noqa: PLR0912,PL
109109

110110
if debug:
111111
print("Init cursor")
112-
self.mouse_cursor = Cursor(
113-
board.DISPLAY, display_group=splash_group, cursor_speed=8
114-
)
112+
self.mouse_cursor = Cursor(board.DISPLAY, display_group=splash_group, cursor_speed=8)
115113
self.mouse_cursor.hide()
116114
self.cursor = CursorManager(self.mouse_cursor)
117115
else:
118-
raise AttributeError(
119-
"PyPortal module requires either a touchscreen or gamepad."
120-
)
116+
raise AttributeError("PyPortal module requires either a touchscreen or gamepad.")
121117

122118
gc.collect()
123119

docs/conf.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@
7272
creation_year = "2019"
7373
current_year = str(datetime.datetime.now().year)
7474
year_duration = (
75-
current_year
76-
if current_year == creation_year
77-
else creation_year + " - " + current_year
75+
current_year if current_year == creation_year else creation_year + " - " + current_year
7876
)
7977
copyright = year_duration + " Limor Fried"
8078
author = "Limor Fried"

examples/pyportal_internet_json_fetching.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@
5555
continue
5656
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)
5757
print("My IP address is", esp.pretty_ip(esp.ip_address))
58-
print(
59-
"IP lookup adafruit.com: %s" % esp.pretty_ip(esp.get_host_by_name("adafruit.com"))
60-
)
58+
print("IP lookup adafruit.com: %s" % esp.pretty_ip(esp.get_host_by_name("adafruit.com")))
6159
print("Ping google.com: %d ms" % esp.ping("google.com"))
6260

6361
# esp._debug = True

pyproject.toml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,6 @@ classifiers = [
3838
]
3939
dynamic = ["dependencies", "optional-dependencies"]
4040

41-
[tool.ruff]
42-
target-version = "py38"
43-
44-
[tool.ruff.lint]
45-
select = ["I", "PL", "UP"]
46-
ignore = ["PLR2004", "UP030"]
47-
48-
[tool.ruff.format]
49-
line-ending = "lf"
50-
5141
[tool.setuptools]
5242
packages = ["adafruit_pyportal"]
5343

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)