From b03f8cbf7f0989d4fa6403f8f478ccb73a287c94 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 22 Feb 2022 10:27:29 -0500 Subject: [PATCH 01/15] Switch to using enumerated widget types --- displayio_effects/__init__.py | 28 +++++++++++++++++++++++++ displayio_effects/fluctuation_effect.py | 24 +++++++++++++++------ 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/displayio_effects/__init__.py b/displayio_effects/__init__.py index e69de29..b9401be 100644 --- a/displayio_effects/__init__.py +++ b/displayio_effects/__init__.py @@ -0,0 +1,28 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# SPDX-FileCopyrightText: Copyright (c) 2022 Alec Delaney for CircuitPython Organization +# +# SPDX-License-Identifier: MIT +# pylint: disable=protected-access +""" +`displayio_effects` +================================================================================ + +Add the some flair to your widgets! + + +* Author(s): Alec Delaney + +Implementation Notes +-------------------- + +**Software and Dependencies:** + +* Adafruit CircuitPython firmware for the supported boards: + https://circuitpython.org/downloads +""" + +class WidgetType: + """Enum values for customizable widget types""" + + DIAL = 0 + GAUGE = 1 diff --git a/displayio_effects/fluctuation_effect.py b/displayio_effects/fluctuation_effect.py index 2312657..48149b5 100644 --- a/displayio_effects/fluctuation_effect.py +++ b/displayio_effects/fluctuation_effect.py @@ -22,11 +22,18 @@ """ import random +from displayio_effects import WidgetType __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/tekktrik/CircuitPython_Org_DisplayIO_Effects.git" +FLUCTUATION_WIDGET_VALUES = { + WidgetType.DIAL: "value", + WidgetType.GAUGE: "level", +} + + @property def fluctuation_amplitude(self): """The furtherest the fluctuation effect can randomly set the widget value relative @@ -88,13 +95,13 @@ def update_fluctuation(self): self._fluctuation_destination = self._fluctuation_hold_value -def hook_fluctuation_effect(widget_class, value_name): +def hook_fluctuation_effect(widget_class, widget_type): """Adds the fluctuation effect for the given class - :param widget_classes: The widgets that should have this effect hooked + :param widget_class: The widget that should have this effect hooked into them. - :param str value_name: The name of the attribute that sets the "value" - for this widget + :param int widget_type: The enum value of this widget type, must be a + valid ~WidgetType For example, to hook this into the ``Dial`` widget, you would use the following code: @@ -102,12 +109,17 @@ def hook_fluctuation_effect(widget_class, value_name): .. code-block:: python from displayio_dial import Dial - from displayio_effects import fluctuation_effect + from + from displayio_effects import WidgetType, fluctuation_effect - fluctuation_effect.hook_fluctuation_effect(Dial, "value") + fluctuation_effect.hook_fluctuation_effect(Dial, WidgetType.DIAL) """ + value_name = FLUCTUATION_WIDGET_VALUES.get(widget_type) + if not value_name: + raise ValueError("The given widget does not have the ability to use this effect") + setattr(widget_class, "_value_name", value_name) setattr(widget_class, "_fluctuation_destination", None) From 5ab897124e1af213237acbefa0bebdc1fb8684ac Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 22 Feb 2022 11:55:51 -0500 Subject: [PATCH 02/15] Update example files --- examples/displayio_effects_gauge.py | 4 ++-- examples/displayio_effects_simpletest.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/displayio_effects_gauge.py b/examples/displayio_effects_gauge.py index 976ce43..a03d62b 100644 --- a/examples/displayio_effects_gauge.py +++ b/examples/displayio_effects_gauge.py @@ -12,7 +12,7 @@ import board import displayio from displayio_gauge import Gauge -from displayio_effects import fluctuation_effect +from displayio_effects import WidgetType, fluctuation_effect display = board.DISPLAY @@ -27,7 +27,7 @@ main_group.append(bg_sprite) display.show(main_group) -fluctuation_effect.hook_fluctuation_effect(Gauge, "level") +fluctuation_effect.hook_fluctuation_effect(Gauge, WidgetType.GAUGE) my_gauge = Gauge( x=90, diff --git a/examples/displayio_effects_simpletest.py b/examples/displayio_effects_simpletest.py index f597a1e..ea7dfda 100644 --- a/examples/displayio_effects_simpletest.py +++ b/examples/displayio_effects_simpletest.py @@ -11,7 +11,7 @@ import displayio import terminalio from displayio_dial import Dial -from displayio_effects import fluctuation_effect +from displayio_effects import WidgetType, fluctuation_effect # Fonts used for the Dial tick labels tick_font = terminalio.FONT @@ -26,7 +26,7 @@ maximum_value = 100 # Hook in the throttle effect for the Dial widget -fluctuation_effect.hook_fluctuation_effect(Dial, "value") +fluctuation_effect.hook_fluctuation_effect(Dial, WidgetType.DIAL) # Create a Dial widget my_dial = Dial( From 9d20149820e90f66c0b62e5f82f5158120e3c4d5 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 22 Feb 2022 11:57:43 -0500 Subject: [PATCH 03/15] Reformatted and linted --- displayio_effects/__init__.py | 1 + displayio_effects/fluctuation_effect.py | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/displayio_effects/__init__.py b/displayio_effects/__init__.py index b9401be..8699e7c 100644 --- a/displayio_effects/__init__.py +++ b/displayio_effects/__init__.py @@ -21,6 +21,7 @@ https://circuitpython.org/downloads """ + class WidgetType: """Enum values for customizable widget types""" diff --git a/displayio_effects/fluctuation_effect.py b/displayio_effects/fluctuation_effect.py index 48149b5..5cb3292 100644 --- a/displayio_effects/fluctuation_effect.py +++ b/displayio_effects/fluctuation_effect.py @@ -98,8 +98,8 @@ def update_fluctuation(self): def hook_fluctuation_effect(widget_class, widget_type): """Adds the fluctuation effect for the given class - :param widget_class: The widget that should have this effect hooked - into them. + :param widget_class: The widget class that should have this effect hooked + into it :param int widget_type: The enum value of this widget type, must be a valid ~WidgetType @@ -109,7 +109,6 @@ def hook_fluctuation_effect(widget_class, widget_type): .. code-block:: python from displayio_dial import Dial - from from displayio_effects import WidgetType, fluctuation_effect fluctuation_effect.hook_fluctuation_effect(Dial, WidgetType.DIAL) @@ -118,7 +117,9 @@ def hook_fluctuation_effect(widget_class, widget_type): value_name = FLUCTUATION_WIDGET_VALUES.get(widget_type) if not value_name: - raise ValueError("The given widget does not have the ability to use this effect") + raise ValueError( + "The given widget does not have the ability to use this effect" + ) setattr(widget_class, "_value_name", value_name) From 85e7cf8bdd4ab4e7194652a53f87dfbb1c4d3e5b Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 22 Feb 2022 12:02:11 -0500 Subject: [PATCH 04/15] Disable pylint warning for too few public methods for enum-like class --- displayio_effects/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/displayio_effects/__init__.py b/displayio_effects/__init__.py index 8699e7c..5bbe060 100644 --- a/displayio_effects/__init__.py +++ b/displayio_effects/__init__.py @@ -22,6 +22,7 @@ """ +# pylint: disable=too-few-public-methods class WidgetType: """Enum values for customizable widget types""" From 4b414d5055351c617c49a8ef4b96a32ab17381f4 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 22 Feb 2022 13:05:42 -0500 Subject: [PATCH 05/15] Store widget type instead of value name --- displayio_effects/__init__.py | 2 ++ displayio_effects/fluctuation_effect.py | 15 ++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/displayio_effects/__init__.py b/displayio_effects/__init__.py index 5bbe060..d7a2679 100644 --- a/displayio_effects/__init__.py +++ b/displayio_effects/__init__.py @@ -22,6 +22,8 @@ """ +WIDGET_TYPE_ATTR = "_widget_type" + # pylint: disable=too-few-public-methods class WidgetType: """Enum values for customizable widget types""" diff --git a/displayio_effects/fluctuation_effect.py b/displayio_effects/fluctuation_effect.py index 5cb3292..c3a1abe 100644 --- a/displayio_effects/fluctuation_effect.py +++ b/displayio_effects/fluctuation_effect.py @@ -22,7 +22,7 @@ """ import random -from displayio_effects import WidgetType +from displayio_effects import WidgetType, WIDGET_TYPE_ATTR __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/tekktrik/CircuitPython_Org_DisplayIO_Effects.git" @@ -44,10 +44,11 @@ def fluctuation_amplitude(self): @fluctuation_amplitude.setter def fluctuation_amplitude(self, amplitude): + value_name = getattr(self, WIDGET_TYPE_ATTR) if amplitude < 0: raise ValueError("Fluctuation effect setting must be larger than 0") if amplitude: - self._fluctuation_hold_value = getattr(self, self._value_name) + self._fluctuation_hold_value = getattr(self, value_name) self._fluctuation_amplitude = amplitude @@ -67,6 +68,7 @@ def fluctuation_move_rate(self, rate): def update_fluctuation(self): """Updates the widget value and propagates the fluctuation effect refresh""" + value_name = getattr(self, WIDGET_TYPE_ATTR) if self._fluctuation_amplitude == 0: self._fluctuation_destination = None return @@ -78,13 +80,13 @@ def update_fluctuation(self): + self._fluctuation_hold_value ) - value = getattr(self, self._value_name) + value = getattr(self, value_name) value = ( value + self._fluctuation_move_rate if self._fluctuation_destination > value else value - self._fluctuation_move_rate ) - setattr(self, self._value_name, value) + setattr(self, value_name, value) threshold_check = ( value >= self._fluctuation_destination @@ -115,13 +117,12 @@ def hook_fluctuation_effect(widget_class, widget_type): """ - value_name = FLUCTUATION_WIDGET_VALUES.get(widget_type) - if not value_name: + if not FLUCTUATION_WIDGET_VALUES.get(widget_type): raise ValueError( "The given widget does not have the ability to use this effect" ) - setattr(widget_class, "_value_name", value_name) + setattr(widget_class, WIDGET_TYPE_ATTR, widget_type) setattr(widget_class, "_fluctuation_destination", None) setattr(widget_class, "_fluctuation_hold_value", 0) From 40a15f7e5a094d70aaa15cdec3bbda865b12cc71 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 22 Feb 2022 13:05:52 -0500 Subject: [PATCH 06/15] Add prototype for colorwheel effect --- displayio_effects/colorwheel_effect.py | 83 ++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 displayio_effects/colorwheel_effect.py diff --git a/displayio_effects/colorwheel_effect.py b/displayio_effects/colorwheel_effect.py new file mode 100644 index 0000000..e83f855 --- /dev/null +++ b/displayio_effects/colorwheel_effect.py @@ -0,0 +1,83 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# SPDX-FileCopyrightText: Copyright (c) 2022 Alec Delaney for CircuitPython Organization +# +# SPDX-License-Identifier: MIT +# pylint: disable=protected-access +""" +`displayio_effects.fluctuation_effect` +================================================================================ + +Add the colorwheel effect to your widgets + + +* Author(s): Alec Delaney + +Implementation Notes +-------------------- + +**Software and Dependencies:** + +* Adafruit CircuitPython firmware for the supported boards: + https://circuitpython.org/downloads +""" + +from rainbowio import colorwheel +from adafruit_itertools.adafruit_itertools import cycle +from displayio_effects import WidgetType, WIDGET_TYPE_ATTR + +__version__ = "0.0.0-auto.0" +__repo__ = "https://github.com/tekktrik/CircuitPython_Org_DisplayIO_Effects.git" + + +COLORWHEEL_WIDGET_VALUES = { + WidgetType.DIAL: { + "path": ("_needle", "_palette"), + "index" : 0, + }, + WidgetType.GAUGE: { + "path": ("_palette"), + "index": 2, + }, +} + +COLORWHEEL_COLORS = cycle([colorwheel(color_value) for color_value in range(256)]) + + +def update_colorwheel(self): + """Updates the widget value and propagates the fluctuation effect refresh""" + + palette_map = getattr(self, WIDGET_TYPE_ATTR) + palette_attr = self + for attr_path in palette_map["path"]: + palette_attr = getattr(palette_attr, attr_path) + palette_attr[palette_map["index"]] = next(COLORWHEEL_COLORS) + + +def hook_colorwheel_effect(widget_class, widget_type): + """Adds the colorwheel effect for the given class + + :param widget_class: The widget class that should have this effect hooked + into it + :param int widget_type: The enum value of this widget type, must be a + valid ~WidgetType + + For example, to hook this into the ``Dial`` widget, you would use the + following code: + + .. code-block:: python + + from displayio_dial import Dial + from displayio_effects import WidgetType, colorwheel_effect + + fluctuation_effect.hook_colorwheel_effect(Dial, WidgetType.DIAL) + + """ + + if not COLORWHEEL_WIDGET_VALUES.get(widget_type): + raise ValueError( + "The given widget does not have the ability to use this effect" + ) + + setattr(widget_class, WIDGET_TYPE_ATTR, widget_type) + + setattr(widget_class, "update_colorwheel", update_colorwheel) From 7e2551d67c889027250557e227c7dafc56f9ba1f Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 22 Feb 2022 13:06:48 -0500 Subject: [PATCH 07/15] Reformatted per pre-commit --- displayio_effects/colorwheel_effect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/displayio_effects/colorwheel_effect.py b/displayio_effects/colorwheel_effect.py index e83f855..66aa165 100644 --- a/displayio_effects/colorwheel_effect.py +++ b/displayio_effects/colorwheel_effect.py @@ -32,7 +32,7 @@ COLORWHEEL_WIDGET_VALUES = { WidgetType.DIAL: { "path": ("_needle", "_palette"), - "index" : 0, + "index": 0, }, WidgetType.GAUGE: { "path": ("_palette"), From 14ef7d4d0980c5b0206eb4a6ec8d23b89c252e4d Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 22 Feb 2022 13:09:08 -0500 Subject: [PATCH 08/15] Add valid options of WidgetType to docstring --- displayio_effects/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/displayio_effects/__init__.py b/displayio_effects/__init__.py index d7a2679..914e678 100644 --- a/displayio_effects/__init__.py +++ b/displayio_effects/__init__.py @@ -26,7 +26,11 @@ # pylint: disable=too-few-public-methods class WidgetType: - """Enum values for customizable widget types""" + """Enum values for customizable widget types. Valid options are: + + - ``WidgetType.DIAL`` - Dial widget + - ``WidgetType.GAUGE`` - Gauge widget + """ DIAL = 0 GAUGE = 1 From b981f121ef73774d50d6224a7b11fe1244b902a3 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 22 Feb 2022 13:12:29 -0500 Subject: [PATCH 09/15] Reformatted per pre-commit --- displayio_effects/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/displayio_effects/__init__.py b/displayio_effects/__init__.py index 914e678..021b2bf 100644 --- a/displayio_effects/__init__.py +++ b/displayio_effects/__init__.py @@ -27,7 +27,7 @@ # pylint: disable=too-few-public-methods class WidgetType: """Enum values for customizable widget types. Valid options are: - + - ``WidgetType.DIAL`` - Dial widget - ``WidgetType.GAUGE`` - Gauge widget """ From e791c0e125dfc7507672157e5fd379b40cd4a8cb Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 22 Feb 2022 16:43:55 -0500 Subject: [PATCH 10/15] Update example file docstring --- examples/displayio_effects_gauge.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/displayio_effects_gauge.py b/examples/displayio_effects_gauge.py index a03d62b..122481c 100644 --- a/examples/displayio_effects_gauge.py +++ b/examples/displayio_effects_gauge.py @@ -3,8 +3,7 @@ # SPDX-License-Identifier: Unlicense """ -Create multiple gauge's and change their level. -This works on any CircuitPython device with a built-in display. +Use the random fluctuation effect for the Gauge. """ From 5f66f81eb847bf8a432966e4870ccd0acab635b9 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 22 Feb 2022 20:53:08 -0500 Subject: [PATCH 11/15] Finalize effects and refactoring --- displayio_effects/colorwheel_effect.py | 25 +++++++++++++++---------- displayio_effects/fluctuation_effect.py | 11 ++++++++--- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/displayio_effects/colorwheel_effect.py b/displayio_effects/colorwheel_effect.py index 66aa165..0325b6f 100644 --- a/displayio_effects/colorwheel_effect.py +++ b/displayio_effects/colorwheel_effect.py @@ -31,11 +31,11 @@ COLORWHEEL_WIDGET_VALUES = { WidgetType.DIAL: { - "path": ("_needle", "_palette"), + "path": ["_needle", "pixel_shader"], "index": 0, }, WidgetType.GAUGE: { - "path": ("_palette"), + "path": ["_palette"], "index": 2, }, } @@ -43,14 +43,9 @@ COLORWHEEL_COLORS = cycle([colorwheel(color_value) for color_value in range(256)]) -def update_colorwheel(self): - """Updates the widget value and propagates the fluctuation effect refresh""" - - palette_map = getattr(self, WIDGET_TYPE_ATTR) - palette_attr = self - for attr_path in palette_map["path"]: - palette_attr = getattr(palette_attr, attr_path) - palette_attr[palette_map["index"]] = next(COLORWHEEL_COLORS) +def get_widget_value(instance): + widget_type = getattr(instance, WIDGET_TYPE_ATTR) + return COLORWHEEL_WIDGET_VALUES[widget_type] def hook_colorwheel_effect(widget_class, widget_type): @@ -81,3 +76,13 @@ def hook_colorwheel_effect(widget_class, widget_type): setattr(widget_class, WIDGET_TYPE_ATTR, widget_type) setattr(widget_class, "update_colorwheel", update_colorwheel) + + +def update_colorwheel(self): + """Updates the widget value and propagates the fluctuation effect refresh""" + + palette_map = get_widget_value(self) + palette_attr = self + for attr_path in palette_map["path"]: + palette_attr = getattr(palette_attr, attr_path) + palette_attr[palette_map["index"]] = next(COLORWHEEL_COLORS) diff --git a/displayio_effects/fluctuation_effect.py b/displayio_effects/fluctuation_effect.py index c3a1abe..079b391 100644 --- a/displayio_effects/fluctuation_effect.py +++ b/displayio_effects/fluctuation_effect.py @@ -33,6 +33,10 @@ WidgetType.GAUGE: "level", } +def get_value_name(instance): + widget_type = getattr(instance, WIDGET_TYPE_ATTR) + return FLUCTUATION_WIDGET_VALUES[widget_type] + @property def fluctuation_amplitude(self): @@ -44,7 +48,7 @@ def fluctuation_amplitude(self): @fluctuation_amplitude.setter def fluctuation_amplitude(self, amplitude): - value_name = getattr(self, WIDGET_TYPE_ATTR) + value_name = get_value_name(self) if amplitude < 0: raise ValueError("Fluctuation effect setting must be larger than 0") if amplitude: @@ -68,7 +72,8 @@ def fluctuation_move_rate(self, rate): def update_fluctuation(self): """Updates the widget value and propagates the fluctuation effect refresh""" - value_name = getattr(self, WIDGET_TYPE_ATTR) + value_name = get_value_name(self) + if self._fluctuation_amplitude == 0: self._fluctuation_destination = None return @@ -130,6 +135,6 @@ def hook_fluctuation_effect(widget_class, widget_type): setattr(widget_class, "fluctuation_amplitude", fluctuation_amplitude) setattr(widget_class, "_fluctuation_amplitude", 0) setattr(widget_class, "fluctuation_move_rate", fluctuation_move_rate) - setattr(widget_class, "_fluctuation_move_rate", 0.1) + setattr(widget_class, "_fluctuation_move_rate", 0.01) setattr(widget_class, "update_fluctuation", update_fluctuation) From 1adab7bcfb27a3e483c0eb0ad98dc9814a502686 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 22 Feb 2022 20:53:25 -0500 Subject: [PATCH 12/15] Add example for colorwheel effect --- examples/displayio_effects_colorwheel.py | 58 ++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 examples/displayio_effects_colorwheel.py diff --git a/examples/displayio_effects_colorwheel.py b/examples/displayio_effects_colorwheel.py new file mode 100644 index 0000000..d772726 --- /dev/null +++ b/examples/displayio_effects_colorwheel.py @@ -0,0 +1,58 @@ +# SPDX-FileCopyrightText: 2021 GaryZ, Alec Delaney +# SPDX-FileCopyrightText: Copyright (c) 2022 Alec Delaney for CircuitPython Organization +# +# SPDX-License-Identifier: Unlicense +############################# +""" +Use the random fluctuation effect for the Dial. +""" + +import time +import board +import displayio +import terminalio +from displayio_dial import Dial +from displayio_effects import WidgetType, colorwheel_effect + +# Fonts used for the Dial tick labels +tick_font = terminalio.FONT + +display = board.DISPLAY # create the display on the PyPortal or Clue (for example) +# otherwise change this to setup the display +# for display chip driver and pinout you have (e.g. ILI9341) + + +# Define the minimum and maximum values for the dial +minimum_value = 0 +maximum_value = 100 + +# Hook in the throttle effect for the Dial widget +colorwheel_effect.hook_colorwheel_effect(Dial, WidgetType.DIAL) + +# Create a Dial widget +my_dial = Dial( + x=20, # set x-position of the dial inside of my_group + y=20, # set y-position of the dial inside of my_group + width=180, # requested width of the dial + height=180, # requested height of the dial + padding=25, # add 25 pixels around the dial to make room for labels + start_angle=-120, # left angle position at -120 degrees + sweep_angle=240, # total sweep angle of 240 degrees + min_value=minimum_value, # set the minimum value shown on the dial + max_value=maximum_value, # set the maximum value shown on the dial + tick_label_font=tick_font, # the font used for the tick labels + tick_label_scale=2.0, # the scale factor for the tick label font +) + +my_group = displayio.Group() +my_group.append(my_dial) + +display.show(my_group) # add high level Group to the display + +# Set the dial to the value before turning on the fluctuation effect +my_dial.value = 50 + +while True: + + my_dial.update_colorwheel() + time.sleep(0.01) From e22535e757b0a7be0628dbf796d5ce844085bac9 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 22 Feb 2022 20:54:55 -0500 Subject: [PATCH 13/15] Reformatted and linted per pre-commit --- displayio_effects/colorwheel_effect.py | 4 ++-- displayio_effects/fluctuation_effect.py | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/displayio_effects/colorwheel_effect.py b/displayio_effects/colorwheel_effect.py index 0325b6f..eb64bf4 100644 --- a/displayio_effects/colorwheel_effect.py +++ b/displayio_effects/colorwheel_effect.py @@ -43,7 +43,7 @@ COLORWHEEL_COLORS = cycle([colorwheel(color_value) for color_value in range(256)]) -def get_widget_value(instance): +def _get_widget_value(instance): widget_type = getattr(instance, WIDGET_TYPE_ATTR) return COLORWHEEL_WIDGET_VALUES[widget_type] @@ -81,7 +81,7 @@ def hook_colorwheel_effect(widget_class, widget_type): def update_colorwheel(self): """Updates the widget value and propagates the fluctuation effect refresh""" - palette_map = get_widget_value(self) + palette_map = _get_widget_value(self) palette_attr = self for attr_path in palette_map["path"]: palette_attr = getattr(palette_attr, attr_path) diff --git a/displayio_effects/fluctuation_effect.py b/displayio_effects/fluctuation_effect.py index 079b391..fef7a8c 100644 --- a/displayio_effects/fluctuation_effect.py +++ b/displayio_effects/fluctuation_effect.py @@ -33,7 +33,8 @@ WidgetType.GAUGE: "level", } -def get_value_name(instance): + +def _get_value_name(instance): widget_type = getattr(instance, WIDGET_TYPE_ATTR) return FLUCTUATION_WIDGET_VALUES[widget_type] @@ -48,7 +49,7 @@ def fluctuation_amplitude(self): @fluctuation_amplitude.setter def fluctuation_amplitude(self, amplitude): - value_name = get_value_name(self) + value_name = _get_value_name(self) if amplitude < 0: raise ValueError("Fluctuation effect setting must be larger than 0") if amplitude: @@ -72,7 +73,7 @@ def fluctuation_move_rate(self, rate): def update_fluctuation(self): """Updates the widget value and propagates the fluctuation effect refresh""" - value_name = get_value_name(self) + value_name = _get_value_name(self) if self._fluctuation_amplitude == 0: self._fluctuation_destination = None From 8d766b50ea22742ee714e5005c66e625028bdc88 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 30 Apr 2025 12:23:57 -0500 Subject: [PATCH 14/15] new infrastructure files, use ruff, update for new displayio API --- .pre-commit-config.yaml | 47 ++++------- .readthedocs.yaml | 5 +- README.rst | 6 +- displayio_effects/__init__.py | 2 +- displayio_effects/colorwheel_effect.py | 11 ++- displayio_effects/fluctuation_effect.py | 12 ++- docs/api.rst | 6 ++ docs/conf.py | 30 +++---- examples/displayio_effects_colorwheel.py | 5 +- examples/displayio_effects_gauge.py | 6 +- examples/displayio_effects_simpletest.py | 4 +- pyproject.toml | 52 +++++++++++- requirements.txt | 1 + ruff.toml | 100 +++++++++++++++++++++++ setup.py | 63 -------------- 15 files changed, 208 insertions(+), 142 deletions(-) create mode 100644 ruff.toml delete mode 100644 setup.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0afe50a..ff19dde 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,40 +1,21 @@ -# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò +# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries # # SPDX-License-Identifier: Unlicense repos: -- repo: https://github.com/python/black - rev: 20.8b1 + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 hooks: - - id: black -- repo: https://github.com/fsfe/reuse-tool - rev: v0.12.1 + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.4 hooks: - - id: reuse -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.3.0 + - id: ruff-format + - id: ruff + args: ["--fix"] + - repo: https://github.com/fsfe/reuse-tool + rev: v3.0.1 hooks: - - id: check-yaml - - id: end-of-file-fixer - - id: trailing-whitespace -- repo: https://github.com/pycqa/pylint - rev: pylint-2.7.1 - hooks: - - id: pylint - name: pylint (library code) - types: [python] - exclude: "^(docs/|examples/|tests/|setup.py$)" -- repo: local - hooks: - - id: pylint_examples - name: pylint (examples code) - description: Run pylint rules on "examples/*.py" files - entry: /usr/bin/env bash -c - args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name,consider-using-f-string $example; done)'] - language: system - - id: pylint_tests - name: pylint (tests code) - description: Run pylint rules on "tests/*.py" files - entry: /usr/bin/env bash -c - args: ['([[ ! -d "tests" ]] || for test in $(find . -path "./tests/*.py"); do pylint --disable=missing-docstring $test; done)'] - language: system + - id: reuse diff --git a/.readthedocs.yaml b/.readthedocs.yaml index b79ec5b..ee38fa0 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -8,8 +8,11 @@ # Required version: 2 +sphinx: + configuration: docs/conf.py + build: - os: ubuntu-20.04 + os: ubuntu-lts-latest tools: python: "3" diff --git a/README.rst b/README.rst index 88544ca..d9b4e88 100644 --- a/README.rst +++ b/README.rst @@ -17,9 +17,9 @@ Introduction :alt: Build Status -.. image:: https://img.shields.io/badge/code%20style-black-000000.svg - :target: https://github.com/psf/black - :alt: Code Style: Black +.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json + :target: https://github.com/astral-sh/ruff + :alt: Code Style: Ruff Add some flair to your widgets with effects! diff --git a/displayio_effects/__init__.py b/displayio_effects/__init__.py index 021b2bf..c1bc85a 100644 --- a/displayio_effects/__init__.py +++ b/displayio_effects/__init__.py @@ -21,9 +21,9 @@ https://circuitpython.org/downloads """ - WIDGET_TYPE_ATTR = "_widget_type" + # pylint: disable=too-few-public-methods class WidgetType: """Enum values for customizable widget types. Valid options are: diff --git a/displayio_effects/colorwheel_effect.py b/displayio_effects/colorwheel_effect.py index eb64bf4..9f16aa7 100644 --- a/displayio_effects/colorwheel_effect.py +++ b/displayio_effects/colorwheel_effect.py @@ -4,7 +4,7 @@ # SPDX-License-Identifier: MIT # pylint: disable=protected-access """ -`displayio_effects.fluctuation_effect` +`displayio_effects.colorwheel_effect` ================================================================================ Add the colorwheel effect to your widgets @@ -21,9 +21,10 @@ https://circuitpython.org/downloads """ +from adafruit_itertools import cycle from rainbowio import colorwheel -from adafruit_itertools.adafruit_itertools import cycle -from displayio_effects import WidgetType, WIDGET_TYPE_ATTR + +from displayio_effects import WIDGET_TYPE_ATTR, WidgetType __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/tekktrik/CircuitPython_Org_DisplayIO_Effects.git" @@ -69,9 +70,7 @@ def hook_colorwheel_effect(widget_class, widget_type): """ if not COLORWHEEL_WIDGET_VALUES.get(widget_type): - raise ValueError( - "The given widget does not have the ability to use this effect" - ) + raise ValueError("The given widget does not have the ability to use this effect") setattr(widget_class, WIDGET_TYPE_ATTR, widget_type) diff --git a/displayio_effects/fluctuation_effect.py b/displayio_effects/fluctuation_effect.py index fef7a8c..d7b8e32 100644 --- a/displayio_effects/fluctuation_effect.py +++ b/displayio_effects/fluctuation_effect.py @@ -22,7 +22,8 @@ """ import random -from displayio_effects import WidgetType, WIDGET_TYPE_ATTR + +from displayio_effects import WIDGET_TYPE_ATTR, WidgetType __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/tekktrik/CircuitPython_Org_DisplayIO_Effects.git" @@ -79,11 +80,10 @@ def update_fluctuation(self): self._fluctuation_destination = None return - if self._fluctuation_destination in (None, self._fluctuation_hold_value): + if self._fluctuation_destination in {None, self._fluctuation_hold_value}: limit_bound = self._fluctuation_amplitude * 10 self._fluctuation_destination = ( - random.uniform(-limit_bound, limit_bound) / 10 - + self._fluctuation_hold_value + random.uniform(-limit_bound, limit_bound) / 10 + self._fluctuation_hold_value ) value = getattr(self, value_name) @@ -124,9 +124,7 @@ def hook_fluctuation_effect(widget_class, widget_type): """ if not FLUCTUATION_WIDGET_VALUES.get(widget_type): - raise ValueError( - "The given widget does not have the ability to use this effect" - ) + raise ValueError("The given widget does not have the ability to use this effect") setattr(widget_class, WIDGET_TYPE_ATTR, widget_type) diff --git a/docs/api.rst b/docs/api.rst index e8830c9..357234c 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -4,5 +4,11 @@ .. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py) .. use this format as the module name: "adafruit_foo.foo" +API Reference +############# + .. automodule:: displayio_effects.fluctuation_effect :members: + +.. automodule:: displayio_effects.colorwheel_effect + :members: diff --git a/docs/conf.py b/docs/conf.py index 1761605..3e9ca3d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,9 +1,8 @@ -# -*- coding: utf-8 -*- - # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries # # SPDX-License-Identifier: MIT +import datetime import os import sys @@ -16,6 +15,7 @@ # ones. extensions = [ "sphinx.ext.autodoc", + "sphinxcontrib.jquery", "sphinx.ext.intersphinx", "sphinx.ext.napoleon", "sphinx.ext.todo", @@ -27,6 +27,7 @@ # autodoc module docs will fail to generate with a warning. # autodoc_mock_imports = ["digitalio", "busio"] +autodoc_preserve_defaults = True intersphinx_mapping = { "python": ("https://docs.python.org/3", None), @@ -46,7 +47,12 @@ # General information about the project. project = "CircuitPython DisplayIO_Effects Library" -copyright = "2022 Alec Delaney" +creation_year = "2022" +current_year = str(datetime.datetime.now().year) +year_duration = ( + current_year if current_year == creation_year else creation_year + " - " + current_year +) +copyright = year_duration + " Alec Delaney" author = "Alec Delaney" # The version info for the project you're documenting, acts as replacement for @@ -63,7 +69,7 @@ # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = None +language = "en" # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. @@ -101,19 +107,9 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -on_rtd = os.environ.get("READTHEDOCS", None) == "True" - -if not on_rtd: # only import and set the theme if we're building docs locally - try: - import sphinx_rtd_theme - - html_theme = "sphinx_rtd_theme" - html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] - except: - html_theme = "default" - html_theme_path = ["."] -else: - html_theme_path = ["."] +import sphinx_rtd_theme + +html_theme = "sphinx_rtd_theme" # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, diff --git a/examples/displayio_effects_colorwheel.py b/examples/displayio_effects_colorwheel.py index d772726..96b2471 100644 --- a/examples/displayio_effects_colorwheel.py +++ b/examples/displayio_effects_colorwheel.py @@ -8,10 +8,12 @@ """ import time + import board import displayio import terminalio from displayio_dial import Dial + from displayio_effects import WidgetType, colorwheel_effect # Fonts used for the Dial tick labels @@ -47,12 +49,11 @@ my_group = displayio.Group() my_group.append(my_dial) -display.show(my_group) # add high level Group to the display +display.root_group = my_group # add high level Group to the display # Set the dial to the value before turning on the fluctuation effect my_dial.value = 50 while True: - my_dial.update_colorwheel() time.sleep(0.01) diff --git a/examples/displayio_effects_gauge.py b/examples/displayio_effects_gauge.py index 122481c..a6caa8a 100644 --- a/examples/displayio_effects_gauge.py +++ b/examples/displayio_effects_gauge.py @@ -6,11 +6,12 @@ Use the random fluctuation effect for the Gauge. """ - import time + import board import displayio from displayio_gauge import Gauge + from displayio_effects import WidgetType, fluctuation_effect display = board.DISPLAY @@ -24,7 +25,7 @@ color_palette[0] = 0x000000 bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0) main_group.append(bg_sprite) -display.show(main_group) +display.root_group = main_group fluctuation_effect.hook_fluctuation_effect(Gauge, WidgetType.GAUGE) @@ -45,5 +46,4 @@ while True: - my_gauge.update_fluctuation() diff --git a/examples/displayio_effects_simpletest.py b/examples/displayio_effects_simpletest.py index ea7dfda..a33362c 100644 --- a/examples/displayio_effects_simpletest.py +++ b/examples/displayio_effects_simpletest.py @@ -11,6 +11,7 @@ import displayio import terminalio from displayio_dial import Dial + from displayio_effects import WidgetType, fluctuation_effect # Fonts used for the Dial tick labels @@ -47,7 +48,7 @@ my_group = displayio.Group() my_group.append(my_dial) -display.show(my_group) # add high level Group to the display +display.root_group = my_group # add high level Group to the display # Set the dial to the value before turning on the fluctuation effect my_dial.value = 50 @@ -56,5 +57,4 @@ my_dial.fluctuation_move_rate = 0.01 # Fluctuate at "0.01" per throttle_update() while True: - my_dial.update_fluctuation() diff --git a/pyproject.toml b/pyproject.toml index f3c35ae..89476f8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,50 @@ -# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò +# SPDX-FileCopyrightText: 2022 Alec Delaney, written for Adafruit Industries +# SPDX-FileCopyrightText: Copyright (c) 2025 Alec Delaney for circuitpython # -# SPDX-License-Identifier: Unlicense +# SPDX-License-Identifier: MIT -[tool.black] -target-version = ['py35'] +[build-system] +requires = [ + "setuptools", + "wheel", + "setuptools-scm", +] + +[project] +name = "circuitpython-displayio-effects" +description = "Add some flair to your displayio widgets with effects!" +version = "0.0.0+auto.0" +readme = "README.rst" +authors = [ + {name = "circuitpython"} +] +urls = {Homepage = "https://github.com/circuitpython/CircuitPython_Org_DisplayIO_Effects"} +keywords = [ + "adafruit", + "blinka", + "circuitpython", + "micropython", + "displayio_effects", + "effects,", + "displayio,", + "widget", +] +license = {text = "MIT"} +classifiers = [ + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries", + "Topic :: Software Development :: Embedded Systems", + "Topic :: System :: Hardware", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", +] +dynamic = ["dependencies", "optional-dependencies"] + +[tool.setuptools] +# TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER, +# CHANGE `py_modules = ['...']` TO `packages = ['...']` +packages = ["displayio_effects"] + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.txt"]} +optional-dependencies = {optional = {file = ["optional_requirements.txt"]}} diff --git a/requirements.txt b/requirements.txt index dc267ca..7071aa9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ # SPDX-License-Identifier: MIT Adafruit-Blinka +adafruit-circuitpython-itertools diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..970c292 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,100 @@ +# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +target-version = "py38" +line-length = 100 + +[lint] +preview = true +select = ["I", "PL", "UP"] + +extend-select = [ + "D419", # empty-docstring + "E501", # line-too-long + "W291", # trailing-whitespace + "PLC0414", # useless-import-alias + "PLC2401", # non-ascii-name + "PLC2801", # unnecessary-dunder-call + "PLC3002", # unnecessary-direct-lambda-call + "E999", # syntax-error + "PLE0101", # return-in-init + "F706", # return-outside-function + "F704", # yield-outside-function + "PLE0116", # continue-in-finally + "PLE0117", # nonlocal-without-binding + "PLE0241", # duplicate-bases + "PLE0302", # unexpected-special-method-signature + "PLE0604", # invalid-all-object + "PLE0605", # invalid-all-format + "PLE0643", # potential-index-error + "PLE0704", # misplaced-bare-raise + "PLE1141", # dict-iter-missing-items + "PLE1142", # await-outside-async + "PLE1205", # logging-too-many-args + "PLE1206", # logging-too-few-args + "PLE1307", # bad-string-format-type + "PLE1310", # bad-str-strip-call + "PLE1507", # invalid-envvar-value + "PLE2502", # bidirectional-unicode + "PLE2510", # invalid-character-backspace + "PLE2512", # invalid-character-sub + "PLE2513", # invalid-character-esc + "PLE2514", # invalid-character-nul + "PLE2515", # invalid-character-zero-width-space + "PLR0124", # comparison-with-itself + "PLR0202", # no-classmethod-decorator + "PLR0203", # no-staticmethod-decorator + "UP004", # useless-object-inheritance + "PLR0206", # property-with-parameters + "PLR0904", # too-many-public-methods + "PLR0911", # too-many-return-statements + "PLR0912", # too-many-branches + "PLR0913", # too-many-arguments + "PLR0914", # too-many-locals + "PLR0915", # too-many-statements + "PLR0916", # too-many-boolean-expressions + "PLR1702", # too-many-nested-blocks + "PLR1704", # redefined-argument-from-local + "PLR1711", # useless-return + "C416", # unnecessary-comprehension + "PLR1733", # unnecessary-dict-index-lookup + "PLR1736", # unnecessary-list-index-lookup + + # ruff reports this rule is unstable + #"PLR6301", # no-self-use + + "PLW0108", # unnecessary-lambda + "PLW0120", # useless-else-on-loop + "PLW0127", # self-assigning-variable + "PLW0129", # assert-on-string-literal + "B033", # duplicate-value + "PLW0131", # named-expr-without-context + "PLW0245", # super-without-brackets + "PLW0406", # import-self + "PLW0602", # global-variable-not-assigned + "PLW0603", # global-statement + "PLW0604", # global-at-module-level + + # fails on the try: import typing used by libraries + #"F401", # unused-import + + "F841", # unused-variable + "E722", # bare-except + "PLW0711", # binary-op-exception + "PLW1501", # bad-open-mode + "PLW1508", # invalid-envvar-default + "PLW1509", # subprocess-popen-preexec-fn + "PLW2101", # useless-with-lock + "PLW3301", # nested-min-max +] + +ignore = [ + "PLR2004", # magic-value-comparison + "UP030", # format literals + "PLW1514", # unspecified-encoding + +] + +[format] +line-ending = "lf" diff --git a/setup.py b/setup.py deleted file mode 100644 index bf40135..0000000 --- a/setup.py +++ /dev/null @@ -1,63 +0,0 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -# SPDX-FileCopyrightText: Copyright (c) 2022 Alec Delaney for CircuitPython Organization -# -# SPDX-License-Identifier: MIT - -"""A setuptools based setup module. - -See: -https://packaging.python.org/en/latest/distributing.html -https://github.com/pypa/sampleproject -""" - -from setuptools import setup, find_packages - -# To use a consistent encoding -from codecs import open -from os import path - -here = path.abspath(path.dirname(__file__)) - -# Get the long description from the README file -with open(path.join(here, "README.rst"), encoding="utf-8") as f: - long_description = f.read() - -setup( - # CircuitPython Org Bundle Information - name="circuitpython-displayio-effects", - use_scm_version={ - # This is needed for the PyPI version munging in the Github Actions release.yml - "git_describe_command": "git describe --tags --long", - "local_scheme": "no-local-version", - }, - setup_requires=["setuptools_scm"], - description="Add some flair to your widgets with effects!", - long_description=long_description, - long_description_content_type="text/x-rst", - # The project's main homepage. - url="https://github.com/tekktrik/CircuitPython_Org_DisplayIO_Effects.git", - # Author details - author="Alec Delaney", - author_email="", # TODO: Add your email here - install_requires=[ - "Adafruit-Blinka", - ], - # Choose your license - license="MIT", - # See https://pypi.python.org/pypi?%3Aaction=list_classifiers - classifiers=[ - "Development Status :: 3 - Alpha", - "Intended Audience :: Developers", - "Topic :: Software Development :: Libraries", - "Topic :: System :: Hardware", - "License :: OSI Approved :: MIT License", - "Programming Language :: Python :: 3", - ], - # What does your project relate to? - keywords="adafruit blinka circuitpython micropython displayio_effects effects, displayio, widget", - # You can just specify the packages manually here if your project is - # simple. Or you can use find_packages(). - # TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER, - # CHANGE `py_modules=['...']` TO `packages=['...']` - py_modules=["displayio_effects"], -) From e7bed0c4a4ea53c5bb4f989224cdff82a3cf8036 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 30 Apr 2025 12:27:08 -0500 Subject: [PATCH 15/15] new actions files --- .github/workflows/build.yml | 70 +----------------------- .github/workflows/release.yml | 88 ------------------------------ .github/workflows/release_gh.yml | 23 ++++++++ .github/workflows/release_pypi.yml | 19 +++++++ 4 files changed, 44 insertions(+), 156 deletions(-) delete mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/release_gh.yml create mode 100644 .github/workflows/release_pypi.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f3a4593..041a337 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,71 +10,5 @@ jobs: test: runs-on: ubuntu-latest steps: - - name: Dump GitHub context - env: - GITHUB_CONTEXT: ${{ toJson(github) }} - run: echo "$GITHUB_CONTEXT" - - name: Translate Repo Name For Build Tools filename_prefix - id: repo-name - run: | - echo ::set-output name=repo-name::$( - echo ${{ github.repository }} | - awk -F '\/' '{ print tolower($2) }' | - tr '_' '-' - ) - - name: Set up Python 3.x - uses: actions/setup-python@v2 - with: - python-version: "3.x" - - name: Versions - run: | - python3 --version - - name: Checkout Current Repo - uses: actions/checkout@v1 - with: - submodules: true - - name: Checkout tools repo - uses: actions/checkout@v2 - with: - repository: adafruit/actions-ci-circuitpython-libs - path: actions-ci - - name: Install dependencies - # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) - run: | - source actions-ci/install.sh - - name: Pip install pylint, Sphinx, pre-commit - run: | - pip install --force-reinstall pylint Sphinx sphinx-rtd-theme pre-commit - - name: Library version - run: git describe --dirty --always --tags - - name: Setup problem matchers - uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1 - - name: Pre-commit hooks - run: | - pre-commit run --all-files - - name: Build assets - run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . - - name: Archive bundles - uses: actions/upload-artifact@v2 - with: - name: bundles - path: ${{ github.workspace }}/bundles/ - - name: Check For docs folder - id: need-docs - run: | - echo ::set-output name=docs::$( find . -wholename './docs' ) - - name: Build docs - if: contains(steps.need-docs.outputs.docs, 'docs') - working-directory: docs - run: sphinx-build -E -W -b html . _build/html - - name: Check For setup.py - id: need-pypi - run: | - echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) - - name: Build Python package - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') - run: | - pip install --upgrade setuptools wheel twine readme_renderer testresources - python setup.py sdist - python setup.py bdist_wheel --universal - twine check dist/* + - name: Run Build CI workflow + uses: adafruit/workflows-circuitpython-libs/build@main diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index b279a99..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,88 +0,0 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -# -# SPDX-License-Identifier: MIT - -name: Release Actions - -on: - release: - types: [published] - -jobs: - upload-release-assets: - runs-on: ubuntu-latest - steps: - - name: Dump GitHub context - env: - GITHUB_CONTEXT: ${{ toJson(github) }} - run: echo "$GITHUB_CONTEXT" - - name: Translate Repo Name For Build Tools filename_prefix - id: repo-name - run: | - echo ::set-output name=repo-name::$( - echo ${{ github.repository }} | - awk -F '\/' '{ print tolower($2) }' | - tr '_' '-' - ) - - name: Set up Python 3.x - uses: actions/setup-python@v2 - with: - python-version: "3.x" - - name: Versions - run: | - python3 --version - - name: Checkout Current Repo - uses: actions/checkout@v1 - with: - submodules: true - - name: Checkout tools repo - uses: actions/checkout@v2 - with: - repository: adafruit/actions-ci-circuitpython-libs - path: actions-ci - - name: Install deps - run: | - source actions-ci/install.sh - - name: Build assets - run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . - - name: Upload Release Assets - # the 'official' actions version does not yet support dynamically - # supplying asset names to upload. @csexton's version chosen based on - # discussion in the issue below, as its the simplest to implement and - # allows for selecting files with a pattern. - # https://github.com/actions/upload-release-asset/issues/4 - #uses: actions/upload-release-asset@v1.0.1 - uses: csexton/release-asset-action@master - with: - pattern: "bundles/*" - github-token: ${{ secrets.GITHUB_TOKEN }} - - upload-pypi: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: Check For setup.py - id: need-pypi - run: | - echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) - - name: Set up Python - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - name: Install dependencies - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') - run: | - python -m pip install --upgrade pip - pip install setuptools wheel twine - - name: Build and publish - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') - env: - TWINE_USERNAME: ${{ secrets.pypi_username }} - TWINE_PASSWORD: ${{ secrets.pypi_password }} - run: | - for file in $(find -not -path "./.*" -not -path "./docs*" -name "*.py"); do - sed -i -e "s/0.0.0-auto.0/${{github.event.release.tag_name}}/" $file; - done; - python setup.py sdist - twine upload dist/* diff --git a/.github/workflows/release_gh.yml b/.github/workflows/release_gh.yml new file mode 100644 index 0000000..423009e --- /dev/null +++ b/.github/workflows/release_gh.yml @@ -0,0 +1,23 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: GitHub Release Actions + +on: + release: + types: [published] + +jobs: + upload-release-assets: + runs-on: ubuntu-latest + steps: + - name: Run GitHub Release CI workflow + uses: adafruit/workflows-circuitpython-libs/release-gh@main + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + upload-url: ${{ github.event.release.upload_url }} + # TODO: If you're creating a package (library is a folder), add this + # argument along with the prefix (or full name) of the package folder + # so the MPY bundles are built correctly:s + # package-prefix: displayio_effects diff --git a/.github/workflows/release_pypi.yml b/.github/workflows/release_pypi.yml new file mode 100644 index 0000000..65775b7 --- /dev/null +++ b/.github/workflows/release_pypi.yml @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: PyPI Release Actions + +on: + release: + types: [published] + +jobs: + upload-release-assets: + runs-on: ubuntu-latest + steps: + - name: Run PyPI Release CI workflow + uses: adafruit/workflows-circuitpython-libs/release-pypi@main + with: + pypi-username: ${{ secrets.pypi_username }} + pypi-password: ${{ secrets.pypi_password }}