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 d41fbeb

Browse files
authoredFeb 24, 2025··
Merge pull request #50 from FoamyGuy/use_ruff_and_remove_8x_compat
use ruff and remove 8x displayio compatibility
2 parents dc40a00 + 1e39bd7 commit d41fbeb

11 files changed

+141
-469
lines changed
 

‎.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
@@ -13,9 +13,9 @@ Introduction
1313
:target: https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SSD1306/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
DisplayIO driver for SSD1306 monochrome displays. DisplayIO drivers enable terminal output
2121

‎adafruit_displayio_ssd1306.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,34 +33,35 @@
3333
https://github.com/adafruit/circuitpython/releases
3434
3535
"""
36+
37+
from busdisplay import BusDisplay
38+
3639
try:
3740
from typing import Union
38-
from busdisplay import BusDisplay
41+
3942
from fourwire import FourWire
4043
from i2cdisplaybus import I2CDisplayBus
4144
except ImportError:
42-
from displayio import FourWire
43-
from displayio import I2CDisplay as I2CDisplayBus
44-
from displayio import Display as BusDisplay
45+
pass
4546

4647
__version__ = "0.0.0+auto.0"
4748
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SSD1306.git"
4849

4950
# Sequence from page 19 here: https://cdn-shop.adafruit.com/datasheets/UG-2864HSWEG01+user+guide.pdf
5051
_INIT_SEQUENCE = (
51-
b"\xAE\x00" # DISPLAY_OFF
52+
b"\xae\x00" # DISPLAY_OFF
5253
b"\x20\x01\x00" # Set memory addressing to horizontal mode.
5354
b"\x81\x01\xcf" # set contrast control
54-
b"\xA1\x00" # Column 127 is segment 0
55-
b"\xA6\x00" # Normal display
55+
b"\xa1\x00" # Column 127 is segment 0
56+
b"\xa6\x00" # Normal display
5657
b"\xc8\x00" # Normal display
57-
b"\xA8\x01\x3f" # Mux ratio is 1/64
58+
b"\xa8\x01\x3f" # Mux ratio is 1/64
5859
b"\xd5\x01\x80" # Set divide ratio
5960
b"\xd9\x01\xf1" # Set pre-charge period
6061
b"\xda\x01\x12" # Set com configuration
6162
b"\xdb\x01\x40" # Set vcom configuration
6263
b"\x8d\x01\x14" # Enable charge pump
63-
b"\xAF\x00" # DISPLAY_ON
64+
b"\xaf\x00" # DISPLAY_ON
6465
)
6566

6667

@@ -85,7 +86,7 @@ def __init__(self, bus: Union[FourWire, I2CDisplayBus], **kwargs) -> None:
8586
init_sequence[16] = height - 1 # patch mux ratio
8687
if height == 32 and width == 64: # Make sure this only apply to that resolution
8788
init_sequence[16] = 64 - 1 # FORCED for 64x32 because it fail with formula
88-
if height in (32, 16) and width != 64:
89+
if height in {32, 16} and width != 64:
8990
init_sequence[25] = 0x02 # patch com configuration
9091
col_offset = (
9192
0 if width == 128 else (128 - width) // 2

‎docs/api.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@
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_displayio_ssd1306
811
:members:

‎docs/conf.py

Lines changed: 3 additions & 7 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

@@ -27,7 +25,7 @@
2725
# Uncomment the below if you use native CircuitPython modules such as
2826
# digitalio, micropython and busio. List the modules you use. Without it, the
2927
# autodoc module docs will fail to generate with a warning.
30-
autodoc_mock_imports = ["displayio"]
28+
autodoc_mock_imports = ["busdisplay", "fourwire", "i2cdisplaybus"]
3129

3230

3331
intersphinx_mapping = {
@@ -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 + " Scott Shawcroft"
5652
author = "Scott Shawcroft"

‎examples/displayio_ssd1306_64x32_simpletest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import terminalio
2121
from adafruit_display_text import label
22+
2223
import adafruit_displayio_ssd1306
2324

2425
displayio.release_displays()

‎examples/displayio_ssd1306_featherwing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import terminalio
2020
from adafruit_display_text import label
21+
2122
import adafruit_displayio_ssd1306
2223

2324
displayio.release_displays()

‎examples/displayio_ssd1306_picowbell_tempsensor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Coded for Circuit Python 8.1
55

66
import time
7+
78
import board
89
import displayio
910

@@ -16,8 +17,9 @@
1617

1718
import busio
1819
import terminalio
19-
from adafruit_display_text import label
2020
from adafruit_bme280 import basic as adafruit_bme280
21+
from adafruit_display_text import label
22+
2123
import adafruit_displayio_ssd1306 as ssd1306
2224

2325
# Reinitalizes display upon any soft reboot or hard reset

‎examples/displayio_ssd1306_simpletest.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,11 @@
99
import board
1010
import displayio
1111

12-
# Compatibility with both CircuitPython 8.x.x and 9.x.x.
13-
# Remove after 8.x.x is no longer a supported release.
14-
try:
15-
from i2cdisplaybus import I2CDisplayBus
16-
17-
# from fourwire import FourWire
18-
except ImportError:
19-
from displayio import I2CDisplay as I2CDisplayBus
20-
21-
# from displayio import FourWire
22-
12+
# from fourwire import FourWire
2313
import terminalio
2414
from adafruit_display_text import label
15+
from i2cdisplaybus import I2CDisplayBus
16+
2517
import adafruit_displayio_ssd1306
2618

2719
displayio.release_displays()
@@ -61,16 +53,12 @@
6153
inner_bitmap = displayio.Bitmap(WIDTH - BORDER * 2, HEIGHT - BORDER * 2, 1)
6254
inner_palette = displayio.Palette(1)
6355
inner_palette[0] = 0x000000 # Black
64-
inner_sprite = displayio.TileGrid(
65-
inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER
66-
)
56+
inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER)
6757
splash.append(inner_sprite)
6858

6959
# Draw a label
7060
text = "Hello World!"
71-
text_area = label.Label(
72-
terminalio.FONT, text=text, color=0xFFFFFF, x=28, y=HEIGHT // 2 - 1
73-
)
61+
text_area = label.Label(terminalio.FONT, text=text, color=0xFFFFFF, x=28, y=HEIGHT // 2 - 1)
7462
splash.append(text_area)
7563

7664
while True:

‎ruff.toml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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+
97+
]
98+
99+
[format]
100+
line-ending = "lf"

0 commit comments

Comments
 (0)
Please sign in to comment.