Skip to content

Commit

Permalink
ruff config file. update copyright.
Browse files Browse the repository at this point in the history
  • Loading branch information
FoamyGuy committed Jul 29, 2024
1 parent e67aff8 commit 1f7b5b1
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 41 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries
# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò
# SPDX-FileCopyrightText: 2024 Justin Myers
#
# SPDX-License-Identifier: Unlicense

Expand Down
8 changes: 2 additions & 6 deletions adafruit_pyportal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,7 @@ def __init__( # noqa: PLR0912,PLR0913,PLR0915 Too many branches,Too many argume
self.set_caption(caption_text, caption_position, caption_color)

if text_font:
if text_position is not None and isinstance(
text_position[0], (list, tuple)
):
if text_position is not None and isinstance(text_position[0], (list, tuple)):
num = len(text_position)
if not text_wrap:
text_wrap = [0] * num
Expand Down Expand Up @@ -329,9 +327,7 @@ def fetch(self, refresh_url=None, timeout=10, force_content_type=None): # noqa:
supervisor.reload()

try:
filename, position = self.network.process_image(
json_out, self.peripherals.sd_check()
)
filename, position = self.network.process_image(json_out, self.peripherals.sd_check())
if filename and position is not None:
self.graphics.set_background(filename, position)
except ValueError as error:
Expand Down
20 changes: 8 additions & 12 deletions adafruit_pyportal/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ def image_converter_url(self, image_url, width, height, color_depth=16):
aio_key = self._get_setting("AIO_KEY")
except KeyError as error:
raise KeyError(
"\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'"
"\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'"
) from error

return IMAGE_CONVERTER_SERVICE % (
Expand Down Expand Up @@ -163,11 +165,7 @@ def process_image(self, json_data, sd_card=False): # noqa: PLR0912 Too many bra
if iwidth < iheight:
image_url = self.image_converter_url(
image_url,
int(
self._image_resize[1]
* self._image_resize[1]
/ self._image_resize[0]
),
int(self._image_resize[1] * self._image_resize[1] / self._image_resize[0]),
self._image_resize[1],
)
else:
Expand All @@ -187,16 +185,14 @@ def process_image(self, json_data, sd_card=False): # noqa: PLR0912 Too many bra
self.wget(image_url, filename, chunk_size=chunk_size)
except OSError as error:
raise OSError(
"""\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"""
"""\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"""
) from error
except RuntimeError as error:
raise RuntimeError("wget didn't write a complete file") from error
if iwidth < iheight:
pwidth = int(
self._image_resize[1]
* self._image_resize[1]
/ self._image_resize[0]
)
pwidth = int(self._image_resize[1] * self._image_resize[1] / self._image_resize[0])
position = (
self._image_position[0] + int((self._image_resize[0] - pwidth) / 2),
self._image_position[1],
Expand Down
8 changes: 2 additions & 6 deletions adafruit_pyportal/peripherals.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,11 @@ def __init__(self, spi, display, splash_group, debug=False): # noqa: PLR0912,PL

if debug:
print("Init cursor")
self.mouse_cursor = Cursor(
board.DISPLAY, display_group=splash_group, cursor_speed=8
)
self.mouse_cursor = Cursor(board.DISPLAY, display_group=splash_group, cursor_speed=8)
self.mouse_cursor.hide()
self.cursor = CursorManager(self.mouse_cursor)
else:
raise AttributeError(
"PyPortal module requires either a touchscreen or gamepad."
)
raise AttributeError("PyPortal module requires either a touchscreen or gamepad.")

gc.collect()

Expand Down
4 changes: 1 addition & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@
creation_year = "2019"
current_year = str(datetime.datetime.now().year)
year_duration = (
current_year
if current_year == creation_year
else creation_year + " - " + current_year
current_year if current_year == creation_year else creation_year + " - " + current_year
)
copyright = year_duration + " Limor Fried"
author = "Limor Fried"
Expand Down
4 changes: 1 addition & 3 deletions examples/pyportal_internet_json_fetching.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@
continue
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)
print("My IP address is", esp.pretty_ip(esp.ip_address))
print(
"IP lookup adafruit.com: %s" % esp.pretty_ip(esp.get_host_by_name("adafruit.com"))
)
print("IP lookup adafruit.com: %s" % esp.pretty_ip(esp.get_host_by_name("adafruit.com")))
print("Ping google.com: %d ms" % esp.ping("google.com"))

# esp._debug = True
Expand Down
10 changes: 0 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,6 @@ classifiers = [
]
dynamic = ["dependencies", "optional-dependencies"]

[tool.ruff]
target-version = "py38"

[tool.ruff.lint]
select = ["I", "PL", "UP"]
ignore = ["PLR2004", "UP030"]

[tool.ruff.format]
line-ending = "lf"

[tool.setuptools]
packages = ["adafruit_pyportal"]

Expand Down
99 changes: 99 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries
#
# SPDX-License-Identifier: MIT

target-version = "py38"
line-length = 100

[lint]
select = ["I", "PL", "UP"]

extend-select = [
"D419", # empty-docstring
"E501", # line-too-long
"W291", # trailing-whitespace
"PLC0414", # useless-import-alias
"PLC2401", # non-ascii-name
"PLC2801", # unnecessary-dunder-call
"PLC3002", # unnecessary-direct-lambda-call
"E999", # syntax-error
"PLE0101", # return-in-init
"F706", # return-outside-function
"F704", # yield-outside-function
"PLE0116", # continue-in-finally
"PLE0117", # nonlocal-without-binding
"PLE0241", # duplicate-bases
"PLE0302", # unexpected-special-method-signature
"PLE0604", # invalid-all-object
"PLE0605", # invalid-all-format
"PLE0643", # potential-index-error
"PLE0704", # misplaced-bare-raise
"PLE1141", # dict-iter-missing-items
"PLE1142", # await-outside-async
"PLE1205", # logging-too-many-args
"PLE1206", # logging-too-few-args
"PLE1307", # bad-string-format-type
"PLE1310", # bad-str-strip-call
"PLE1507", # invalid-envvar-value
"PLE2502", # bidirectional-unicode
"PLE2510", # invalid-character-backspace
"PLE2512", # invalid-character-sub
"PLE2513", # invalid-character-esc
"PLE2514", # invalid-character-nul
"PLE2515", # invalid-character-zero-width-space
"PLR0124", # comparison-with-itself
"PLR0202", # no-classmethod-decorator
"PLR0203", # no-staticmethod-decorator
"UP004", # useless-object-inheritance
"PLR0206", # property-with-parameters
"PLR0904", # too-many-public-methods
"PLR0911", # too-many-return-statements
"PLR0912", # too-many-branches
"PLR0913", # too-many-arguments
"PLR0914", # too-many-locals
"PLR0915", # too-many-statements
"PLR0916", # too-many-boolean-expressions
"PLR1702", # too-many-nested-blocks
"PLR1704", # redefined-argument-from-local
"PLR1711", # useless-return
"C416", # unnecessary-comprehension
"PLR1733", # unnecessary-dict-index-lookup
"PLR1736", # unnecessary-list-index-lookup

# ruff reports this rule is unstable
#"PLR6301", # no-self-use

"PLW0108", # unnecessary-lambda
"PLW0120", # useless-else-on-loop
"PLW0127", # self-assigning-variable
"PLW0129", # assert-on-string-literal
"B033", # duplicate-value
"PLW0131", # named-expr-without-context
"PLW0245", # super-without-brackets
"PLW0406", # import-self
"PLW0602", # global-variable-not-assigned
"PLW0603", # global-statement
"PLW0604", # global-at-module-level

# fails on the try: import typing used by libraries
#"F401", # unused-import

"F841", # unused-variable
"E722", # bare-except
"PLW0711", # binary-op-exception
"PLW1501", # bad-open-mode
"PLW1508", # invalid-envvar-default
"PLW1509", # subprocess-popen-preexec-fn
"PLW2101", # useless-with-lock
"PLW3301", # nested-min-max
]

ignore = [
"PLR2004", # magic-value-comparison
"UP030", # format literals
"PLW1514", # unspecified-encoding

]

[format]
line-ending = "lf"

0 comments on commit 1f7b5b1

Please sign in to comment.