Skip to content

Commit 8d766b5

Browse files
committed
new infrastructure files, use ruff, update for new displayio API
1 parent c8b9d22 commit 8d766b5

15 files changed

+208
-142
lines changed

.pre-commit-config.yaml

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +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: 20.8b1
6+
- repo: https://github.com/pre-commit/pre-commit-hooks
7+
rev: v4.5.0
88
hooks:
9-
- id: black
10-
- repo: https://github.com/fsfe/reuse-tool
11-
rev: v0.12.1
9+
- id: check-yaml
10+
- id: end-of-file-fixer
11+
- id: trailing-whitespace
12+
- repo: https://github.com/astral-sh/ruff-pre-commit
13+
rev: v0.3.4
1214
hooks:
13-
- id: reuse
14-
- repo: https://github.com/pre-commit/pre-commit-hooks
15-
rev: v2.3.0
15+
- id: ruff-format
16+
- id: ruff
17+
args: ["--fix"]
18+
- repo: https://github.com/fsfe/reuse-tool
19+
rev: v3.0.1
1620
hooks:
17-
- id: check-yaml
18-
- id: end-of-file-fixer
19-
- id: trailing-whitespace
20-
- repo: https://github.com/pycqa/pylint
21-
rev: pylint-2.7.1
22-
hooks:
23-
- id: pylint
24-
name: pylint (library code)
25-
types: [python]
26-
exclude: "^(docs/|examples/|tests/|setup.py$)"
27-
- repo: local
28-
hooks:
29-
- id: pylint_examples
30-
name: pylint (examples code)
31-
description: Run pylint rules on "examples/*.py" files
32-
entry: /usr/bin/env bash -c
33-
args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name,consider-using-f-string $example; done)']
34-
language: system
35-
- id: pylint_tests
36-
name: pylint (tests code)
37-
description: Run pylint rules on "tests/*.py" files
38-
entry: /usr/bin/env bash -c
39-
args: ['([[ ! -d "tests" ]] || for test in $(find . -path "./tests/*.py"); do pylint --disable=missing-docstring $test; done)']
40-
language: system
21+
- id: reuse

.readthedocs.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
# Required
99
version: 2
1010

11+
sphinx:
12+
configuration: docs/conf.py
13+
1114
build:
12-
os: ubuntu-20.04
15+
os: ubuntu-lts-latest
1316
tools:
1417
python: "3"
1518

README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ Introduction
1717
:alt: Build Status
1818

1919

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

2424
Add some flair to your widgets with effects!
2525

displayio_effects/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
https://circuitpython.org/downloads
2222
"""
2323

24-
2524
WIDGET_TYPE_ATTR = "_widget_type"
2625

26+
2727
# pylint: disable=too-few-public-methods
2828
class WidgetType:
2929
"""Enum values for customizable widget types. Valid options are:

displayio_effects/colorwheel_effect.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# SPDX-License-Identifier: MIT
55
# pylint: disable=protected-access
66
"""
7-
`displayio_effects.fluctuation_effect`
7+
`displayio_effects.colorwheel_effect`
88
================================================================================
99
1010
Add the colorwheel effect to your widgets
@@ -21,9 +21,10 @@
2121
https://circuitpython.org/downloads
2222
"""
2323

24+
from adafruit_itertools import cycle
2425
from rainbowio import colorwheel
25-
from adafruit_itertools.adafruit_itertools import cycle
26-
from displayio_effects import WidgetType, WIDGET_TYPE_ATTR
26+
27+
from displayio_effects import WIDGET_TYPE_ATTR, WidgetType
2728

2829
__version__ = "0.0.0-auto.0"
2930
__repo__ = "https://github.com/tekktrik/CircuitPython_Org_DisplayIO_Effects.git"
@@ -69,9 +70,7 @@ def hook_colorwheel_effect(widget_class, widget_type):
6970
"""
7071

7172
if not COLORWHEEL_WIDGET_VALUES.get(widget_type):
72-
raise ValueError(
73-
"The given widget does not have the ability to use this effect"
74-
)
73+
raise ValueError("The given widget does not have the ability to use this effect")
7574

7675
setattr(widget_class, WIDGET_TYPE_ATTR, widget_type)
7776

displayio_effects/fluctuation_effect.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"""
2323

