Skip to content

Commit da2744d

Browse files
authored
Merge pull request #51 from FoamyGuy/use_ruff
Use ruff
2 parents 014d013 + 3466a7d commit da2744d

15 files changed

+167
-71
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 & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,22 @@
11
# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò
2+
# SPDX-FileCopyrightText: 2024 Justin Myers
23
#
34
# SPDX-License-Identifier: Unlicense
45

56
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
147
- repo: https://github.com/pre-commit/pre-commit-hooks
15-
rev: v4.4.0
8+
rev: v4.5.0
169
hooks:
1710
- id: check-yaml
1811
- id: end-of-file-fixer
1912
- id: trailing-whitespace
20-
- repo: https://github.com/pycqa/pylint
21-
rev: v3.3.1
13+
- repo: https://github.com/astral-sh/ruff-pre-commit
14+
rev: v0.3.4
2215
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
16+
- id: ruff-format
17+
- id: ruff
18+
args: ["--fix"]
19+
- repo: https://github.com/fsfe/reuse-tool
20+
rev: v3.0.1
21+
hooks:
22+
- id: reuse

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_Display_Button/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
UI Buttons for displayio
2121

adafruit_button/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@
2020
https://github.com/adafruit/circuitpython/releases
2121
2222
"""
23+
2324
from adafruit_button.button import Button

adafruit_button/button.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@
2222
2323
"""
2424

25-
from micropython import const
2625
from adafruit_display_shapes.rect import Rect
2726
from adafruit_display_shapes.roundrect import RoundRect
27+
from micropython import const
28+
2829
from adafruit_button.button_base import ButtonBase, _check_color
2930

3031
try:
31-
from typing import Optional, Union, Tuple
32-
from fontio import FontProtocol
32+
from typing import Optional, Tuple, Union
33+
3334
from displayio import Group
35+
from fontio import FontProtocol
3436
except ImportError:
3537
pass
3638

@@ -39,7 +41,6 @@
3941

4042

4143
class Button(ButtonBase):
42-
# pylint: disable=too-many-instance-attributes, too-many-locals
4344
"""Helper class for creating UI buttons for ``displayio``. Provides the following
4445
buttons:
4546
RECT: A rectangular button. SHAWDOWRECT adds a drop shadow.
@@ -100,9 +101,7 @@ def _create_body(self) -> None:
100101
outline=self._outline_color,
101102
)
102103
elif self.style == Button.SHADOWRECT:
103-
self.shadow = Rect(
104-
2, 2, self.width - 2, self.height - 2, fill=self.outline_color
105-
)
104+
self.shadow = Rect(2, 2, self.width - 2, self.height - 2, fill=self.outline_color)
106105
self.body = Rect(
107106
0,
108107
0,
@@ -137,7 +136,7 @@ def _create_body(self) -> None:
137136
SHADOWRECT = const(2)
138137
SHADOWROUNDRECT = const(3)
139138

140-
def __init__(
139+
def __init__( # noqa: PLR0913 Too many arguments
141140
self,
142141
*,
143142
x: int,
@@ -154,7 +153,7 @@ def __init__(
154153
selected_fill: Optional[Union[int, Tuple[int, int, int]]] = None,
155154
selected_outline: Optional[Union[int, Tuple[int, int, int]]] = None,
156155
selected_label: Optional[Union[int, Tuple[int, int, int]]] = None,
157-
label_scale: Optional[int] = 1
156+
label_scale: Optional[int] = 1,
158157
):
159158
super().__init__(
160159
x=x,

adafruit_button/button_base.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
https://github.com/adafruit/circuitpython/releases
2222
2323
"""
24+
25+
import terminalio
2426
from adafruit_display_text.bitmap_label import Label
2527
from displayio import Group
26-
import terminalio
2728

2829
try:
29-
from typing import Optional, Union, Tuple
30+
from typing import Optional, Tuple, Union
31+
3032
from fontio import FontProtocol
3133
except ImportError:
3234
pass
@@ -41,7 +43,6 @@ def _check_color(color: Optional[Union[int, tuple[int, int, int]]]) -> int:
4143

4244

4345
class ButtonBase(Group):
44-
# pylint: disable=too-many-instance-attributes
4546
"""Superclass for creating UI buttons for ``displayio``.
4647
4748
:param int x: The x position of the button.
@@ -60,7 +61,7 @@ class ButtonBase(Group):
6061
:param Optional[int] label_scale: The scale factor used for the label. Defaults to 1.
6162
"""
6263

