Skip to content

Commit daf6bc2

Browse files
committed
use ruff
1 parent c368494 commit daf6bc2

15 files changed

+164
-68
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: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@
2121
2222
"""
2323

24-
from micropython import const
2524
from adafruit_display_shapes.rect import Rect
2625
from adafruit_display_shapes.roundrect import RoundRect
26+
from micropython import const
27+
2728
from adafruit_button.button_base import ButtonBase, _check_color
2829

2930
try:
3031
from typing import Optional, Union
31-
from fontio import FontProtocol
32+
3233
from displayio import Group
34+
from fontio import FontProtocol
3335
except ImportError:
3436
pass
3537

@@ -38,7 +40,6 @@
3840

3941

4042
class Button(ButtonBase):
41-
# pylint: disable=too-many-instance-attributes, too-many-locals
4243
"""Helper class for creating UI buttons for ``displayio``.
4344
4445
:param x: The x position of the button.
@@ -84,9 +85,7 @@ def _create_body(self):
8485
outline=self._outline_color,
8586
)
8687
elif self.style == Button.SHADOWRECT:
87-
self.shadow = Rect(
88-
2, 2, self.width - 2, self.height - 2, fill=self.outline_color
89-
)
88+
self.shadow = Rect(2, 2, self.width - 2, self.height - 2, fill=self.outline_color)
9089
self.body = Rect(
9190
0,
9291
0,
@@ -121,7 +120,7 @@ def _create_body(self):
121120
SHADOWRECT = const(2)
122121
SHADOWROUNDRECT = const(3)
123122

124-
def __init__(
123+
def __init__( # noqa: PLR0913 Too many arguments
125124
self,
126125
*,
127126
x: int,
@@ -138,7 +137,7 @@ def __init__(
138137
selected_fill: Optional[Union[int, tuple[int, int, int]]] = None,
139138
selected_outline: Optional[Union[int, tuple[int, int, int]]] = None,
140139
selected_label: Optional[Union[int, tuple[int, int, int]]] = None,
141-
label_scale: Optional[int] = None
140+
label_scale: Optional[int] = None,
142141
) -> None:
143142
super().__init__(
144143
x=x,

adafruit_button/button_base.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020
https://github.com/adafruit/circuitpython/releases
2121
2222
"""
23+
2324
from adafruit_display_text.bitmap_label import Label
2425
from displayio import Group
2526

2627
try:
2728
from typing import Optional, Union
29+
2830
from fontio import FontProtocol
2931
except ImportError:
3032
pass
@@ -39,7 +41,6 @@ def _check_color(color):
3941

4042

4143
class ButtonBase(Group):
42-
# pylint: disable=too-many-instance-attributes
4344
"""Superclass for creating UI buttons for ``displayio``.
4445
4546
:param x: The x position of the button.
@@ -53,7 +54,7 @@ class ButtonBase(Group):
5354
:param selected_label: Text that appears when selected
5455
"""
5556

56-
def __init__(
57+
def __init__( # noqa: PLR0913 Too many arguments
5758
self,
5859
*,
5960
x: int,
@@ -65,7 +66,7 @@ def __init__(
6566
label_font: Optional[FontProtocol] = None,
6667
label_color: Optional[Union[int, tuple[int, int, int]]] = 0x0,
6768
selected_label: Optional[Union[int, tuple[int, int, int]]] = None,
68-
label_scale: Optional[int] = None
69+
label_scale: Optional[int] = None,
6970
):
7071
super().__init__(x=x, y=y)
7172
self.x = x
@@ -102,20 +103,16 @@ def label(self, newtext: str) -> None:
102103
dims[2] *= self._label.scale
103104
dims[3] *= self._label.scale
104105
if dims[2] >= self.width or dims[3] >= self.height:
105-
while len(self._label.text) > 1 and (
106-
dims[2] >= self.width or dims[3] >= self.height
107-
):
108-
self._label.text = "{}.".format(self._label.text[:-2])
106+
while len(self._label.text) > 1 and (dims[2] >= self.width or dims[3] >= self.height):
107+
self._label.text = f"{self._label.text[:-2]}."
109108
dims = list(self._label.bounding_box)
110109
dims[2] *= self._label.scale
111110
dims[3] *= self._label.scale
112111
if len(self._label.text) <= 1:
113112
raise RuntimeError("Button not large enough for label")
114113
self._label.x = (self.width - dims[2]) // 2
115114
self._label.y = self.height // 2
116-
self._label.color = (
117-
self._label_color if not self.selected else self._selected_label
118-
)
115+
self._label.color = self._label_color if not self.selected else self._selected_label
119116
self.append(self._label)
120117

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

adafruit_button/sprite_button.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@
2020
https://github.com/adafruit/circuitpython/releases
2121
2222
"""
23-
from adafruit_imageload.tilegrid_inflator import inflate_tilegrid
23+
2424
from adafruit_imageload import load
25+
from adafruit_imageload.tilegrid_inflator import inflate_tilegrid
26+
2527
from adafruit_button.button_base import ButtonBase
2628

2729
try:
28-
from typing import Optional, Union, Tuple
30+
from typing import Optional, Tuple, Union
31+
2932
from fontio import FontProtocol
3033
except ImportError:
3134
pass
@@ -48,7 +51,7 @@ class SpriteButton(ButtonBase):
4851
:param int or tuple transparent_index: Index(s) that will be made transparent on the Palette
4952
"""
5053

51-
def __init__(
54+
def __init__( # noqa: PLR0913 Too many arguments
5255
self,
5356
*,
5457
x: int,

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)