2424
import random
25-
from displayio_effects import WidgetType, WIDGET_TYPE_ATTR
25+
26+
from displayio_effects import WIDGET_TYPE_ATTR, WidgetType
2627

2728
__version__ = "0.0.0-auto.0"
2829
__repo__ = "https://github.com/tekktrik/CircuitPython_Org_DisplayIO_Effects.git"
@@ -79,11 +80,10 @@ def update_fluctuation(self):
7980
self._fluctuation_destination = None
8081
return
8182

82-
if self._fluctuation_destination in (None, self._fluctuation_hold_value):
83+
if self._fluctuation_destination in {None, self._fluctuation_hold_value}:
8384
limit_bound = self._fluctuation_amplitude * 10
8485
self._fluctuation_destination = (
85-
random.uniform(-limit_bound, limit_bound) / 10
86-
+ self._fluctuation_hold_value
86+
random.uniform(-limit_bound, limit_bound) / 10 + self._fluctuation_hold_value
8787
)
8888

8989
value = getattr(self, value_name)
@@ -124,9 +124,7 @@ def hook_fluctuation_effect(widget_class, widget_type):
124124
"""
125125

126126
if not FLUCTUATION_WIDGET_VALUES.get(widget_type):
127-
raise ValueError(
128-
"The given widget does not have the ability to use this effect"
129-
)
127+
raise ValueError("The given widget does not have the ability to use this effect")
130128

131129
setattr(widget_class, WIDGET_TYPE_ATTR, widget_type)
132130

docs/api.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,11 @@
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:: displayio_effects.fluctuation_effect
811
:members:
12+
13+
.. automodule:: displayio_effects.colorwheel_effect
14+
:members:

docs/conf.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
# -*- coding: utf-8 -*-
2-
31
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
42
#
53
# SPDX-License-Identifier: MIT
64

5+
import datetime
76
import os
87
import sys
98

@@ -16,6 +15,7 @@
1615
# ones.
1716
extensions = [
1817
"sphinx.ext.autodoc",
18+
"sphinxcontrib.jquery",
1919
"sphinx.ext.intersphinx",
2020
"sphinx.ext.napoleon",
2121
"sphinx.ext.todo",
@@ -27,6 +27,7 @@
2727
# autodoc module docs will fail to generate with a warning.
2828
# autodoc_mock_imports = ["digitalio", "busio"]
2929

30+
autodoc_preserve_defaults = True
3031

3132
intersphinx_mapping = {
3233
"python": ("https://docs.python.org/3", None),
@@ -46,7 +47,12 @@
4647

4748
# General information about the project.
4849
project = "CircuitPython DisplayIO_Effects Library"
49-
copyright = "2022 Alec Delaney"
50+
creation_year = "2022"
51+
current_year = str(datetime.datetime.now().year)
52+
year_duration = (
53+
current_year if current_year == creation_year else creation_year + " - " + current_year
54+
)
55+
copyright = year_duration + " Alec Delaney"
5056
author = "Alec Delaney"
5157

5258
# The version info for the project you're documenting, acts as replacement for
@@ -63,7 +69,7 @@
6369
#
6470
# This is also used if you do content translation via gettext catalogs.
6571
# Usually you set "language" from the command line for these cases.
66-
language = None
72+
language = "en"
6773

6874
# List of patterns, relative to source directory, that match files and
6975
# directories to ignore when looking for source files.
@@ -101,19 +107,9 @@
101107
# The theme to use for HTML and HTML Help pages. See the documentation for
102108
# a list of builtin themes.
103109
#
104-
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
105-
106-
if not on_rtd: # only import and set the theme if we're building docs locally
107-
try:
108-
import sphinx_rtd_theme
109-
110-
html_theme = "sphinx_rtd_theme"
111-
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
112-
except:
113-
html_theme = "default"
114-
html_theme_path = ["."]
115-
else:
116-
html_theme_path = ["."]
110+
import sphinx_rtd_theme
111+
112+
html_theme = "sphinx_rtd_theme"
117113

118114
# Add any paths that contain custom static files (such as style sheets) here,
119115
# relative to this directory. They are copied after the builtin static files,

examples/displayio_effects_colorwheel.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
"""
99

1010
import time
11+
1112
import board
1213
import displayio
1314
import terminalio
1415
from displayio_dial import Dial
16+
1517
from displayio_effects import WidgetType, colorwheel_effect
1618

