Skip to content

Commit 22d9ebe

Browse files
authored
Merge pull request #21 from FoamyGuy/use_ruff
use ruff
2 parents 74e8b6b + a368ef7 commit 22d9ebe

8 files changed

+137
-57
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: v2.17.4
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_VS1053/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
Driver for interacting and playing media files with the VS1053 audio codec over
2121
a SPI connection.

adafruit_vs1053.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,17 @@
4141
"""
4242

4343
import time
44+
4445
import digitalio
45-
from micropython import const
4646
from adafruit_bus_device.spi_device import SPIDevice
47+
from micropython import const
4748

4849
try:
4950
from typing import Optional
51+
52+
from busio import SPI
5053
from circuitpython_typing import ReadableBuffer
5154
from microcontroller import Pin
52-
from busio import SPI
5355
except ImportError:
5456
pass
5557

@@ -104,9 +106,7 @@ def __init__( # pylint: disable=invalid-name
104106
) -> None:
105107
# Create SPI device for VS1053
106108
self._cs = digitalio.DigitalInOut(cs)
107-
self._vs1053_spi = SPIDevice(
108-
spi, self._cs, baudrate=_COMMAND_BAUDRATE, polarity=0, phase=0
109-
)
109+
self._vs1053_spi = SPIDevice(spi, self._cs, baudrate=_COMMAND_BAUDRATE, polarity=0, phase=0)
110110
# Setup control lines.
111111
self._xdcs = digitalio.DigitalInOut(xdcs)
112112
self._xdcs.switch_to_output(value=True)
@@ -147,9 +147,7 @@ def _sci_read(self, address: int) -> int:
147147

148148
def soft_reset(self) -> None:
149149
"""Perform a quick soft reset of the VS1053."""
150-
self._sci_write(
151-
_VS1053_REG_MODE, _VS1053_MODE_SM_SDINEW | _VS1053_MODE_SM_RESET
152-
)
150+
self._sci_write(_VS1053_REG_MODE, _VS1053_MODE_SM_SDINEW | _VS1053_MODE_SM_RESET)
153151
time.sleep(0.1)
154152

155153
def reset(self) -> None:
@@ -203,9 +201,7 @@ def start_playback(self) -> None:
203201
buffers of music data to the play_data function.
204202
"""
205203
# Reset playback.
206-
self._sci_write(
207-
_VS1053_REG_MODE, _VS1053_MODE_SM_LINE1 | _VS1053_MODE_SM_SDINEW
208-
)
204+
self._sci_write(_VS1053_REG_MODE, _VS1053_MODE_SM_LINE1 | _VS1053_MODE_SM_SDINEW)
209205
# Resync.
210206
self._sci_write(_VS1053_REG_WRAMADDR, 0x1E29)
211207
self._sci_write(_VS1053_REG_WRAM, 0)
@@ -219,9 +215,7 @@ def stop_playback(self) -> None:
219215
_VS1053_MODE_SM_LINE1 | _VS1053_MODE_SM_SDINEW | _VS1053_MODE_SM_CANCEL,
220216
)
221217

222-
def play_data(
223-
self, data_buffer: ReadableBuffer, start: int = 0, end: Optional[int] = None
224-
):
218+
def play_data(self, data_buffer: ReadableBuffer, start: int = 0, end: Optional[int] = None):
225219
"""Send a buffer of file data to the VS1053 for playback. Make sure
226220
the ready_for_data property is True before calling!
227221
"""

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

@@ -56,9 +54,7 @@
5654
creation_year = "2018"
5755
current_year = str(datetime.datetime.now().year)
5856
year_duration = (
59-
current_year
60-
if current_year == creation_year
61-
else creation_year + " - " + current_year
57+
current_year if current_year == creation_year else creation_year + " - " + current_year
6258
)
6359
copyright = year_duration + " Tony DiCola"
6460
author = "Tony DiCola"

examples/vs1053_MIDI.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: MIT
33

44
import time
5+
56
import board
67
import busio
78

examples/vs1053_simpletest.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010
# We'll need to look into interrupt support perhaps to monitor DREQ like in the
1111
# arduino library. Basic sine wave playback does however work and monitoring
1212
# of attributes like status register and other VS1053 state is accessible.
13+
import adafruit_sdcard
1314
import board
1415
import busio
1516
import digitalio
1617
import storage
1718

18-
import adafruit_sdcard
1919
import adafruit_vs1053
2020

21-
2221
# Define pins connected to VS1053:
2322