63-
def __init__(
64+
def __init__( # noqa: PLR0913 Too many arguments
6465
self,
6566
*,
6667
x: int,
@@ -109,20 +110,16 @@ def label(self, newtext: str) -> None:
109110
dims[2] *= self._label.scale
110111
dims[3] *= self._label.scale
111112
if dims[2] >= self.width or dims[3] >= self.height:
112-
while len(self._label.text) > 1 and (
113-
dims[2] >= self.width or dims[3] >= self.height
114-
):
115-
self._label.text = "{}.".format(self._label.text[:-2])
113+
while len(self._label.text) > 1 and (dims[2] >= self.width or dims[3] >= self.height):
114+
self._label.text = f"{self._label.text[:-2]}."
116115
dims = list(self._label.bounding_box)
117116
dims[2] *= self._label.scale
118117
dims[3] *= self._label.scale
119118
if len(self._label.text) <= 1:
120119
raise RuntimeError("Button not large enough for label")
121120
self._label.x = (self.width - dims[2]) // 2
122121
self._label.y = self.height // 2
123-
self._label.color = (
124-
self._label_color if not self.selected else self._selected_label
125-
)
122+
self._label.color = self._label_color if not self.selected else self._selected_label
126123
self.append(self._label)
127124

128125
if (self.selected_label is None) and (self._label_color is not None):

adafruit_button/sprite_button.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@
2121
https://github.com/adafruit/circuitpython/releases
2222
2323
"""
24-
from adafruit_imageload.tilegrid_inflator import inflate_tilegrid
24+
2525
from adafruit_imageload import load
26+
from adafruit_imageload.tilegrid_inflator import inflate_tilegrid
27+
2628
from adafruit_button.button_base import ButtonBase
2729

2830
try:
29-
from typing import Optional, Union, Tuple
31+
from typing import Optional, Tuple, Union
32+
3033
from fontio import FontProtocol
3134
except ImportError:
3235
pass
@@ -56,7 +59,7 @@ class SpriteButton(ButtonBase):
5659
:param Optional[int] label_scale: The scale multiplier of the button label. Defaults to 1.
5760
"""
5861

59-
def __init__(
62+
def __init__( # noqa: PLR0913 Too many arguments
6063
self,
6164
*,
6265
x: int,
@@ -71,7 +74,7 @@ def __init__(
7174
bmp_path: str = None,
7275
selected_bmp_path: Optional[str] = None,
7376
transparent_index: Optional[Union[int, Tuple]] = None,
74-
label_scale: Optional[int] = 1
77+
label_scale: Optional[int] = 1,
7578
):
7679
if bmp_path is None:
7780
raise ValueError("Please supply bmp_path. It cannot be None.")

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: 2021 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

@@ -48,9 +46,7 @@
4846
creation_year = "2019"
4947
current_year = str(datetime.datetime.now().year)
5048
year_duration = (
51-
current_year
52-
if current_year == creation_year
53-
else creation_year + " - " + current_year
49+
current_year if current_year == creation_year else creation_year + " - " + current_year
5450
)
5551
copyright = year_duration + " Limor Fried"
5652
author = "Limor Fried"

examples/display_button_color_properties.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
properties after the button has been initialized.
77
"""
88

9+
import adafruit_touchscreen
910
import board
1011
import displayio
1112
import terminalio
12-
import adafruit_touchscreen
13+
1314
from adafruit_button import Button
1415

1516
# use built in display (MagTag, PyPortal, PyGamer, PyBadge, CLUE, etc.)

examples/display_button_customfont.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
"""
66

77
import os
8+
9+
import adafruit_touchscreen
810
import board
911
import displayio
1012
from adafruit_bitmap_font import bitmap_font
11-
import adafruit_touchscreen
13+
1214
from adafruit_button import Button
1315

1416
# use built in display (MagTag, PyPortal, PyGamer, PyBadge, CLUE, etc.)

examples/display_button_simpletest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
Simple button example.
55
"""
66

7+
import adafruit_touchscreen
78
import board
89
import displayio
910
import terminalio
10-
import adafruit_touchscreen
11+
1112
from adafruit_button import Button
1213

1314
# use built in display (MagTag, PyPortal, PyGamer, PyBadge, CLUE, etc.)

examples/display_button_soundboard.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"""
66

77
import time
8+
89
from adafruit_pyportal import PyPortal
10+
911
from adafruit_button import Button
1012

1113
SHOW_BUTTONS = False

examples/display_button_spritebutton_simpletest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# SPDX-FileCopyrightText: 2022 Tim Cocks for Adafruit Industries
22
# SPDX-License-Identifier: MIT
33
import time
4+
5+
import adafruit_touchscreen
46
import board
57
import displayio
6-
import adafruit_touchscreen
78
import terminalio
9+
810
from adafruit_button.sprite_button import SpriteButton
911

1012
# These pins are used as both analog and digital! XL, XR and YU must be analog

examples/display_button_spritebutton_tft_featherwing_simpletest.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# SPDX-FileCopyrightText: 2024 DJDevon3
22
# SPDX-License-Identifier: MIT
33
import time
4-
import displayio
5-
import terminalio
4+
5+
import adafruit_stmpe610 # TFT Featherwing V1 touch driver
66
import board
77
import digitalio
8+
import displayio
9+
import terminalio
810
from adafruit_hx8357 import HX8357 # TFT Featherwing display driver
9-
import adafruit_stmpe610 # TFT Featherwing V1 touch driver
11+
1012
from adafruit_button.sprite_button import SpriteButton
1113

1214
# 3.5" TFT Featherwing is 480x320

0 commit comments

Comments
 (0)