1719
# Fonts used for the Dial tick labels
@@ -47,12 +49,11 @@
4749
my_group = displayio.Group()
4850
my_group.append(my_dial)
4951

50-
display.show(my_group) # add high level Group to the display
52+
display.root_group = my_group # add high level Group to the display
5153

5254
# Set the dial to the value before turning on the fluctuation effect
5355
my_dial.value = 50
5456

5557
while True:
56-
5758
my_dial.update_colorwheel()
5859
time.sleep(0.01)

examples/displayio_effects_gauge.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
Use the random fluctuation effect for the Gauge.
77
"""
88

9-
109
import time
10+
1111
import board
1212
import displayio
1313
from displayio_gauge import Gauge
14+
1415
from displayio_effects import WidgetType, fluctuation_effect
1516

1617
display = board.DISPLAY
@@ -24,7 +25,7 @@
2425
color_palette[0] = 0x000000
2526
bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
2627
main_group.append(bg_sprite)
27-
display.show(main_group)
28+
display.root_group = main_group
2829

2930
fluctuation_effect.hook_fluctuation_effect(Gauge, WidgetType.GAUGE)
3031

@@ -45,5 +46,4 @@
4546

4647

4748
while True:
48-
4949
my_gauge.update_fluctuation()

examples/displayio_effects_simpletest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import displayio
1212
import terminalio
1313
from displayio_dial import Dial
14+
1415
from displayio_effects import WidgetType, fluctuation_effect
1516

1617
# Fonts used for the Dial tick labels
@@ -47,7 +48,7 @@
4748
my_group = displayio.Group()
4849
my_group.append(my_dial)
4950

50-
display.show(my_group) # add high level Group to the display
51+
display.root_group = my_group # add high level Group to the display
5152

5253
# Set the dial to the value before turning on the fluctuation effect
5354
my_dial.value = 50
@@ -56,5 +57,4 @@
5657
my_dial.fluctuation_move_rate = 0.01 # Fluctuate at "0.01" per throttle_update()
5758

5859
while True:
59-
6060
my_dial.update_fluctuation()

pyproject.toml

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,50 @@
1-
# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò
1+
# SPDX-FileCopyrightText: 2022 Alec Delaney, written for Adafruit Industries
2+
# SPDX-FileCopyrightText: Copyright (c) 2025 Alec Delaney for circuitpython
23
#
3-
# SPDX-License-Identifier: Unlicense
4+
# SPDX-License-Identifier: MIT
45

5-
[tool.black]
6-
target-version = ['py35']
6+
[build-system]
7+
requires = [
8+
"setuptools",
9+
"wheel",
10+
"setuptools-scm",
11+
]
12+
13+
[project]
14+
name = "circuitpython-displayio-effects"
15+
description = "Add some flair to your displayio widgets with effects!"
16+
version = "0.0.0+auto.0"
17+
readme = "README.rst"
18+
authors = [
19+
{name = "circuitpython"}
20+
]
21+
urls = {Homepage = "https://github.com/circuitpython/CircuitPython_Org_DisplayIO_Effects"}
22+
keywords = [
23+
"adafruit",
24+
"blinka",
25+
"circuitpython",
26+
"micropython",
27+
"displayio_effects",
28+
"effects,",
29+
"displayio,",
30+
"widget",
31+
]
32+
license = {text = "MIT"}
33+
classifiers = [
34+
"Intended Audience :: Developers",
35+
"Topic :: Software Development :: Libraries",
36+
"Topic :: Software Development :: Embedded Systems",
37+
"Topic :: System :: Hardware",
38+
"License :: OSI Approved :: MIT License",
39+
"Programming Language :: Python :: 3",
40+
]
41+
dynamic = ["dependencies", "optional-dependencies"]
42+
43+
[tool.setuptools]
44+
# TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER,
45+
# CHANGE `py_modules = ['...']` TO `packages = ['...']`
46+
packages = ["displayio_effects"]
47+
48+
[tool.setuptools.dynamic]
49+
dependencies = {file = ["requirements.txt"]}
50+
optional-dependencies = {optional = {file = ["optional_requirements.txt"]}}

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
# SPDX-License-Identifier: MIT
55

66
Adafruit-Blinka
7+
adafruit-circuitpython-itertools

0 commit comments

Comments
 (0)