2423
# For FeatherWing with Feather M0:
@@ -71,7 +70,7 @@
7170
# the VS1053 making static, stopping, and eventually requiring a hard reset.
7271
# We'll need to look into interrupt support perhaps to monitor DREQ like in the
7372
# arduino library.
74-
print("Playing {}...".format(PLAYBACK_FILE))
73+
print(f"Playing {PLAYBACK_FILE}...")
7574
vs1053.start_playback()
7675
with open(PLAYBACK_FILE, "rb") as infile:
7776
music_data = infile.read(BUFFER_SIZE)

ruff.toml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
select = ["I", "PL", "UP"]
10+
11+
extend-select = [
12+
"D419", # empty-docstring
13+
"E501", # line-too-long
14+
"W291", # trailing-whitespace
15+
"PLC0414", # useless-import-alias
16+
"PLC2401", # non-ascii-name
17+
"PLC2801", # unnecessary-dunder-call
18+
"PLC3002", # unnecessary-direct-lambda-call
19+
"E999", # syntax-error
20+
"PLE0101", # return-in-init
21+
"F706", # return-outside-function
22+
"F704", # yield-outside-function
23+
"PLE0116", # continue-in-finally
24+
"PLE0117", # nonlocal-without-binding
25+
"PLE0241", # duplicate-bases
26+
"PLE0302", # unexpected-special-method-signature
27+
"PLE0604", # invalid-all-object
28+
"PLE0605", # invalid-all-format
29+
"PLE0643", # potential-index-error
30+
"PLE0704", # misplaced-bare-raise
31+
"PLE1141", # dict-iter-missing-items
32+
"PLE1142", # await-outside-async
33+
"PLE1205", # logging-too-many-args
34+
"PLE1206", # logging-too-few-args
35+
"PLE1307", # bad-string-format-type
36+
"PLE1310", # bad-str-strip-call
37+
"PLE1507", # invalid-envvar-value
38+
"PLE2502", # bidirectional-unicode
39+
"PLE2510", # invalid-character-backspace
40+
"PLE2512", # invalid-character-sub
41+
"PLE2513", # invalid-character-esc
42+
"PLE2514", # invalid-character-nul
43+
"PLE2515", # invalid-character-zero-width-space
44+
"PLR0124", # comparison-with-itself
45+
"PLR0202", # no-classmethod-decorator
46+
"PLR0203", # no-staticmethod-decorator
47+
"UP004", # useless-object-inheritance
48+
"PLR0206", # property-with-parameters
49+
"PLR0904", # too-many-public-methods
50+
"PLR0911", # too-many-return-statements
51+
"PLR0912", # too-many-branches
52+
"PLR0913", # too-many-arguments
53+
"PLR0914", # too-many-locals
54+
"PLR0915", # too-many-statements
55+
"PLR0916", # too-many-boolean-expressions
56+
"PLR1702", # too-many-nested-blocks
57+
"PLR1704", # redefined-argument-from-local
58+
"PLR1711", # useless-return
59+
"C416", # unnecessary-comprehension
60+
"PLR1733", # unnecessary-dict-index-lookup
61+
"PLR1736", # unnecessary-list-index-lookup
62+
63+
# ruff reports this rule is unstable
64+
#"PLR6301", # no-self-use
65+
66+
"PLW0108", # unnecessary-lambda
67+
"PLW0120", # useless-else-on-loop
68+
"PLW0127", # self-assigning-variable
69+
"PLW0129", # assert-on-string-literal
70+
"B033", # duplicate-value
71+
"PLW0131", # named-expr-without-context
72+
"PLW0245", # super-without-brackets
73+
"PLW0406", # import-self
74+
"PLW0602", # global-variable-not-assigned
75+
"PLW0603", # global-statement
76+
"PLW0604", # global-at-module-level
77+
78+
# fails on the try: import typing used by libraries
79+
#"F401", # unused-import
80+
81+
"F841", # unused-variable
82+
"E722", # bare-except
83+
"PLW0711", # binary-op-exception
84+
"PLW1501", # bad-open-mode
85+
"PLW1508", # invalid-envvar-default
86+
"PLW1509", # subprocess-popen-preexec-fn
87+
"PLW2101", # useless-with-lock
88+
"PLW3301", # nested-min-max
89+
]
90+
91+
ignore = [
92+
"PLR2004", # magic-value-comparison
93+
"UP030", # format literals
94+
"PLW1514", # unspecified-encoding
95+
96+
]
97+
98+
[format]
99+
line-ending = "lf"

0 commit comments

Comments
 (0)