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 cb6b30a

Browse files
authoredMay 16, 2025··
Merge pull request #13 from adafruit/use_ruff
change to ruff
2 parents d37a7ff + d7c2575 commit cb6b30a

File tree

12 files changed

+162
-480
lines changed

12 files changed

+162
-480
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: v2.17.4
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
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
@@ -17,9 +17,9 @@ Introduction
1717
:alt: Build Status
1818

1919

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

2424
Helper library for the Adafruit ESP32-S2 TFT Feather.
2525

‎adafruit_esp32s2tft/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@
2828
"""
2929

3030
import gc
31+
3132
from adafruit_portalbase import PortalBase
32-
from .network import Network
33+
3334
from .graphics import Graphics
35+
from .network import Network
3436
from .peripherals import Peripherals
3537

3638
try:
37-
from typing import Optional, Dict, Union, Callable, Sequence, List
39+
from typing import Callable, Dict, List, Optional, Sequence, Union
40+
3841
from neopixel import NeoPixel
3942
except ImportError:
4043
pass
@@ -69,7 +72,6 @@ class ESP32S2TFT(PortalBase):
6972
7073
"""
7174

72-
# pylint: disable=too-many-instance-attributes, too-many-locals, too-many-branches, too-many-statements
7375
def __init__(
7476
self,
7577
*,
@@ -83,7 +85,7 @@ def __init__(
8385
rotation: int = 0,
8486
scale: int = 1,
8587
debug: bool = False,
86-
use_network: bool = True
88+
use_network: bool = True,
8789
) -> None:
8890
if use_network:
8991
network = Network(

‎adafruit_esp32s2tft/graphics.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,8 @@ class Graphics(GraphicsBase):
4444
4545
"""
4646

47-
# pylint: disable=too-many-instance-attributes, too-many-locals, too-many-branches, too-many-statements, too-few-public-methods
4847
def __init__(
49-
self,
50-
*,
51-
default_bg: int = 0,
52-
rotation: int = 0,
53-
scale: int = 1,
54-
debug: bool = False
48+
self, *, default_bg: int = 0, rotation: int = 0, scale: int = 1, debug: bool = False
5549
) -> None:
5650
self._debug = debug
5751
self.display = board.DISPLAY

‎adafruit_esp32s2tft/network.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@
2828
"""
2929

3030
import ssl
31+
3132
from adafruit_portalbase.network import NetworkBase
3233
from adafruit_portalbase.wifi_esp32s2 import WiFi
3334

3435
try:
35-
from typing import Optional, Union, Callable
36-
from neopixel import NeoPixel
37-
from adafruit_io.adafruit_io import IO_MQTT
36+
from typing import Callable, Optional, Union
37+
3838
import adafruit_minimqtt.adafruit_minimqtt as MQTT
39+
from adafruit_io.adafruit_io import IO_MQTT
40+
from neopixel import NeoPixel
3941
except ImportError:
4042
pass
4143

@@ -56,7 +58,6 @@ class Network(NetworkBase):
5658
5759
"""
5860

59-
# pylint: disable=too-many-instance-attributes, too-many-locals, too-many-branches, too-many-statements
6061
def __init__(
6162
self,
6263
*,
@@ -75,14 +76,13 @@ def init_io_mqtt(self) -> IO_MQTT:
7576
"""Initialize MQTT for Adafruit IO"""
7677
aio_username = self._get_setting["ADAFRUIT_AIO_USERNAME"]
7778
aio_key = self._get_setting["ADAFRUIT_AIO_KEY"]
78-
if None in [aio_username, aio_key]:
79+
if aio_username is None or aio_key is None:
7980
raise AttributeError(
8081
"Adafruit IO keys are kept in settings.toml, please add them there."
8182
)
8283

8384
return self.init_mqtt(IO_MQTT_BROKER, 8883, aio_username, aio_key, True)
8485

85-
# pylint: disable=too-many-arguments
8686
def init_mqtt(
8787
self,
8888
broker: str,
@@ -106,16 +106,12 @@ def init_mqtt(
106106

107107
return self._mqtt_client
108108

109-
# pylint: enable=too-many-arguments
110-
111109
def _get_mqtt_client(self) -> Union[MQTT.MQTT, IO_MQTT]:
112110
if self._mqtt_client is not None:
113111
return self._mqtt_client
114112
raise RuntimeError("Please initialize MQTT before using")
115113

116-
def mqtt_loop(
117-
self, *args: int, suppress_mqtt_errors: bool = True, **kwargs: int
118-
) -> None:
114+
def mqtt_loop(self, *args: int, suppress_mqtt_errors: bool = True, **kwargs: int) -> None:
119115
"""Run the MQTT Loop"""
120116
self._get_mqtt_client()
121117
if suppress_mqtt_errors:
@@ -126,9 +122,8 @@ def mqtt_loop(
126122
print(f"MMQTTException: {err}")
127123
except OSError as err:
128124
print(f"OSError: {err}")
129-
else:
130-
if self._mqtt_client is not None:
131-
self._mqtt_client.loop(*args, **kwargs)
125+
elif self._mqtt_client is not None:
126+
self._mqtt_client.loop(*args, **kwargs)
132127

133128
def mqtt_publish(
134129
self,
@@ -144,13 +139,10 @@ def mqtt_publish(
144139
self._mqtt_client.publish(*args, **kwargs)
145140
except OSError as err:
146141
print(f"OSError: {err}")
147-
else:
148-
if self._mqtt_client is not None:
149-
self._mqtt_client.publish(*args, **kwargs)
142+
elif self._mqtt_client is not None:
143+
self._mqtt_client.publish(*args, **kwargs)
150144

151-
def mqtt_connect(
152-
self, *args: Union[bool, str, int], **kwargs: Union[bool, str, int]
153-
) -> None:
145+
def mqtt_connect(self, *args: Union[bool, str, int], **kwargs: Union[bool, str, int]) -> None:
154146
"""Connect to MQTT"""
155147
self._get_mqtt_client()
156148
if self._mqtt_client is not None:

‎adafruit_esp32s2tft/peripherals.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@
2828
"""
2929

3030
import board
31-
from digitalio import DigitalInOut, Direction, Pull
3231
import neopixel
33-
32+
from digitalio import DigitalInOut, Direction, Pull
3433

3534
__version__ = "0.0.0+auto.0"
3635
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ESP32S2TFT.git"
@@ -45,7 +44,6 @@ class Peripherals:
4544
See https://circuitpython.readthedocs.io/projects/neopixel/en/latest/api.html
4645
"""
4746

48-
# pylint: disable=too-many-instance-attributes, too-many-locals, too-many-branches, too-many-statements
4947
def __init__(self) -> None:
5048
# Neopixel
5149
self.neopixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.3)

‎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_esp32s2tft
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: 2017 Scott Shawcroft, written 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

@@ -57,9 +55,7 @@
5755
creation_year = "2022"
5856
current_year = str(datetime.datetime.now().year)
5957
year_duration = (
60-
current_year
61-
if current_year == creation_year
62-
else creation_year + " - " + current_year
58+
current_year if current_year == creation_year else creation_year + " - " + current_year
6359
)
6460
copyright = year_duration + " Melissa LeBlanc-Williams"
6561
author = "Melissa LeBlanc-Williams"

‎examples/esp32s2tft_simpletest.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
# SPDX-License-Identifier: Unlicense
55

66
import random
7+
78
from rainbowio import colorwheel
9+
810
from adafruit_esp32s2tft import ESP32S2TFT
911

1012
esp32s2tft = ESP32S2TFT(default_bg=0xFFFF00, scale=2, use_network=False)
1113

1214
# Create the labels
13-
esp32s2tft.add_text(
14-
text="ESP32-S2", text_position=(10, 10), text_scale=2, text_color=0xFF00FF
15-
)
15+
esp32s2tft.add_text(text="ESP32-S2", text_position=(10, 10), text_scale=2, text_color=0xFF00FF)
1616
esp32s2tft.add_text(
1717
text="TFT Feather",
1818
text_position=(60, 30),
@@ -29,9 +29,7 @@
2929
esp32s2tft.display.root_group = esp32s2tft.splash
3030

3131
while True:
32-
esp32s2tft.set_text_color(
33-
0xFF0000 if esp32s2tft.peripherals.button else 0x606060, button_label
34-
)
32+
esp32s2tft.set_text_color(0xFF0000 if esp32s2tft.peripherals.button else 0x606060, button_label)
3533
esp32s2tft.peripherals.led = esp32s2tft.peripherals.button
3634
if esp32s2tft.peripherals.button:
3735
esp32s2tft.peripherals.neopixel[0] = colorwheel(random.randint(0, 255))

‎ruff.toml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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+
"PLR6301", # could-be-static no-self-use
103+
"PLC0415", # import outside toplevel
104+
"PLC2701", # private import
105+
]
106+
107+
[format]
108+
line-ending = "lf"

0 commit comments

Comments
 (0)
Please sign in to comment.