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 cb0b62b

Browse files
authoredMay 14, 2025··
Merge pull request #75 from adafruit/use_ruff
change to ruff
2 parents d3d8d73 + 4abddfd commit cb0b62b

File tree

10 files changed

+160
-467
lines changed

10 files changed

+160
-467
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
@@ -14,9 +14,9 @@ Introduction
1414
:target: https://github.com/adafruit/Adafruit_CircuitPython_IRRemote/actions/
1515
:alt: Build Status
1616

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

2121
CircuitPython driver for use with IR Receivers.
2222

‎adafruit_irremote.py

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5-
# pylint: disable=missing-module-docstring
65
from __future__ import annotations
76

87
import array
9-
from collections import namedtuple
108
import time
9+
from collections import namedtuple
1110

1211
try:
13-
from typing import List, NamedTuple, Optional, Tuple
12+
from typing import NamedTuple, Optional
13+
1414
from pulseio import PulseOut
1515
except ImportError:
1616
pass
@@ -76,7 +76,7 @@ class IRNECRepeatException(Exception):
7676
"""Exception when a NEC repeat is decoded"""
7777

7878

79-
def bin_data(pulses: List) -> List[List]:
79+
def bin_data(pulses: list) -> list[list]:
8080
"""Compute bins of pulse lengths where pulses are +-25% of the average.
8181
8282
:param list pulses: Input pulse lengths
@@ -99,9 +99,8 @@ def bin_data(pulses: List) -> List[List]:
9999
return bins
100100

101101

102-
def decode_bits(pulses: List) -> NamedTuple:
102+
def decode_bits(pulses: list) -> NamedTuple:
103103
"""Decode the pulses into bits."""
104-
# pylint: disable=too-many-branches,too-many-statements
105104

106105
# TODO The name pulses is redefined several times below, so we'll stash the
107106
# original in a separate variable for now. It might be worth refactoring to
@@ -165,9 +164,7 @@ def decode_bits(pulses: List) -> NamedTuple:
165164

166165
if outliers:
167166
# skip outliers
168-
pulses = [
169-
p for p in pulses if not (outliers[0] * 0.75) <= p <= (outliers[0] * 1.25)
170-
]
167+
pulses = [p for p in pulses if not (outliers[0] * 0.75) <= p <= (outliers[0] * 1.25)]
171168
# convert marks/spaces to 0 and 1
172169
for i, pulse_length in enumerate(pulses):
173170
if (space * 0.75) <= pulse_length <= (space * 1.25):
@@ -221,7 +218,7 @@ class NonblockingGenericDecode:
221218
... ...
222219
"""
223220

224-
def __init__(self, pulses: List, max_pulse: int = 10_000) -> None:
221+
def __init__(self, pulses: list, max_pulse: int = 10_000) -> None:
225222
self.pulses = pulses # PulseIn
226223
self.max_pulse = max_pulse
227224
self._unparsed_pulses = [] # internal buffer of partial messages
@@ -261,11 +258,11 @@ class GenericDecode:
261258
# this here for back-compat, hence we disable pylint for that specific
262259
# complaint.
263260

264-
def bin_data(self, pulses: List) -> List[List]: # pylint: disable=no-self-use
261+
def bin_data(self, pulses: list) -> list[list]: # noqa: PLR6301
265262
"Wraps the top-level function bin_data for backward-compatibility."
266263
return bin_data(pulses)
267264

268-
def decode_bits(self, pulses: List) -> Tuple: # pylint: disable=no-self-use
265+
def decode_bits(self, pulses: list) -> tuple: # noqa: PLR6301
269266
"Wraps the top-level function decode_bits for backward-compatibility."
270267
try:
271268
result = decode_bits(pulses)
@@ -275,9 +272,9 @@ def decode_bits(self, pulses: List) -> Tuple: # pylint: disable=no-self-use
275272
raise IRNECRepeatException()
276273
return result.code
277274

278-
def _read_pulses_non_blocking( # pylint: disable=no-self-use
279-
self, input_pulses: List, max_pulse: int = 10000, pulse_window: float = 0.10
280-
) -> Optional[List]:
275+
def _read_pulses_non_blocking( # noqa: PLR6301
276+
self, input_pulses: list, max_pulse: int = 10000, pulse_window: float = 0.10
277+
) -> Optional[list]:
281278
"""Read out a burst of pulses without blocking until pulses stop for a specified
282279
period (pulse_window), pruning pulses after a pulse longer than ``max_pulse``.
283280
@@ -317,7 +314,7 @@ def read_pulses(
317314
blocking: bool = True,
318315
pulse_window: float = 0.10,
319316
blocking_delay: float = 0.10,
320-
) -> Optional[List]:
317+
) -> Optional[list]:
321318
"""Read out a burst of pulses until pulses stop for a specified
322319
period (pulse_window), pruning pulses after a pulse longer than ``max_pulse``.
323320
@@ -330,9 +327,7 @@ def read_pulses(
330327
:param float blocking_delay: delay between pulse checks when blocking
331328
"""
332329
while True:
333-
pulses = self._read_pulses_non_blocking(
334-
input_pulses, max_pulse, pulse_window
335-
)
330+
pulses = self._read_pulses_non_blocking(input_pulses, max_pulse, pulse_window)
336331
if blocking and pulses is None:
337332
time.sleep(blocking_delay)
338333
continue
@@ -351,9 +346,9 @@ class GenericTransmit:
351346

352347
def __init__(
353348
self,
354-
header: List[int],
355-
one: List[int],
356-
zero: List[int],
349+
header: list[int],
350+
one: list[int],
351+
zero: list[int],
357352
trail: int,
358353
*,
359354
debug: bool = False,
@@ -388,8 +383,7 @@ def transmit(
388383

389384
durations = array.array(
390385
"H",
391-
[0]
392-
* (len(self.header) + bits_to_send * 2 + (0 if self.trail is None else 1)),
386+
[0] * (len(self.header) + bits_to_send * 2 + (0 if self.trail is None else 1)),
393387
)
394388

395389
for i, _ in enumerate(self.header):

‎docs/api.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11

22
.. If you created a package, create one automodule per module in the package.
33
4+
API Reference
5+
#############
6+
47
.. automodule:: adafruit_irremote
58
:members:

‎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

@@ -40,9 +38,7 @@
4038
creation_year = "2017"
4139
current_year = str(datetime.datetime.now().year)
4240
year_duration = (
43-
current_year
44-
if current_year == creation_year
45-
else creation_year + " - " + current_year
41+
current_year if current_year == creation_year else creation_year + " - " + current_year
4642
)
4743
copyright = year_duration + " Scott Shawcroft"
4844
author = "Scott Shawcroft"

‎examples/irremote_simpletest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
# Circuit Playground Express Demo Code
55
# Adjust the pulseio 'board.PIN' if using something else
6-
import pulseio
76
import board
7+
import pulseio
8+
89
import adafruit_irremote
910

1011
pulsein = pulseio.PulseIn(board.REMOTEIN, maxlen=120, idle_state=True)

‎examples/irremote_transmit.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
# SPDX-License-Identifier: MIT
33

44
"""IR transmit example using Circuit Playground Express"""
5-
# pylint: disable-msg=no-member
5+
66
import time
7-
import pulseio
7+
88
import board
99
import digitalio
10+
import pulseio
11+
1012
import adafruit_irremote
1113

1214
# Create a button object to trigger IR transmit

‎ruff.toml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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+
"UP007", # use-union-operator
103+
]
104+
105+
[format]
106+
line-ending = "lf"

0 commit comments

Comments
 (0)
Please sign in to comment.