From 79828c040fd6c5fb47b5c053f830d7bb2f11706c Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 16 Aug 2022 18:09:16 -0400 Subject: [PATCH 01/47] Update version string --- adafruit_turtle.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index 5944da4..ca6b6a2 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -33,7 +33,7 @@ import board import displayio -__version__ = "0.0.0-auto.0" +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_turtle.git" diff --git a/pyproject.toml b/pyproject.toml index f8e5813..fcb3b34 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ requires = [ [project] name = "adafruit-circuitpython-turtle" description = "Turtle graphics library for CircuitPython and displayio" -version = "0.0.0-auto.0" +version = "0.0.0+auto.0" readme = "README.rst" authors = [ {name = "Adafruit Industries", email = "circuitpython@adafruit.com"} From 2a993cbc389719c64253d82bf21438a6637c0c25 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 16 Aug 2022 21:09:16 -0400 Subject: [PATCH 02/47] Fix version strings in workflow files --- .github/workflows/build.yml | 2 +- .github/workflows/release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 22f6582..cb2f60e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -71,7 +71,7 @@ jobs: run: | pip install --upgrade build twine for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do - sed -i -e "s/0.0.0-auto.0/1.2.3/" $file; + sed -i -e "s/0.0.0+auto.0/1.2.3/" $file; done; python -m build twine check dist/* diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d1b4f8d..f3a0325 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -82,7 +82,7 @@ jobs: TWINE_PASSWORD: ${{ secrets.pypi_password }} run: | for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do - sed -i -e "s/0.0.0-auto.0/${{github.event.release.tag_name}}/" $file; + sed -i -e "s/0.0.0+auto.0/${{github.event.release.tag_name}}/" $file; done; python -m build twine upload dist/* From 6f672a2351cc28ff7a1971459d63912a5d974427 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 22 Aug 2022 21:36:33 -0400 Subject: [PATCH 03/47] Keep copyright up to date in documentation --- docs/conf.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index faff217..38c281c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -6,6 +6,7 @@ import os import sys +import datetime sys.path.insert(0, os.path.abspath("..")) @@ -66,7 +67,8 @@ # General information about the project. project = "Adafruit turtle Library" -copyright = "2019 Adafruit" +current_year = str(datetime.datetime.now().year) +copyright = current_year + " Adafruit" author = "Adafruit" # The version info for the project you're documenting, acts as replacement for From 9f23b464df772da1565c09a06e2da84ff9da1b53 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 23 Aug 2022 17:26:23 -0400 Subject: [PATCH 04/47] Use year duration range for copyright attribution --- docs/conf.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 38c281c..3a409b4 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -67,8 +67,14 @@ # General information about the project. project = "Adafruit turtle Library" +creation_year = "2019" current_year = str(datetime.datetime.now().year) -copyright = current_year + " Adafruit" +year_duration = ( + current_year + if current_year == creation_year + else creation_year + " - " + current_year +) +copyright = year_duration + " Adafruit" author = "Adafruit" # The version info for the project you're documenting, acts as replacement for From 30c0988eb6b84c2f72ac9891b1fd10ce493a154b Mon Sep 17 00:00:00 2001 From: Carsten Thue-Bludworth Date: Tue, 27 Sep 2022 22:20:03 -0400 Subject: [PATCH 05/47] Fixed CPython compatibility --- adafruit_turtle.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index ca6b6a2..94bba3b 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -30,8 +30,11 @@ import gc import math import time -import board import displayio +try: + import board +except: + print("[adafruit-turtle.py]: Couldn't import board module.") __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_turtle.git" @@ -80,7 +83,7 @@ def __init__(self): pass -class Vec2D(tuple): +class Vec2D(): """A 2 dimensional vector class, used as a helper class for implementing turtle graphics. May be useful for turtle graphics programs also. @@ -94,8 +97,8 @@ class Vec2D(tuple): # k*a and a*k multiplication with scalar # |a| absolute value of a # a.rotate(angle) rotation - def __init__(self, x, y): - super().__init__((x, y)) + def __new__(cls, x, y): + return (x, y) def __add__(self, other): return Vec2D(self[0] + other[0], self[1] + other[1]) From b197cd61359791fd951b5f8b2b4f18f21a734235 Mon Sep 17 00:00:00 2001 From: Carsten Thue-Bludworth Date: Tue, 27 Sep 2022 22:27:30 -0400 Subject: [PATCH 06/47] Added author info and ran through black --- adafruit_turtle.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index 94bba3b..b69f820 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -31,6 +31,7 @@ import math import time import displayio + try: import board except: @@ -83,7 +84,7 @@ def __init__(self): pass -class Vec2D(): +class Vec2D: """A 2 dimensional vector class, used as a helper class for implementing turtle graphics. May be useful for turtle graphics programs also. From 0161017036169233ddf69d42e053b8addd132ae7 Mon Sep 17 00:00:00 2001 From: Carsten Thue-Bludworth Date: Tue, 27 Sep 2022 22:30:59 -0400 Subject: [PATCH 07/47] Actually added author info --- adafruit_turtle.py | 1 + 1 file changed, 1 insertion(+) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index b69f820..6fd1fb1 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: 2006-2010 Gregor Lingl for Adafruit Industries # SPDX-FileCopyrightText: 2019 LadyAda for Adafruit Industries # SPDX-FileCopyrightText: 2021 Dave Astels for Adafruit Industries +# SPDX-FileCopyrightText: 2022 Carsten Thue-Bludworth for Adafruit Industries # # SPDX-License-Identifier: MIT From cf9a11aac86c0b037539ae4b996aeba32292c9e8 Mon Sep 17 00:00:00 2001 From: Carsten Thue-Bludworth Date: Tue, 27 Sep 2022 23:30:15 -0400 Subject: [PATCH 08/47] Fixed test errors by implementing __getitem__ method for Vec2D --- adafruit_turtle.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index 6fd1fb1..f50106a 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -35,7 +35,7 @@ try: import board -except: +except NotImplementedError: print("[adafruit-turtle.py]: Couldn't import board module.") __version__ = "0.0.0+auto.0" @@ -102,6 +102,9 @@ class Vec2D: def __new__(cls, x, y): return (x, y) + def __getitem__(self, index): + return getattr(self, index) + def __add__(self, other): return Vec2D(self[0] + other[0], self[1] + other[1]) From 8c3267999c553217e06eba9485eb7a2c3179a57c Mon Sep 17 00:00:00 2001 From: Carsten Thue-Bludworth Date: Sat, 1 Oct 2022 10:50:56 -0400 Subject: [PATCH 09/47] Removed author info --- adafruit_turtle.py | 1 - 1 file changed, 1 deletion(-) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index f50106a..31b1b5b 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -1,7 +1,6 @@ # SPDX-FileCopyrightText: 2006-2010 Gregor Lingl for Adafruit Industries # SPDX-FileCopyrightText: 2019 LadyAda for Adafruit Industries # SPDX-FileCopyrightText: 2021 Dave Astels for Adafruit Industries -# SPDX-FileCopyrightText: 2022 Carsten Thue-Bludworth for Adafruit Industries # # SPDX-License-Identifier: MIT From 017591b4d49fc33a1fd3309b0a050a7ff076cad9 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 1 Oct 2022 10:53:31 -0500 Subject: [PATCH 10/47] try has-a tuple instead of is-a tuple for Vec2D --- adafruit_turtle.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index ca6b6a2..24b80f0 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -80,7 +80,7 @@ def __init__(self): pass -class Vec2D(tuple): +class Vec2D: """A 2 dimensional vector class, used as a helper class for implementing turtle graphics. May be useful for turtle graphics programs also. @@ -95,7 +95,11 @@ class Vec2D(tuple): # |a| absolute value of a # a.rotate(angle) rotation def __init__(self, x, y): - super().__init__((x, y)) + # super().__init__() + self.values = (x, y) + + def __getitem__(self, index): + return self.values[index] def __add__(self, other): return Vec2D(self[0] + other[0], self[1] + other[1]) @@ -268,8 +272,8 @@ def forward(self, distance): """ p = self.pos() angle = ( - self._angleOffset + self._angleOrient * self._heading - ) % self._fullcircle + self._angleOffset + self._angleOrient * self._heading + ) % self._fullcircle x1 = p[0] + math.sin(math.radians(angle)) * distance y1 = p[1] + math.cos(math.radians(angle)) * distance self.goto(x1, y1) @@ -397,6 +401,7 @@ def goto(self, x1, y1=None): setpos = goto setposition = goto + # pylint:enable=too-many-branches,too-many-statements def setx(self, x): @@ -455,8 +460,8 @@ def _plot(self, x, y, c): pass r = self._pensize // 2 + 1 angle = ( - self._angleOffset + self._angleOrient * self._heading - 90 - ) % self._fullcircle + self._angleOffset + self._angleOrient * self._heading - 90 + ) % self._fullcircle sin = math.sin(math.radians(angle)) cos = math.cos(math.radians(angle)) x0 = x + sin * r From 5acb2d0585eab612973e78b766d36fb3a5ed9b6a Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 1 Oct 2022 11:04:45 -0500 Subject: [PATCH 11/47] only import board if we are going to try to use builtin display --- adafruit_turtle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index 24b80f0..4938c29 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -30,7 +30,6 @@ import gc import math import time -import board import displayio __version__ = "0.0.0+auto.0" @@ -151,6 +150,7 @@ def __init__(self, display=None, scale=1): self._display = display else: try: + import board self._display = board.DISPLAY except AttributeError as err: raise RuntimeError( From c146d6bb77866c419b857c8d9ce02412c748f6a4 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 1 Oct 2022 11:10:10 -0500 Subject: [PATCH 12/47] allow import outside top for board --- adafruit_turtle.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index 4938c29..2c5f046 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -150,7 +150,9 @@ def __init__(self, display=None, scale=1): self._display = display else: try: + # pylint: disable=import-outside-toplevel import board + self._display = board.DISPLAY except AttributeError as err: raise RuntimeError( @@ -272,8 +274,8 @@ def forward(self, distance): """ p = self.pos() angle = ( - self._angleOffset + self._angleOrient * self._heading - ) % self._fullcircle + self._angleOffset + self._angleOrient * self._heading + ) % self._fullcircle x1 = p[0] + math.sin(math.radians(angle)) * distance y1 = p[1] + math.cos(math.radians(angle)) * distance self.goto(x1, y1) @@ -460,8 +462,8 @@ def _plot(self, x, y, c): pass r = self._pensize // 2 + 1 angle = ( - self._angleOffset + self._angleOrient * self._heading - 90 - ) % self._fullcircle + self._angleOffset + self._angleOrient * self._heading - 90 + ) % self._fullcircle sin = math.sin(math.radians(angle)) cos = math.cos(math.radians(angle)) x0 = x + sin * r From 87ee248a953a4c3fc307881e21d1b697c0a12c4b Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 1 Oct 2022 11:11:26 -0500 Subject: [PATCH 13/47] remove unused super init --- adafruit_turtle.py | 1 - 1 file changed, 1 deletion(-) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index 2c5f046..4f49fa0 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -94,7 +94,6 @@ class Vec2D: # |a| absolute value of a # a.rotate(angle) rotation def __init__(self, x, y): - # super().__init__() self.values = (x, y) def __getitem__(self, index): From 332a94751900be16d9d7766df374bd11c835ce17 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 00:02:50 -0400 Subject: [PATCH 14/47] Switching to composite actions --- .github/workflows/build.yml | 67 +---------------------- .github/workflows/release.yml | 88 ------------------------------ .github/workflows/release_gh.yml | 14 +++++ .github/workflows/release_pypi.yml | 14 +++++ 4 files changed, 30 insertions(+), 153 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 cb2f60e..041a337 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,68 +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 Sphinx, pre-commit - run: | - pip install --force-reinstall 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: Build docs - working-directory: docs - run: sphinx-build -E -W -b html . _build/html - - name: Check For pyproject.toml - id: need-pypi - run: | - echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' ) - - name: Build Python package - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - run: | - pip install --upgrade build twine - for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do - sed -i -e "s/0.0.0+auto.0/1.2.3/" $file; - done; - python -m build - 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 f3a0325..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 pyproject.toml - id: need-pypi - run: | - echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' ) - - name: Set up Python - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - name: Install dependencies - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - run: | - python -m pip install --upgrade pip - pip install --upgrade build twine - - name: Build and publish - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - env: - TWINE_USERNAME: ${{ secrets.pypi_username }} - TWINE_PASSWORD: ${{ secrets.pypi_password }} - run: | - for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do - sed -i -e "s/0.0.0+auto.0/${{github.event.release.tag_name}}/" $file; - done; - python -m build - twine upload dist/* diff --git a/.github/workflows/release_gh.yml b/.github/workflows/release_gh.yml new file mode 100644 index 0000000..041a337 --- /dev/null +++ b/.github/workflows/release_gh.yml @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: Build CI + +on: [pull_request, push] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Run Build CI workflow + uses: adafruit/workflows-circuitpython-libs/build@main diff --git a/.github/workflows/release_pypi.yml b/.github/workflows/release_pypi.yml new file mode 100644 index 0000000..041a337 --- /dev/null +++ b/.github/workflows/release_pypi.yml @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: Build CI + +on: [pull_request, push] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Run Build CI workflow + uses: adafruit/workflows-circuitpython-libs/build@main From 4fb06f44827c2bef07a1d58a7aa859fc2c8dd130 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 00:47:01 -0400 Subject: [PATCH 15/47] Updated pylint version to 2.13.0 --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3343606..4c43710 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,7 +18,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: v2.11.1 + rev: v2.13.0 hooks: - id: pylint name: pylint (library code) From 4bdae92772ee1c1a83b19947a5547ffdb816fcbf Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 08:15:21 -0400 Subject: [PATCH 16/47] Update pylint to 2.15.5 --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4c43710..0e5fccc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,7 +18,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: v2.13.0 + rev: v2.15.5 hooks: - id: pylint name: pylint (library code) From f97bae782601be57b7b933cb8ffe44495d13437e Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 09:12:46 -0400 Subject: [PATCH 17/47] Fix release CI files --- .github/workflows/release_gh.yml | 14 +++++++++----- .github/workflows/release_pypi.yml | 15 ++++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.github/workflows/release_gh.yml b/.github/workflows/release_gh.yml index 041a337..b8aa8d6 100644 --- a/.github/workflows/release_gh.yml +++ b/.github/workflows/release_gh.yml @@ -2,13 +2,17 @@ # # SPDX-License-Identifier: MIT -name: Build CI +name: GitHub Release Actions -on: [pull_request, push] +on: + release: + types: [published] jobs: - test: + upload-release-assets: runs-on: ubuntu-latest steps: - - name: Run Build CI workflow - uses: adafruit/workflows-circuitpython-libs/build@main + - name: Run GitHub Release CI workflow + uses: adafruit/workflows-circuitpython-libs/release-gh@main + with: + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release_pypi.yml b/.github/workflows/release_pypi.yml index 041a337..65775b7 100644 --- a/.github/workflows/release_pypi.yml +++ b/.github/workflows/release_pypi.yml @@ -2,13 +2,18 @@ # # SPDX-License-Identifier: MIT -name: Build CI +name: PyPI Release Actions -on: [pull_request, push] +on: + release: + types: [published] jobs: - test: + upload-release-assets: runs-on: ubuntu-latest steps: - - name: Run Build CI workflow - uses: adafruit/workflows-circuitpython-libs/build@main + - 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 }} From 298f6de31017b0c29694aaa6e989a3d2efe21865 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 18:34:33 -0400 Subject: [PATCH 18/47] Update .pylintrc for v2.15.5 --- .pylintrc | 45 ++++----------------------------------------- 1 file changed, 4 insertions(+), 41 deletions(-) diff --git a/.pylintrc b/.pylintrc index f772971..40208c3 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries # # SPDX-License-Identifier: Unlicense @@ -26,7 +26,7 @@ jobs=1 # List of plugins (as comma separated values of python modules names) to load, # usually to register additional checkers. -load-plugins= +load-plugins=pylint.extensions.no_self_use # Pickle collected data for later comparisons. persistent=yes @@ -54,8 +54,8 @@ confidence= # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" -# disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call -disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation,unspecified-encoding +# disable=import-error,raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,deprecated-str-translate-call +disable=raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,import-error,pointless-string-statement,unspecified-encoding # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option @@ -225,12 +225,6 @@ max-line-length=100 # Maximum number of lines in a module max-module-lines=1000 -# List of optional constructs for which whitespace checking is disabled. `dict- -# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. -# `trailing-comma` allows a space between comma and closing bracket: (a, ). -# `empty-line` allows space-only lines. -no-space-check=trailing-comma,dict-separator - # Allow the body of a class to be on the same line as the declaration if body # contains single statement. single-line-class-stmt=no @@ -257,38 +251,22 @@ min-similarity-lines=12 [BASIC] -# Naming hint for argument names -argument-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct argument names argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ -# Naming hint for attribute names -attr-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct attribute names attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ # Bad variable names which should always be refused, separated by a comma bad-names=foo,bar,baz,toto,tutu,tata -# Naming hint for class attribute names -class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ - # Regular expression matching correct class attribute names class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ -# Naming hint for class names -# class-name-hint=[A-Z_][a-zA-Z0-9]+$ -class-name-hint=[A-Z_][a-zA-Z0-9_]+$ - # Regular expression matching correct class names # class-rgx=[A-Z_][a-zA-Z0-9]+$ class-rgx=[A-Z_][a-zA-Z0-9_]+$ -# Naming hint for constant names -const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$ - # Regular expression matching correct constant names const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ @@ -296,9 +274,6 @@ const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ # ones are exempt. docstring-min-length=-1 -# Naming hint for function names -function-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct function names function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ @@ -309,21 +284,12 @@ good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_ # Include a hint for the correct naming format with invalid-name include-naming-hint=no -# Naming hint for inline iteration names -inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$ - # Regular expression matching correct inline iteration names inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ -# Naming hint for method names -method-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct method names method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ -# Naming hint for module names -module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ - # Regular expression matching correct module names module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ @@ -339,9 +305,6 @@ no-docstring-rgx=^_ # to this list to register other decorators that produce valid properties. property-classes=abc.abstractproperty -# Naming hint for variable names -variable-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct variable names variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ From 689c01102cbda652980284ddebb6c1a0e8f98553 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Mon, 7 Nov 2022 21:07:36 -0500 Subject: [PATCH 19/47] Fix pylint errors --- examples/turtle_hilbert.py | 2 ++ examples/turtle_koch.py | 2 ++ examples/turtle_overlayed_koch.py | 2 ++ 3 files changed, 6 insertions(+) diff --git a/examples/turtle_hilbert.py b/examples/turtle_hilbert.py index c2a5e79..6413d3a 100644 --- a/examples/turtle_hilbert.py +++ b/examples/turtle_hilbert.py @@ -1,6 +1,8 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +# pylint: disable=unnecessary-lambda-assignment + import board from adafruit_turtle import turtle diff --git a/examples/turtle_koch.py b/examples/turtle_koch.py index a2d5ee8..9332a36 100644 --- a/examples/turtle_koch.py +++ b/examples/turtle_koch.py @@ -1,6 +1,8 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +# pylint: disable=unnecessary-lambda-assignment + import board from adafruit_turtle import turtle diff --git a/examples/turtle_overlayed_koch.py b/examples/turtle_overlayed_koch.py index 05bfef0..cd92939 100644 --- a/examples/turtle_overlayed_koch.py +++ b/examples/turtle_overlayed_koch.py @@ -1,6 +1,8 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +# pylint: disable=unnecessary-lambda-assignment + import board from adafruit_turtle import turtle, Color From 0ac3837b829e9235816dcb1e92463d59e3c624fb Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Thu, 1 Sep 2022 20:16:31 -0400 Subject: [PATCH 20/47] Add .venv to .gitignore Signed-off-by: Alec Delaney <89490472+tekktrik@users.noreply.github.com> --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 544ec4a..db3d538 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ _build # Virtual environment-specific files .env +.venv # MacOS-specific files *.DS_Store From 2ab650e36436d94a047387f324b215e008601d89 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Thu, 19 Jan 2023 23:39:55 -0500 Subject: [PATCH 21/47] Add upload url to release action Signed-off-by: Alec Delaney <89490472+tekktrik@users.noreply.github.com> --- .github/workflows/release_gh.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release_gh.yml b/.github/workflows/release_gh.yml index b8aa8d6..9acec60 100644 --- a/.github/workflows/release_gh.yml +++ b/.github/workflows/release_gh.yml @@ -16,3 +16,4 @@ jobs: uses: adafruit/workflows-circuitpython-libs/release-gh@main with: github-token: ${{ secrets.GITHUB_TOKEN }} + upload-url: ${{ github.event.release.upload_url }} From d70d57abca4cb48572114fb0dfc79e8e24006a3c Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 19 Apr 2023 10:55:38 -0700 Subject: [PATCH 22/47] Fix koch example --- examples/turtle_koch.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/examples/turtle_koch.py b/examples/turtle_koch.py index 9332a36..f04c919 100644 --- a/examples/turtle_koch.py +++ b/examples/turtle_koch.py @@ -8,22 +8,23 @@ def f(side_length, depth, generation): - if depth != 0: - side = lambda: f(side_length / 3, depth - 1, generation + 1) - side() - turtle.left(60) - side() - turtle.right(120) - side() - turtle.left(60) - side() + if depth == 0: + turtle.forward(side_length) + return + side = lambda: f(side_length / 3, depth - 1, generation + 1) + side() + turtle.left(60) + side() + turtle.right(120) + side() + turtle.left(60) + side() turtle = turtle(board.DISPLAY) unit = min(board.DISPLAY.width / 3, board.DISPLAY.height / 4) top_len = unit * 3 -print(top_len) turtle.penup() turtle.goto(-1.5 * unit, unit) turtle.pendown() From 480352b7b9464ffb0dfda99907bc64c588a5f732 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 19 Apr 2023 10:57:41 -0700 Subject: [PATCH 23/47] Fix overlayed koch --- examples/turtle_overlayed_koch.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/examples/turtle_overlayed_koch.py b/examples/turtle_overlayed_koch.py index cd92939..0bfe018 100644 --- a/examples/turtle_overlayed_koch.py +++ b/examples/turtle_overlayed_koch.py @@ -6,19 +6,21 @@ import board from adafruit_turtle import turtle, Color -generation_colors = [Color.RED, Color.BLUE, Color.GREEN] +generation_colors = [Color.RED, Color.BLUE, Color.GREEN, Color.YELLOW] def f(side_length, depth, generation): - if depth != 0: - side = lambda: f(side_length / 3, depth - 1, generation + 1) - side() - turtle.left(60) - side() - turtle.right(120) - side() - turtle.left(60) - side() + if depth == 0: + turtle.forward(side_length) + return + side = lambda: f(side_length / 3, depth - 1, generation + 1) + side() + turtle.left(60) + side() + turtle.right(120) + side() + turtle.left(60) + side() def snowflake(num_generations, generation_color): @@ -42,7 +44,7 @@ def snowflake(num_generations, generation_color): turtle.goto(-1.5 * unit, unit) turtle.pendown() -for generations in range(3): +for generations in range(4): snowflake(generations, generation_colors[generations]) turtle.right(120) From 614b602f8d1db53d8af19fc631207ecf8ebffbc7 Mon Sep 17 00:00:00 2001 From: Rauha Rahkola Date: Thu, 27 Apr 2023 08:47:11 -0700 Subject: [PATCH 24/47] adding type annotations for adafruit_turtle.py --- .gitignore | 6 ++ adafruit_turtle.py | 228 ++++++++++++++++++++++++--------------------- 2 files changed, 126 insertions(+), 108 deletions(-) diff --git a/.gitignore b/.gitignore index db3d538..87b9508 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,12 @@ __pycache__ # Sphinx build-specific files _build +# MyPy-specific type-checking files +.mypy_cache + +# pip install files +/build/ + # This file results from running `pip -e install .` in a local repository *.egg-info diff --git a/adafruit_turtle.py b/adafruit_turtle.py index 4f49fa0..68f6182 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -3,7 +3,6 @@ # SPDX-FileCopyrightText: 2021 Dave Astels for Adafruit Industries # # SPDX-License-Identifier: MIT - """ `adafruit_turtle` ================================================================================ @@ -23,6 +22,7 @@ * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice """ +from __future__ import annotations # pylint:disable=too-many-public-methods, too-many-instance-attributes, invalid-name # pylint:disable=too-few-public-methods, too-many-lines, too-many-arguments @@ -32,6 +32,11 @@ import time import displayio +try: + from typing import Any, Dict, List, Optional, Tuple, Union +except ImportError: + pass + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_turtle.git" @@ -75,7 +80,7 @@ class Color: DARK_RED, ) - def __init__(self): + def __init__(self) -> None: pass @@ -93,35 +98,35 @@ class Vec2D: # k*a and a*k multiplication with scalar # |a| absolute value of a # a.rotate(angle) rotation - def __init__(self, x, y): + def __init__(self, x: float, y: float) -> None: self.values = (x, y) - def __getitem__(self, index): + def __getitem__(self, index: int) -> float: return self.values[index] - def __add__(self, other): + def __add__(self, other: Vec2D) -> Vec2D: return Vec2D(self[0] + other[0], self[1] + other[1]) - def __mul__(self, other): + def __mul__(self, other: Union[float, Vec2D]) -> Union[float, Vec2D]: if isinstance(other, Vec2D): return self[0] * other[0] + self[1] * other[1] return Vec2D(self[0] * other, self[1] * other) - def __rmul__(self, other): + def __rmul__(self, other: Union[float, int]) -> Vec2D: if isinstance(other, (float, int)): return Vec2D(self[0] * other, self[1] * other) return None - def __sub__(self, other): + def __sub__(self, other: Vec2D) -> Vec2D: return Vec2D(self[0] - other[0], self[1] - other[1]) - def __neg__(self): + def __neg__(self) -> Vec2D: return Vec2D(-self[0], -self[1]) - def __abs__(self): + def __abs__(self) -> float: return (self[0] ** 2 + self[1] ** 2) ** 0.5 - def rotate(self, angle): + def rotate(self, angle: float) -> Vec2D: """Rotate self counterclockwise by angle. :param angle: how much to rotate @@ -132,10 +137,10 @@ def rotate(self, angle): c, s = math.cos(angle), math.sin(angle) return Vec2D(self[0] * c + perp[0] * s, self[1] * c + perp[1] * s) - def __getnewargs__(self): + def __getnewargs__(self) -> Tuple[float, float]: return (self[0], self[1]) - def __repr__(self): + def __repr__(self) -> str: return "({:.2f},{:.2f})".format(self[0], self[1]) @@ -143,8 +148,7 @@ class turtle: """A Turtle that can be given commands to draw.""" # pylint:disable=too-many-statements - def __init__(self, display=None, scale=1): - + def __init__(self, display: Any = None, scale: float = 1) -> None: if display: self._display = display else: @@ -158,21 +162,21 @@ def __init__(self, display=None, scale=1): "No display available. One must be provided." ) from err - self._w = self._display.width - self._h = self._display.height + self._w: int = self._display.width + self._h: int = self._display.height self._x = self._w // (2 * scale) self._y = self._h // (2 * scale) self._speed = 6 - self._heading = 0 + self._heading: float = 0 self._logomode = True self._fullcircle = 360.0 self._degreesPerAU = 1.0 self._angleOrient = 1 - self._angleOffset = 0 + self._angleOffset: float = 0 self._bg_color = 0 - self._splash = displayio.Group() - self._bgscale = 1 + self._splash: Any = displayio.Group() + self._bgscale: int = 1 if self._w == self._h: i = 1 while self._bgscale == 1: @@ -196,7 +200,7 @@ def __init__(self, display=None, scale=1): # group to add background pictures (and/or user-defined stuff) self._bg_addon_group = displayio.Group() self._splash.append(self._bg_addon_group) - self._fg_scale = scale + self._fg_scale: int = int(scale) self._w = self._w // self._fg_scale self._h = self._h // self._fg_scale self._fg_bitmap = displayio.Bitmap(self._w, self._h, len(Color.colors)) @@ -238,20 +242,20 @@ def __init__(self, display=None, scale=1): self.pencolor(Color.WHITE) self._bg_pic = None self._bg_pic_filename = "" - self._turtle_pic = None - self._turtle_odb = None - self._turtle_alt_sprite = None + self._turtle_pic: Any = None + self._turtle_odb: Any = None + self._turtle_alt_sprite: Any = None self._drawturtle() - self._stamps = {} + self._stamps: Dict[int, Any] = {} self._turtle_odb_use = 0 - self._turtle_odb_file = None - self._odb_tilegrid = None + self._turtle_odb_file: Optional[str] = None + self._odb_tilegrid: Any = None gc.collect() self._display.show(self._splash) # pylint:enable=too-many-statements - def _drawturtle(self): + def _drawturtle(self) -> None: if self._turtle_pic is None: self._turtle_sprite.x = int(self._x - 4) self._turtle_sprite.y = int(self._y - 4) @@ -266,7 +270,7 @@ def _drawturtle(self): ########################################################################### # Move and draw - def forward(self, distance): + def forward(self, distance: float) -> None: """Move the turtle forward by the specified distance, in the direction the turtle is headed. :param distance: how far to move (integer or float) @@ -281,7 +285,7 @@ def forward(self, distance): fd = forward - def backward(self, distance): + def backward(self, distance: float) -> None: """Move the turtle backward by distance, opposite to the direction the turtle is headed. Does not change the turtle's heading. @@ -293,7 +297,7 @@ def backward(self, distance): bk = backward back = backward - def right(self, angle): + def right(self, angle: float) -> None: """Turn turtle right by angle units. (Units are by default degrees, but can be set via the degrees() and radians() functions.) Angle orientation depends on the turtle mode, see mode(). @@ -307,7 +311,7 @@ def right(self, angle): rt = right - def left(self, angle): + def left(self, angle: float) -> None: """Turn turtle left by angle units. (Units are by default degrees, but can be set via the degrees() and radians() functions.) Angle orientation depends on the turtle mode, see mode(). @@ -322,7 +326,9 @@ def left(self, angle): lt = left # pylint:disable=too-many-branches,too-many-statements - def goto(self, x1, y1=None): + def goto( + self, x1: Union[float, Vec2D, Tuple[float, float]], y1: Optional[float] = None + ) -> None: """If y1 is None, x1 must be a pair of coordinates or an (x, y) tuple Move turtle to an absolute position. If the pen is down, draw line. @@ -331,35 +337,34 @@ def goto(self, x1, y1=None): :param x1: a number or a pair of numbers :param y1: a number or None """ - if y1 is None: - y1 = x1[1] - x1 = x1[0] - x1 += self._w // 2 - y1 = self._h // 2 - y1 + yn: float = x1[1] if y1 is None else y1 # type: ignore + xn: float = x1[0] if y1 is None else x1 # type: ignore + xn += self._w // 2 + yn = self._h // 2 - yn x0 = self._x y0 = self._y if not self.isdown(): - self._x = x1 # woot, we just skip ahead - self._y = y1 + self._x = xn # woot, we just skip ahead + self._y = yn self._drawturtle() return - steep = abs(y1 - y0) > abs(x1 - x0) + steep = abs(yn - y0) > abs(xn - x0) rev = False - dx = x1 - x0 + dx = xn - x0 if steep: x0, y0 = y0, x0 - x1, y1 = y1, x1 - dx = x1 - x0 + xn, yn = yn, xn + dx = xn - x0 - if x0 > x1: + if x0 > xn: rev = True - dx = x0 - x1 + dx = x0 - xn - dy = abs(y1 - y0) + dy = abs(yn - y0) err = dx / 2 ystep = -1 - if y0 < y1: + if y0 < yn: ystep = 1 step = 1 if self._speed > 0: @@ -367,7 +372,7 @@ def goto(self, x1, y1=None): else: ts = 0 - while (not rev and x0 <= x1) or (rev and x1 <= x0): + while (not rev and x0 <= xn) or (rev and xn <= x0): if steep: try: self._plot(int(y0), int(x0), self._pencolor) @@ -405,7 +410,7 @@ def goto(self, x1, y1=None): # pylint:enable=too-many-branches,too-many-statements - def setx(self, x): + def setx(self, x: float) -> None: """Set the turtle's first coordinate to x, leave second coordinate unchanged. @@ -414,7 +419,7 @@ def setx(self, x): """ self.goto(x, self.pos()[1]) - def sety(self, y): + def sety(self, y: float) -> None: """Set the turtle's second coordinate to y, leave first coordinate unchanged. @@ -423,7 +428,7 @@ def sety(self, y): """ self.goto(self.pos()[0], y) - def setheading(self, to_angle): + def setheading(self, to_angle: float) -> None: """Set the orientation of the turtle to to_angle. Here are some common directions in degrees: @@ -443,7 +448,7 @@ def setheading(self, to_angle): seth = setheading - def home(self): + def home(self) -> None: """Move turtle to the origin - coordinates (0,0) - and set its heading to its start-orientation (which depends on the mode, see mode()). @@ -452,7 +457,7 @@ def home(self): self.goto(0, 0) # pylint:disable=too-many-locals, too-many-statements, too-many-branches - def _plot(self, x, y, c): + def _plot(self, x: float, y: float, c: int) -> None: if self._pensize == 1: try: self._fg_bitmap[int(x), int(y)] = c @@ -532,7 +537,9 @@ def _plot(self, x, y, c): # pylint:enable=too-many-locals, too-many-statements, too-many-branches - def circle(self, radius, extent=None, steps=None): + def circle( + self, radius: float, extent: Optional[float] = None, steps: Optional[int] = None + ) -> None: """Draw a circle with given radius. The center is radius units left of the turtle; extent - an angle - determines which part of the circle is drawn. If extent is not given, draw the entire circle. If extent is not @@ -576,9 +583,8 @@ def circle(self, radius, extent=None, steps=None): self.setheading(h) # pylint:disable=inconsistent-return-statements - def speed(self, speed=None): + def speed(self, speed: Optional[int] = None) -> int: """ - Set the turtle's speed to an integer value in the range 0..10. If no argument is given, return current speed. @@ -599,16 +605,16 @@ def speed(self, speed=None): :param speed: the new turtle speed (0..10) or None """ - if speed is None: - return self._speed - if speed > 10 or speed < 1: - self._speed = 0 - else: - self._speed = speed + if speed is not None: + if speed > 10 or speed < 1: + self._speed = 0 + else: + self._speed = speed + return self._speed # pylint:enable=inconsistent-return-statements - def dot(self, size=None, color=None): + def dot(self, size: Optional[int] = None, color: Optional[int] = None) -> None: """Draw a circular dot with diameter size, using color. If size is not given, the maximum of pensize+4 and 2*pensize is used. @@ -641,7 +647,7 @@ def dot(self, size=None, color=None): self._plot(self._x, self._y, color) self._pensize = pensize - def stamp(self, bitmap=None, palette=None): + def stamp(self, bitmap: Optional[Any] = None, palette: Optional[Any] = None) -> int: """ Stamp a copy of the turtle shape onto the canvas at the current turtle position. Return a stamp_id for that stamp, which can be used to @@ -684,7 +690,7 @@ def stamp(self, bitmap=None, palette=None): return s_id - def clearstamp(self, stampid): + def clearstamp(self, stampid: int) -> None: """ Delete stamp with given stampid. @@ -706,9 +712,8 @@ def clearstamp(self, stampid): else: raise TypeError("Stamp id must be an int") - def clearstamps(self, n=None): + def clearstamps(self, n: Optional[int] = None) -> None: """ - Delete all or first/last n of turtle's stamps. If n is None, delete all stamps, if n > 0 delete first n stamps, else if n < 0 delete last n stamps. @@ -727,13 +732,15 @@ def clearstamps(self, n=None): ########################################################################### # Tell turtle's state - def pos(self): + def pos(self) -> Vec2D: """Return the turtle's current location (x,y) (as a Vec2D vector).""" return Vec2D(self._x - self._w // 2, self._h // 2 - self._y) position = pos - def towards(self, x1, y1=None): + def towards( + self, x1: Union[float, Vec2D, Tuple[float, float]], y1: Optional[float] = None + ) -> float: """ Return the angle between the line from turtle position to position specified by (x,y) or the vector. This depends on the turtle's start @@ -743,30 +750,32 @@ def towards(self, x1, y1=None): :param y: a number if x is a number, else None """ - if y1 is None: - y1 = x1[1] - x1 = x1[0] - x0, y0 = self.pos() + yn: float = x1[1] if y1 is None else y1 # type: ignore + xn: float = x1[0] if y1 is None else x1 # type: ignore + p = self.pos() + x0, y0 = (p[0], p[1]) - result = math.degrees(math.atan2(x1 - x0, y1 - y0)) + result = math.degrees(math.atan2(xn - x0, yn - y0)) result /= self._degreesPerAU return (self._angleOffset + self._angleOrient * result) % self._fullcircle - def xcor(self): + def xcor(self) -> float: """Return the turtle's x coordinate.""" return self._x - self._w // 2 - def ycor(self): + def ycor(self) -> float: """Return the turtle's y coordinate.""" return self._h // 2 - self._y - def heading(self): + def heading(self) -> float: """Return the turtle's current heading (value depends on the turtle mode, see mode()). """ return self._heading - def distance(self, x1, y1=None): + def distance( + self, x1: Union[float, List[float], Tuple[float, float]], y1: Optional[float] + ) -> float: """ Return the distance from the turtle to (x,y) or the vector, in turtle step units. @@ -775,16 +784,16 @@ def distance(self, x1, y1=None): :param y: a number if x is a number, else None """ - if y1 is None: - y1 = x1[1] - x1 = x1[0] - x0, y0 = self.pos() - return math.sqrt((x0 - x1) ** 2 + (y0 - y1) ** 2) + yn: float = x1[1] if y1 is None else y1 # type: ignore + xn: float = x1[0] if y1 is None else x1 # type: ignore + p = self.pos() + x0, y0 = (p[0], p[1]) + return math.sqrt((x0 - xn) ** 2 + (y0 - yn) ** 2) ########################################################################### # Setting and measurement - def _setDegreesPerAU(self, fullcircle): + def _setDegreesPerAU(self, fullcircle: float) -> None: """Helper function for degrees() and radians()""" self._fullcircle = fullcircle self._degreesPerAU = 360 / fullcircle @@ -793,7 +802,7 @@ def _setDegreesPerAU(self, fullcircle): else: self._angleOffset = -fullcircle / 4 - def degrees(self, fullcircle=360): + def degrees(self, fullcircle: float = 360) -> None: """Set angle measurement units, i.e. set number of "degrees" for a full circle. Default value is 360 degrees. @@ -802,12 +811,12 @@ def degrees(self, fullcircle=360): """ self._setDegreesPerAU(fullcircle) - def radians(self): + def radians(self) -> None: """Set the angle measurement units to radians. Equivalent to degrees(2*math.pi).""" self._setDegreesPerAU(2 * math.pi) - def mode(self, mode=None): + def mode(self, mode: Optional[str] = None) -> Optional[str]: """ Set turtle mode ("standard" or "logo") and perform reset. @@ -834,12 +843,12 @@ def mode(self, mode=None): raise RuntimeError("Mode must be 'logo', 'standard', or None") return None - def window_height(self): + def window_height(self) -> float: """ Return the height of the turtle window.""" return self._h - def window_width(self): + def window_width(self) -> float: """ Return the width of the turtle window.""" return self._w @@ -847,25 +856,25 @@ def window_width(self): ########################################################################### # Drawing state - def pendown(self): + def pendown(self) -> None: """Pull the pen down - drawing when moving.""" self._penstate = True pd = pendown down = pendown - def penup(self): + def penup(self) -> None: """Pull the pen up - no drawing when moving.""" self._penstate = False pu = penup up = penup - def isdown(self): + def isdown(self) -> bool: """Return True if pen is down, False if it's up.""" return self._penstate - def pensize(self, width=None): + def pensize(self, width: Optional[int] = None) -> int: """ Set the line thickness to width or return it. If no argument is given, the current pensize is returned. @@ -884,12 +893,12 @@ def pensize(self, width=None): # pylint:disable=no-self-use - def _color_to_pencolor(self, c): + def _color_to_pencolor(self, c: int) -> int: return Color.colors.index(c) # pylint:enable=no-self-use - def pencolor(self, c=None): + def pencolor(self, c: Optional[int] = None) -> int: """ Return or set the pencolor. @@ -917,7 +926,7 @@ def pencolor(self, c=None): self._turtle_palette.make_opaque(1) return c - def bgcolor(self, c=None): + def bgcolor(self, c: Optional[int] = None) -> int: """ Return or set the background color. @@ -951,7 +960,7 @@ def bgcolor(self, c=None): return Color.colors[self._bg_color] # pylint:disable=inconsistent-return-statements - def bgpic(self, picname=None): + def bgpic(self, picname: Optional[str] = None) -> Optional[str]: """Set background image or return name of current backgroundimage. Optional argument: picname -- a string, name of an image file or "nopic". @@ -979,13 +988,14 @@ def bgpic(self, picname=None): # centered self._odb_tilegrid.y = ((self._h * self._fg_scale) // 2) - (odb.height // 2) self._odb_tilegrid.x = ((self._w * self._fg_scale) // 2) - (odb.width // 2) + return None # pylint:enable=inconsistent-return-statements ########################################################################### # More drawing control - def reset(self): + def reset(self) -> None: """ Delete the turtle's drawings from the screen, re-center the turtle and set variables to the default values.""" @@ -999,7 +1009,7 @@ def reset(self): self.pensize(1) self.pencolor(Color.WHITE) - def clear(self): + def clear(self) -> None: """Delete the turtle's drawings from the screen. Do not move turtle.""" self.clearstamps() for w in range(self._w): @@ -1014,7 +1024,7 @@ def clear(self): ########################################################################### # Visibility - def showturtle(self): + def showturtle(self) -> None: """ Make the turtle visible.""" if self._turtle_group: @@ -1026,7 +1036,7 @@ def showturtle(self): st = showturtle - def hideturtle(self): + def hideturtle(self) -> None: """ Make the turtle invisible.""" if not self._turtle_group: @@ -1035,7 +1045,7 @@ def hideturtle(self): ht = hideturtle - def isvisible(self): + def isvisible(self) -> bool: """ Return True if the Turtle is shown, False if it's hidden.""" if self._turtle_group: @@ -1043,7 +1053,9 @@ def isvisible(self): return False # pylint:disable=too-many-statements, too-many-branches - def changeturtle(self, source=None, dimensions=(12, 12)): + def changeturtle( + self, source: Any = None, dimensions: Tuple[int, int] = (12, 12) + ) -> None: """ Change the turtle. if a string is provided, its a path to an image opened via OnDiskBitmap @@ -1117,7 +1129,7 @@ def changeturtle(self, source=None, dimensions=(12, 12)): ########################################################################### # Other - def _turn(self, angle): + def _turn(self, angle: float) -> None: if angle % self._fullcircle == 0: return if not self.isdown() or self._pensize == 1: @@ -1148,7 +1160,7 @@ def _turn(self, angle): return if abs(angle - steps * d_angle) >= abs(d_angle): - steps += abs(angle - steps * d_angle) // abs(d_angle) + steps += int(abs(angle - steps * d_angle) // abs(d_angle)) self._plot(self._x, self._y, self._pencolor) for _ in range(steps): @@ -1162,7 +1174,7 @@ def _turn(self, angle): self._heading %= self._fullcircle self._plot(self._x, self._y, self._pencolor) - def _GCD(self, a, b): + def _GCD(self, a: int, b: int) -> int: """GCD(a,b): recursive 'Greatest common divisor' calculus for int numbers a and b""" if b == 0: From 012c3b3a9c1214fed949c652005e08d4aafc1c1f Mon Sep 17 00:00:00 2001 From: Rauha Rahkola Date: Thu, 27 Apr 2023 08:55:30 -0700 Subject: [PATCH 25/47] revert some unnecessary refactoring --- adafruit_turtle.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index 68f6182..cc49d4f 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -583,7 +583,7 @@ def circle( self.setheading(h) # pylint:disable=inconsistent-return-statements - def speed(self, speed: Optional[int] = None) -> int: + def speed(self, speed: Optional[int] = None) -> Optional[int]: """ Set the turtle's speed to an integer value in the range 0..10. If no argument is given, return current speed. @@ -605,12 +605,13 @@ def speed(self, speed: Optional[int] = None) -> int: :param speed: the new turtle speed (0..10) or None """ - if speed is not None: - if speed > 10 or speed < 1: - self._speed = 0 - else: - self._speed = speed - return self._speed + if speed is None: + return self._speed + if speed > 10 or speed < 1: + self._speed = 0 + else: + self._speed = speed + return None # pylint:enable=inconsistent-return-statements From 141d80ce8f23bdbc6353c93f45d6eecaa046dc52 Mon Sep 17 00:00:00 2001 From: Tekktrik Date: Tue, 9 May 2023 20:26:25 -0400 Subject: [PATCH 26/47] Update pre-commit hooks Signed-off-by: Tekktrik --- .pre-commit-config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0e5fccc..70ade69 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,21 +4,21 @@ repos: - repo: https://github.com/python/black - rev: 22.3.0 + rev: 23.3.0 hooks: - id: black - repo: https://github.com/fsfe/reuse-tool - rev: v0.14.0 + rev: v1.1.2 hooks: - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.2.0 + rev: v4.4.0 hooks: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: v2.15.5 + rev: v2.17.4 hooks: - id: pylint name: pylint (library code) From a30359b9d8cb8cd6755aca46037447a607763617 Mon Sep 17 00:00:00 2001 From: Tekktrik Date: Wed, 10 May 2023 22:47:08 -0400 Subject: [PATCH 27/47] Run pre-commit --- adafruit_turtle.py | 1 - examples/turtle_sierpinski.py | 1 - 2 files changed, 2 deletions(-) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index 4f49fa0..814054f 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -144,7 +144,6 @@ class turtle: # pylint:disable=too-many-statements def __init__(self, display=None, scale=1): - if display: self._display = display else: diff --git a/examples/turtle_sierpinski.py b/examples/turtle_sierpinski.py index ff9e155..5c63ea5 100644 --- a/examples/turtle_sierpinski.py +++ b/examples/turtle_sierpinski.py @@ -10,7 +10,6 @@ def getMid(p1, p2): def triangle(points, depth): - turtle.penup() turtle.goto(points[0][0], points[0][1]) turtle.pendown() From 751760ebd7e08c586aec5bd579229ccd3c4c1c29 Mon Sep 17 00:00:00 2001 From: Tekktrik Date: Sun, 14 May 2023 13:00:32 -0400 Subject: [PATCH 28/47] Update .pylintrc, fix jQuery for docs Signed-off-by: Tekktrik --- .pylintrc | 2 +- docs/conf.py | 1 + docs/requirements.txt | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index 40208c3..f945e92 100644 --- a/.pylintrc +++ b/.pylintrc @@ -396,4 +396,4 @@ min-public-methods=1 # Exceptions that will emit a warning when being caught. Defaults to # "Exception" -overgeneral-exceptions=Exception +overgeneral-exceptions=builtins.Exception diff --git a/docs/conf.py b/docs/conf.py index 3a409b4..eb67e83 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -17,6 +17,7 @@ # ones. extensions = [ "sphinx.ext.autodoc", + "sphinxcontrib.jquery", "sphinx.ext.intersphinx", "sphinx.ext.napoleon", "sphinx.ext.todo", diff --git a/docs/requirements.txt b/docs/requirements.txt index 88e6733..797aa04 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -3,3 +3,4 @@ # SPDX-License-Identifier: Unlicense sphinx>=4.0.0 +sphinxcontrib-jquery From f03cfc7fa1639ee09b93958ede489d3483db5122 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 4 Sep 2023 10:50:19 -0500 Subject: [PATCH 29/47] merge main, handle PR feedback --- adafruit_turtle.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index 5cee85c..5c69d2d 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -113,7 +113,7 @@ def __mul__(self, other: Union[float, Vec2D]) -> Union[float, Vec2D]: return self[0] * other[0] + self[1] * other[1] return Vec2D(self[0] * other, self[1] * other) - def __rmul__(self, other: Union[float, int]) -> Vec2D: + def __rmul__(self, other: float) -> Optional[Vec2D]: if isinstance(other, (float, int)): return Vec2D(self[0] * other, self[1] * other) return None @@ -176,7 +176,7 @@ def __init__(self, display: Any = None, scale: float = 1) -> None: self._angleOffset: float = 0 self._bg_color = 0 - self._splash: Any = displayio.Group() + self._splash: displayio.Group = displayio.Group() self._bgscale: int = 1 if self._w == self._h: i = 1 @@ -243,14 +243,14 @@ def __init__(self, display: Any = None, scale: float = 1) -> None: self.pencolor(Color.WHITE) self._bg_pic = None self._bg_pic_filename = "" - self._turtle_pic: Any = None - self._turtle_odb: Any = None - self._turtle_alt_sprite: Any = None + self._turtle_pic = None + self._turtle_odb = None + self._turtle_alt_sprite = None self._drawturtle() - self._stamps: Dict[int, Any] = {} + self._stamps = {} self._turtle_odb_use = 0 - self._turtle_odb_file: Optional[str] = None - self._odb_tilegrid: Any = None + self._turtle_odb_file = None + self._odb_tilegrid = None gc.collect() self._display.show(self._splash) @@ -752,12 +752,12 @@ def towards( :param y: a number if x is a number, else None """ - yn: float = x1[1] if y1 is None else y1 # type: ignore - xn: float = x1[0] if y1 is None else x1 # type: ignore - p = self.pos() - x0, y0 = (p[0], p[1]) + if y1 is None: + y1 = x1[1] + x1 = x1[0] + x0, y0 = self.pos() - result = math.degrees(math.atan2(xn - x0, yn - y0)) + result = math.degrees(math.atan2(x1 - x0, y1 - y0)) result /= self._degreesPerAU return (self._angleOffset + self._angleOrient * result) % self._fullcircle @@ -1056,7 +1056,7 @@ def isvisible(self) -> bool: # pylint:disable=too-many-statements, too-many-branches def changeturtle( - self, source: Any = None, dimensions: Tuple[int, int] = (12, 12) + self, source: Optional[Union[displayio.TileGrid, str]] = None, dimensions: Tuple[int, int] = (12, 12) ) -> None: """ Change the turtle. From d4a599a92852a4b164f8018f176ff7c63ac04153 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 4 Sep 2023 10:57:38 -0500 Subject: [PATCH 30/47] code format, use more specific types than Any --- adafruit_turtle.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index 5c69d2d..2cf5c3d 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -34,7 +34,7 @@ import displayio try: - from typing import Any, Dict, List, Optional, Tuple, Union + from typing import List, Optional, Tuple, Union except ImportError: pass @@ -149,7 +149,9 @@ class turtle: """A Turtle that can be given commands to draw.""" # pylint:disable=too-many-statements - def __init__(self, display: Any = None, scale: float = 1) -> None: + def __init__( + self, display: Optional[displayio.Display] = None, scale: float = 1 + ) -> None: if display: self._display = display else: @@ -649,7 +651,11 @@ def dot(self, size: Optional[int] = None, color: Optional[int] = None) -> None: self._plot(self._x, self._y, color) self._pensize = pensize - def stamp(self, bitmap: Optional[Any] = None, palette: Optional[Any] = None) -> int: + def stamp( + self, + bitmap: Optional[displayio.Bitmap] = None, + palette: Optional[displayio.Palette] = None, + ) -> int: """ Stamp a copy of the turtle shape onto the canvas at the current turtle position. Return a stamp_id for that stamp, which can be used to @@ -1056,7 +1062,9 @@ def isvisible(self) -> bool: # pylint:disable=too-many-statements, too-many-branches def changeturtle( - self, source: Optional[Union[displayio.TileGrid, str]] = None, dimensions: Tuple[int, int] = (12, 12) + self, + source: Optional[Union[displayio.TileGrid, str]] = None, + dimensions: Tuple[int, int] = (12, 12), ) -> None: """ Change the turtle. From d4477d112660fa6b6539f35d702ec7108deff174 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 18 Sep 2023 16:24:09 -0500 Subject: [PATCH 31/47] "fix rtd theme " --- docs/conf.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index eb67e83..58baf1e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -124,19 +124,10 @@ # 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" +html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] # 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, From 9d09f16bb23504d8bf27830f975c85825df615f1 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Thu, 19 Oct 2023 01:48:10 -0400 Subject: [PATCH 32/47] Remove depreciated displayio.show --- adafruit_turtle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index 2cf5c3d..23b2a54 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -254,7 +254,7 @@ def __init__( self._turtle_odb_file = None self._odb_tilegrid = None gc.collect() - self._display.show(self._splash) + self._display.root_group = self._splash # pylint:enable=too-many-statements From 5a170cb7b15897f9055392f205ffc27e59035b58 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 16 Oct 2023 14:30:31 -0500 Subject: [PATCH 33/47] unpin sphinx and add sphinx-rtd-theme to docs reqs Signed-off-by: foamyguy --- docs/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 797aa04..979f568 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,5 +2,6 @@ # # SPDX-License-Identifier: Unlicense -sphinx>=4.0.0 +sphinx sphinxcontrib-jquery +sphinx-rtd-theme From 057d7fd9facfe60c950d80ae50536c75f0b7b5db Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 7 Oct 2024 09:24:05 -0500 Subject: [PATCH 34/47] remove deprecated get_html_theme_path() call Signed-off-by: foamyguy --- docs/conf.py | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 58baf1e..618ae93 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -127,7 +127,6 @@ import sphinx_rtd_theme html_theme = "sphinx_rtd_theme" -html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] # 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, From eeac41fe029f0a778eed43df9548960ea291bf30 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 2 Dec 2024 15:58:23 -0600 Subject: [PATCH 35/47] list standard colors in the docstrings --- adafruit_turtle.py | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index 23b2a54..3b5c3ae 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -46,21 +46,84 @@ class Color: """Standard colors""" WHITE = 0xFFFFFF + """White 0xFFFFFF + + :meta hide-value:""" + BLACK = 0x000000 + """Black 0x000000 + + :meta hide-value:""" + RED = 0xFF0000 + """Red 0xFF0000 + + :meta hide-value:""" + ORANGE = 0xFFA500 + """Orange 0xFFA500 + + :meta hide-value:""" + YELLOW = 0xFFEE00 + """Yellow 0xFFEE00 + + :meta hide-value:""" + GREEN = 0x00C000 + """Green 0x00C000 + + :meta hide-value:""" + BLUE = 0x0000FF + """Blue 0x0000FF + + :meta hide-value:""" + PURPLE = 0x8040C0 + """Purple 0x8040C0 + + :meta hide-value:""" + PINK = 0xFF40C0 + """Pink 0xFF40C0 + + :meta hide-value:""" + LIGHT_GRAY = 0xAAAAAA + """Light Gray 0xAAAAAA + + :meta hide-value:""" + GRAY = 0x444444 + """Gray 0x444444 + + :meta hide-value:""" + BROWN = 0xCA801D + """Brown 0xCA801D + + :meta hide-value:""" + DARK_GREEN = 0x008700 + """Dark Green 0x008700 + + :meta hide-value:""" + TURQUOISE = 0x00C0C0 + """Turquoise 0x00C0C0 + + :meta hide-value:""" + DARK_BLUE = 0x0000AA + """Dark Blue 0x0000AA + + :meta hide-value:""" + DARK_RED = 0x800000 + """Dark Red 0x800000 + + :meta hide-value:""" colors = ( BLACK, From ebd591df4541211b42ee31a8531494d7ed967c45 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 2 Dec 2024 16:02:41 -0600 Subject: [PATCH 36/47] remove duplicate color name --- adafruit_turtle.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index 3b5c3ae..c7c41ea 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -46,83 +46,83 @@ class Color: """Standard colors""" WHITE = 0xFFFFFF - """White 0xFFFFFF + """0xFFFFFF :meta hide-value:""" BLACK = 0x000000 - """Black 0x000000 + """0x000000 :meta hide-value:""" RED = 0xFF0000 - """Red 0xFF0000 + """0xFF0000 :meta hide-value:""" ORANGE = 0xFFA500 - """Orange 0xFFA500 + """0xFFA500 :meta hide-value:""" YELLOW = 0xFFEE00 - """Yellow 0xFFEE00 + """0xFFEE00 :meta hide-value:""" GREEN = 0x00C000 - """Green 0x00C000 + """0x00C000 :meta hide-value:""" BLUE = 0x0000FF - """Blue 0x0000FF + """0x0000FF :meta hide-value:""" PURPLE = 0x8040C0 - """Purple 0x8040C0 + """0x8040C0 :meta hide-value:""" PINK = 0xFF40C0 - """Pink 0xFF40C0 + """0xFF40C0 :meta hide-value:""" LIGHT_GRAY = 0xAAAAAA - """Light Gray 0xAAAAAA + """0xAAAAAA :meta hide-value:""" GRAY = 0x444444 - """Gray 0x444444 + """0x444444 :meta hide-value:""" BROWN = 0xCA801D - """Brown 0xCA801D + """0xCA801D :meta hide-value:""" DARK_GREEN = 0x008700 - """Dark Green 0x008700 + """0x008700 :meta hide-value:""" TURQUOISE = 0x00C0C0 - """Turquoise 0x00C0C0 + """0x00C0C0 :meta hide-value:""" DARK_BLUE = 0x0000AA - """Dark Blue 0x0000AA + """0x0000AA :meta hide-value:""" DARK_RED = 0x800000 - """Dark Red 0x800000 - + """0x800000 + :meta hide-value:""" colors = ( From 0c57fd42dcf745ffa75a9e318a252b9ad001087b Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 2 Dec 2024 16:06:44 -0600 Subject: [PATCH 37/47] format --- adafruit_turtle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index c7c41ea..b501c22 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -122,7 +122,7 @@ class Color: DARK_RED = 0x800000 """0x800000 - + :meta hide-value:""" colors = ( From f2ae512e0e86c6e70dcd2c04251480c98526ebb2 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 2 Dec 2024 17:24:48 -0600 Subject: [PATCH 38/47] default to "standard" mode --- adafruit_turtle.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index 23b2a54..b255b84 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -171,11 +171,11 @@ def __init__( self._y = self._h // (2 * scale) self._speed = 6 self._heading: float = 0 - self._logomode = True self._fullcircle = 360.0 self._degreesPerAU = 1.0 - self._angleOrient = 1 - self._angleOffset: float = 0 + self._logomode = False + self._angleOrient = -1 + self._angleOffset: float = self._fullcircle / 4 self._bg_color = 0 self._splash: displayio.Group = displayio.Group() From e921f796f1578e6b87cd369f0735a9e07b071a0d Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 4 Dec 2024 09:30:24 -0600 Subject: [PATCH 39/47] make circle and dot always use degrees internally --- adafruit_turtle.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index c9d7f97..ed5a550 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -626,6 +626,12 @@ def circle( # --or: circle(radius, extent) # arc # --or: circle(radius, extent, steps) # --or: circle(radius, steps=6) # 6-sided polygon + change_back = False + if not self._in_degrees(): + change_back = True + original_mode = "standard" if not self._logomode else "logo" + self.degrees() + self.mode("standard") pos = self.pos() h = self._heading if extent is None: @@ -647,6 +653,9 @@ def circle( # get back to exact same position and heading self.goto(pos) self.setheading(h) + if change_back: + self.radians() + self.mode(original_mode) # pylint: disable=possibly-used-before-assignment # pylint:disable=inconsistent-return-statements def speed(self, speed: Optional[int] = None) -> Optional[int]: @@ -690,6 +699,13 @@ def dot(self, size: Optional[int] = None, color: Optional[int] = None) -> None: :param color: the color of the dot """ + change_back = False + if not self._in_degrees(): + change_back = True + original_mode = "standard" if not self._logomode else "logo" + print(f"old mode: {original_mode}") + self.degrees() + self.mode("standard") if size is None: size = max(self._pensize + 4, self._pensize * 2) if color is None: @@ -713,6 +729,9 @@ def dot(self, size: Optional[int] = None, color: Optional[int] = None) -> None: self._pensize = 1 self._plot(self._x, self._y, color) self._pensize = pensize + if change_back: + self.radians() + self.mode(original_mode) # pylint: disable=possibly-used-before-assignment def stamp( self, @@ -882,6 +901,10 @@ def degrees(self, fullcircle: float = 360) -> None: """ self._setDegreesPerAU(fullcircle) + def _in_degrees(self) -> bool: + print(self._degreesPerAU) + return self._degreesPerAU == 1.0 + def radians(self) -> None: """Set the angle measurement units to radians. Equivalent to degrees(2*math.pi).""" From 96222c342964255c0a4f23d2cf7f077a408dec3f Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 4 Dec 2024 10:12:15 -0600 Subject: [PATCH 40/47] remove space --- adafruit_turtle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index ed5a550..dfa6d0e 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -655,7 +655,7 @@ def circle( self.setheading(h) if change_back: self.radians() - self.mode(original_mode) # pylint: disable=possibly-used-before-assignment + self.mode(original_mode) # pylint:disable=possibly-used-before-assignment # pylint:disable=inconsistent-return-statements def speed(self, speed: Optional[int] = None) -> Optional[int]: @@ -731,7 +731,7 @@ def dot(self, size: Optional[int] = None, color: Optional[int] = None) -> None: self._pensize = pensize if change_back: self.radians() - self.mode(original_mode) # pylint: disable=possibly-used-before-assignment + self.mode(original_mode) # pylint:disable=possibly-used-before-assignment def stamp( self, From 591b805474ebc34297c45f7416c2ad389588cc73 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 4 Dec 2024 10:16:11 -0600 Subject: [PATCH 41/47] remove pylint disables --- adafruit_turtle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index dfa6d0e..df57e77 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -655,7 +655,7 @@ def circle( self.setheading(h) if change_back: self.radians() - self.mode(original_mode) # pylint:disable=possibly-used-before-assignment + self.mode(original_mode) # pylint:disable=inconsistent-return-statements def speed(self, speed: Optional[int] = None) -> Optional[int]: @@ -731,7 +731,7 @@ def dot(self, size: Optional[int] = None, color: Optional[int] = None) -> None: self._pensize = pensize if change_back: self.radians() - self.mode(original_mode) # pylint:disable=possibly-used-before-assignment + self.mode(original_mode) def stamp( self, From 614e9e2b4fd2012679b8a35f49126495c12c3fb9 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 4 Dec 2024 17:51:34 -0600 Subject: [PATCH 42/47] Account for fractions of a pixel when drawing Previously, the endpoint of the line was always moved along in increments of 1 pixel, so that the endpoint would always be rounded down. This could accumulate to give quite large differences from what the program intended. Ensure that "goto" always ends up storing the floating point endpoints and that the line is drawn from the rounded-integer starting coordinate and rounded-integer ending coordinate. This makes the 3 test lines in the OP's "turtle_truncate.txt" example be the same length. Closes: #41 --- adafruit_turtle.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index c9d7f97..54cdcf4 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -407,13 +407,17 @@ def goto( xn: float = x1[0] if y1 is None else x1 # type: ignore xn += self._w // 2 yn = self._h // 2 - yn - x0 = self._x - y0 = self._y if not self.isdown(): self._x = xn # woot, we just skip ahead self._y = yn self._drawturtle() return + + self._do_draw_line(round(self._x), round(self._y), round(xn), round(yn)) + self._x = xn + self._y = yn + + def _do_draw_line(self, x0: int, y0: int, xn: int, yn: int): steep = abs(yn - y0) > abs(xn - x0) rev = False dx = xn - x0 @@ -444,15 +448,11 @@ def goto( self._plot(int(y0), int(x0), self._pencolor) except IndexError: pass - self._x = y0 - self._y = x0 else: try: self._plot(int(x0), int(y0), self._pencolor) except IndexError: pass - self._x = x0 - self._y = y0 if self._speed > 0: if step >= self._speed: # mark the step From 277983a83636bd1bba1f50b40bea7dd27692be85 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 9 Dec 2024 09:12:37 -0600 Subject: [PATCH 43/47] fix for visible turtle location --- adafruit_turtle.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index 54cdcf4..5c40b4d 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -311,6 +311,8 @@ def __init__( self._turtle_pic = None self._turtle_odb = None self._turtle_alt_sprite = None + self._turtle_x = self._x + self._turtle_y = self._y self._drawturtle() self._stamps = {} self._turtle_odb_use = 0 @@ -323,15 +325,23 @@ def __init__( def _drawturtle(self) -> None: if self._turtle_pic is None: - self._turtle_sprite.x = int(self._x - 4) - self._turtle_sprite.y = int(self._y - 4) + self._turtle_sprite.x = int(self._turtle_x - 4) + self._turtle_sprite.y = int(self._turtle_y - 4) else: if self._turtle_odb is not None: - self._turtle_alt_sprite.x = int(self._x - self._turtle_odb.width // 2) - self._turtle_alt_sprite.y = int(self._y - self._turtle_odb.height // 2) + self._turtle_alt_sprite.x = int( + self._turtle_x - self._turtle_odb.width // 2 + ) + self._turtle_alt_sprite.y = int( + self._turtle_y - self._turtle_odb.height // 2 + ) else: - self._turtle_alt_sprite.x = int(self._x - self._turtle_pic[0] // 2) - self._turtle_alt_sprite.y = int(self._y - self._turtle_pic[1] // 2) + self._turtle_alt_sprite.x = int( + self._turtle_x - self._turtle_pic[0] // 2 + ) + self._turtle_alt_sprite.y = int( + self._turtle_y - self._turtle_pic[1] // 2 + ) ########################################################################### # Move and draw @@ -448,11 +458,15 @@ def _do_draw_line(self, x0: int, y0: int, xn: int, yn: int): self._plot(int(y0), int(x0), self._pencolor) except IndexError: pass + self._turtle_x = y0 + self._turtle_y = x0 else: try: self._plot(int(x0), int(y0), self._pencolor) except IndexError: pass + self._turtle_x = x0 + self._turtle_y = y0 if self._speed > 0: if step >= self._speed: # mark the step From 5aaa6abd758af2e0b0d46744634617285d992700 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 14 Jan 2025 11:32:34 -0600 Subject: [PATCH 44/47] add sphinx configuration to rtd.yaml Signed-off-by: foamyguy --- .readthedocs.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 33c2a61..88bca9f 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -8,6 +8,9 @@ # Required version: 2 +sphinx: + configuration: docs/conf.py + build: os: ubuntu-20.04 tools: From cb4511ae61697247bb473741fb52b6b9e12a67cf Mon Sep 17 00:00:00 2001 From: Justin Myers Date: Thu, 27 Feb 2025 15:43:54 -0800 Subject: [PATCH 45/47] Remove secrets usage --- docs/conf.py | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 618ae93..e4137e6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -39,7 +39,6 @@ "adafruit_bitmap_font", "adafruit_display_text", "adafruit_esp32spi", - "secrets", "adafruit_sdcard", "storage", "adafruit_io", From 8ee4425a0d3bb330cac773c4f52840dcb8308a92 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 16 May 2025 19:34:43 +0000 Subject: [PATCH 46/47] change to ruff --- .gitattributes | 11 + .pre-commit-config.yaml | 43 +-- .pylintrc | 399 -------------------------- README.rst | 6 +- adafruit_turtle.py | 52 +--- docs/api.rst | 3 + docs/conf.py | 8 +- examples/turtle_benzene.py | 1 + examples/turtle_bgpic_changeturtle.py | 1 + examples/turtle_circle.py | 1 + examples/turtle_circle_hex.py | 1 + examples/turtle_dots.py | 1 + examples/turtle_hilbert.py | 3 +- examples/turtle_koch.py | 3 +- examples/turtle_manual_hex.py | 1 + examples/turtle_overlayed_koch.py | 5 +- examples/turtle_sierpinski.py | 1 + examples/turtle_simpletest.py | 1 + examples/turtle_square.py | 1 + examples/turtle_star.py | 1 + examples/turtle_swirl.py | 3 +- ruff.toml | 111 +++++++ 22 files changed, 172 insertions(+), 485 deletions(-) create mode 100644 .gitattributes delete mode 100644 .pylintrc create mode 100644 ruff.toml diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..21c125c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,11 @@ +# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +.py text eol=lf +.rst text eol=lf +.txt text eol=lf +.yaml text eol=lf +.toml text eol=lf +.license text eol=lf +.md text eol=lf diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 70ade69..ff19dde 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,42 +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: 23.3.0 - hooks: - - id: black - - repo: https://github.com/fsfe/reuse-tool - rev: v1.1.2 - hooks: - - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - - repo: https://github.com/pycqa/pylint - rev: v2.17.4 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.4 hooks: - - id: pylint - name: pylint (library code) - types: [python] - args: - - --disable=consider-using-f-string - exclude: "^(docs/|examples/|tests/|setup.py$)" - - id: pylint - name: pylint (example code) - description: Run pylint rules on "examples/*.py" files - types: [python] - files: "^examples/" - args: - - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code - - id: pylint - name: pylint (test code) - description: Run pylint rules on "tests/*.py" files - types: [python] - files: "^tests/" - args: - - --disable=missing-docstring,consider-using-f-string,duplicate-code + - id: ruff-format + - id: ruff + args: ["--fix"] + - repo: https://github.com/fsfe/reuse-tool + rev: v3.0.1 + hooks: + - id: reuse diff --git a/.pylintrc b/.pylintrc deleted file mode 100644 index f945e92..0000000 --- a/.pylintrc +++ /dev/null @@ -1,399 +0,0 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -# -# SPDX-License-Identifier: Unlicense - -[MASTER] - -# A comma-separated list of package or module names from where C extensions may -# be loaded. Extensions are loading into the active Python interpreter and may -# run arbitrary code -extension-pkg-whitelist= - -# Add files or directories to the ignore-list. They should be base names, not -# paths. -ignore=CVS - -# Add files or directories matching the regex patterns to the ignore-list. The -# regex matches against base names, not paths. -ignore-patterns= - -# Python code to execute, usually for sys.path manipulation such as -# pygtk.require(). -#init-hook= - -# Use multiple processes to speed up Pylint. -jobs=1 - -# List of plugins (as comma separated values of python modules names) to load, -# usually to register additional checkers. -load-plugins=pylint.extensions.no_self_use - -# Pickle collected data for later comparisons. -persistent=yes - -# Specify a configuration file. -#rcfile= - -# Allow loading of arbitrary C extensions. Extensions are imported into the -# active Python interpreter and may run arbitrary code. -unsafe-load-any-extension=no - - -[MESSAGES CONTROL] - -# Only show warnings with the listed confidence levels. Leave empty to show -# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED -confidence= - -# Disable the message, report, category or checker with the given id(s). You -# can either give multiple identifiers separated by comma (,) or put this -# option multiple times (only on the command line, not in the configuration -# file where it should appear only once).You can also use "--disable=all" to -# disable everything first and then reenable specific checks. For example, if -# you want to run only the similarities checker, you can use "--disable=all -# --enable=similarities". If you want to run only the classes checker, but have -# no Warning level messages displayed, use"--disable=all --enable=classes -# --disable=W" -# disable=import-error,raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,deprecated-str-translate-call -disable=raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,import-error,pointless-string-statement,unspecified-encoding - -# Enable the message, report, category or checker with the given id(s). You can -# either give multiple identifier separated by comma (,) or put this option -# multiple time (only on the command line, not in the configuration file where -# it should appear only once). See also the "--disable" option for examples. -enable= - - -[REPORTS] - -# Python expression which should return a note less than 10 (10 is the highest -# note). You have access to the variables errors warning, statement which -# respectively contain the number of errors / warnings messages and the total -# number of statements analyzed. This is used by the global evaluation report -# (RP0004). -evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) - -# Template used to display messages. This is a python new-style format string -# used to format the message information. See doc for all details -#msg-template= - -# Set the output format. Available formats are text, parseable, colorized, json -# and msvs (visual studio).You can also give a reporter class, eg -# mypackage.mymodule.MyReporterClass. -output-format=text - -# Tells whether to display a full report or only the messages -reports=no - -# Activate the evaluation score. -score=yes - - -[REFACTORING] - -# Maximum number of nested blocks for function / method body -max-nested-blocks=5 - - -[LOGGING] - -# Logging modules to check that the string format arguments are in logging -# function parameter format -logging-modules=logging - - -[SPELLING] - -# Spelling dictionary name. Available dictionaries: none. To make it working -# install python-enchant package. -spelling-dict= - -# List of comma separated words that should not be checked. -spelling-ignore-words= - -# A path to a file that contains private dictionary; one word per line. -spelling-private-dict-file= - -# Tells whether to store unknown words to indicated private dictionary in -# --spelling-private-dict-file option instead of raising a message. -spelling-store-unknown-words=no - - -[MISCELLANEOUS] - -# List of note tags to take in consideration, separated by a comma. -# notes=FIXME,XXX,TODO -notes=FIXME,XXX - - -[TYPECHECK] - -# List of decorators that produce context managers, such as -# contextlib.contextmanager. Add to this list to register other decorators that -# produce valid context managers. -contextmanager-decorators=contextlib.contextmanager - -# List of members which are set dynamically and missed by pylint inference -# system, and so shouldn't trigger E1101 when accessed. Python regular -# expressions are accepted. -generated-members= - -# Tells whether missing members accessed in mixin class should be ignored. A -# mixin class is detected if its name ends with "mixin" (case insensitive). -ignore-mixin-members=yes - -# This flag controls whether pylint should warn about no-member and similar -# checks whenever an opaque object is returned when inferring. The inference -# can return multiple potential results while evaluating a Python object, but -# some branches might not be evaluated, which results in partial inference. In -# that case, it might be useful to still emit no-member and other checks for -# the rest of the inferred objects. -ignore-on-opaque-inference=yes - -# List of class names for which member attributes should not be checked (useful -# for classes with dynamically set attributes). This supports the use of -# qualified names. -ignored-classes=optparse.Values,thread._local,_thread._local - -# List of module names for which member attributes should not be checked -# (useful for modules/projects where namespaces are manipulated during runtime -# and thus existing member attributes cannot be deduced by static analysis. It -# supports qualified module names, as well as Unix pattern matching. -ignored-modules=board - -# Show a hint with possible names when a member name was not found. The aspect -# of finding the hint is based on edit distance. -missing-member-hint=yes - -# The minimum edit distance a name should have in order to be considered a -# similar match for a missing member name. -missing-member-hint-distance=1 - -# The total number of similar names that should be taken in consideration when -# showing a hint for a missing member. -missing-member-max-choices=1 - - -[VARIABLES] - -# List of additional names supposed to be defined in builtins. Remember that -# you should avoid to define new builtins when possible. -additional-builtins= - -# Tells whether unused global variables should be treated as a violation. -allow-global-unused-variables=yes - -# List of strings which can identify a callback function by name. A callback -# name must start or end with one of those strings. -callbacks=cb_,_cb - -# A regular expression matching the name of dummy variables (i.e. expectedly -# not used). -dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ - -# Argument names that match this expression will be ignored. Default to name -# with leading underscore -ignored-argument-names=_.*|^ignored_|^unused_ - -# Tells whether we should check for unused import in __init__ files. -init-import=no - -# List of qualified module names which can have objects that can redefine -# builtins. -redefining-builtins-modules=six.moves,future.builtins - - -[FORMAT] - -# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. -# expected-line-ending-format= -expected-line-ending-format=LF - -# Regexp for a line that is allowed to be longer than the limit. -ignore-long-lines=^\s*(# )??$ - -# Number of spaces of indent required inside a hanging or continued line. -indent-after-paren=4 - -# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 -# tab). -indent-string=' ' - -# Maximum number of characters on a single line. -max-line-length=100 - -# Maximum number of lines in a module -max-module-lines=1000 - -# Allow the body of a class to be on the same line as the declaration if body -# contains single statement. -single-line-class-stmt=no - -# Allow the body of an if to be on the same line as the test if there is no -# else. -single-line-if-stmt=no - - -[SIMILARITIES] - -# Ignore comments when computing similarities. -ignore-comments=yes - -# Ignore docstrings when computing similarities. -ignore-docstrings=yes - -# Ignore imports when computing similarities. -ignore-imports=yes - -# Minimum lines number of a similarity. -min-similarity-lines=12 - - -[BASIC] - -# Regular expression matching correct argument names -argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Regular expression matching correct attribute names -attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Bad variable names which should always be refused, separated by a comma -bad-names=foo,bar,baz,toto,tutu,tata - -# Regular expression matching correct class attribute names -class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ - -# Regular expression matching correct class names -# class-rgx=[A-Z_][a-zA-Z0-9]+$ -class-rgx=[A-Z_][a-zA-Z0-9_]+$ - -# Regular expression matching correct constant names -const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ - -# Minimum line length for functions/classes that require docstrings, shorter -# ones are exempt. -docstring-min-length=-1 - -# Regular expression matching correct function names -function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Good variable names which should always be accepted, separated by a comma -# good-names=i,j,k,ex,Run,_ -good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_ - -# Include a hint for the correct naming format with invalid-name -include-naming-hint=no - -# Regular expression matching correct inline iteration names -inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ - -# Regular expression matching correct method names -method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Regular expression matching correct module names -module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ - -# Colon-delimited sets of names that determine each other's naming style when -# the name regexes allow several styles. -name-group= - -# Regular expression which should only match function or class names that do -# not require a docstring. -no-docstring-rgx=^_ - -# List of decorators that produce properties, such as abc.abstractproperty. Add -# to this list to register other decorators that produce valid properties. -property-classes=abc.abstractproperty - -# Regular expression matching correct variable names -variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - - -[IMPORTS] - -# Allow wildcard imports from modules that define __all__. -allow-wildcard-with-all=no - -# Analyse import fallback blocks. This can be used to support both Python 2 and -# 3 compatible code, which means that the block might have code that exists -# only in one or another interpreter, leading to false positives when analysed. -analyse-fallback-blocks=no - -# Deprecated modules which should not be used, separated by a comma -deprecated-modules=optparse,tkinter.tix - -# Create a graph of external dependencies in the given file (report RP0402 must -# not be disabled) -ext-import-graph= - -# Create a graph of every (i.e. internal and external) dependencies in the -# given file (report RP0402 must not be disabled) -import-graph= - -# Create a graph of internal dependencies in the given file (report RP0402 must -# not be disabled) -int-import-graph= - -# Force import order to recognize a module as part of the standard -# compatibility libraries. -known-standard-library= - -# Force import order to recognize a module as part of a third party library. -known-third-party=enchant - - -[CLASSES] - -# List of method names used to declare (i.e. assign) instance attributes. -defining-attr-methods=__init__,__new__,setUp - -# List of member names, which should be excluded from the protected access -# warning. -exclude-protected=_asdict,_fields,_replace,_source,_make - -# List of valid names for the first argument in a class method. -valid-classmethod-first-arg=cls - -# List of valid names for the first argument in a metaclass class method. -valid-metaclass-classmethod-first-arg=mcs - - -[DESIGN] - -# Maximum number of arguments for function / method -max-args=5 - -# Maximum number of attributes for a class (see R0902). -# max-attributes=7 -max-attributes=11 - -# Maximum number of boolean expressions in a if statement -max-bool-expr=5 - -# Maximum number of branch for function / method body -max-branches=12 - -# Maximum number of locals for function / method body -max-locals=15 - -# Maximum number of parents for a class (see R0901). -max-parents=7 - -# Maximum number of public methods for a class (see R0904). -max-public-methods=20 - -# Maximum number of return / yield for function / method body -max-returns=6 - -# Maximum number of statements in function / method body -max-statements=50 - -# Minimum number of public methods for a class (see R0903). -min-public-methods=1 - - -[EXCEPTIONS] - -# Exceptions that will emit a warning when being caught. Defaults to -# "Exception" -overgeneral-exceptions=builtins.Exception diff --git a/README.rst b/README.rst index 3ff3f72..b61954f 100644 --- a/README.rst +++ b/README.rst @@ -13,9 +13,9 @@ Introduction :target: https://github.com/adafruit/Adafruit_CircuitPython_turtle/actions/ :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 Turtle graphics library for CircuitPython and displayio diff --git a/adafruit_turtle.py b/adafruit_turtle.py index 1df457a..2288978 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -23,14 +23,15 @@ * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice """ + from __future__ import annotations # pylint:disable=too-many-public-methods, too-many-instance-attributes, invalid-name # pylint:disable=too-few-public-methods, too-many-lines, too-many-arguments - import gc import math import time + import displayio try: @@ -205,28 +206,22 @@ def __getnewargs__(self) -> Tuple[float, float]: return (self[0], self[1]) def __repr__(self) -> str: - return "({:.2f},{:.2f})".format(self[0], self[1]) + return f"({self[0]:.2f},{self[1]:.2f})" class turtle: """A Turtle that can be given commands to draw.""" - # pylint:disable=too-many-statements - def __init__( - self, display: Optional[displayio.Display] = None, scale: float = 1 - ) -> None: + def __init__(self, display: Optional[displayio.Display] = None, scale: float = 1) -> None: if display: self._display = display else: try: - # pylint: disable=import-outside-toplevel import board self._display = board.DISPLAY except AttributeError as err: - raise RuntimeError( - "No display available. One must be provided." - ) from err + raise RuntimeError("No display available. One must be provided.") from err self._w: int = self._display.width self._h: int = self._display.height @@ -327,21 +322,12 @@ def _drawturtle(self) -> None: if self._turtle_pic is None: self._turtle_sprite.x = int(self._turtle_x - 4) self._turtle_sprite.y = int(self._turtle_y - 4) + elif self._turtle_odb is not None: + self._turtle_alt_sprite.x = int(self._turtle_x - self._turtle_odb.width // 2) + self._turtle_alt_sprite.y = int(self._turtle_y - self._turtle_odb.height // 2) else: - if self._turtle_odb is not None: - self._turtle_alt_sprite.x = int( - self._turtle_x - self._turtle_odb.width // 2 - ) - self._turtle_alt_sprite.y = int( - self._turtle_y - self._turtle_odb.height // 2 - ) - else: - self._turtle_alt_sprite.x = int( - self._turtle_x - self._turtle_pic[0] // 2 - ) - self._turtle_alt_sprite.y = int( - self._turtle_y - self._turtle_pic[1] // 2 - ) + self._turtle_alt_sprite.x = int(self._turtle_x - self._turtle_pic[0] // 2) + self._turtle_alt_sprite.y = int(self._turtle_y - self._turtle_pic[1] // 2) ########################################################################### # Move and draw @@ -352,9 +338,7 @@ def forward(self, distance: float) -> None: :param distance: how far to move (integer or float) """ p = self.pos() - angle = ( - self._angleOffset + self._angleOrient * self._heading - ) % self._fullcircle + angle = (self._angleOffset + self._angleOrient * self._heading) % self._fullcircle x1 = p[0] + math.sin(math.radians(angle)) * distance y1 = p[1] + math.cos(math.radians(angle)) * distance self.goto(x1, y1) @@ -545,9 +529,7 @@ def _plot(self, x: float, y: float, c: int) -> None: except IndexError: pass r = self._pensize // 2 + 1 - angle = ( - self._angleOffset + self._angleOrient * self._heading - 90 - ) % self._fullcircle + angle = (self._angleOffset + self._angleOrient * self._heading - 90) % self._fullcircle sin = math.sin(math.radians(angle)) cos = math.cos(math.radians(angle)) x0 = x + sin * r @@ -826,7 +808,7 @@ def clearstamps(self, n: Optional[int] = None) -> None: """ i = 1 - for sid in self._stamps: # pylint: disable=consider-using-dict-items + for sid in self._stamps: if self._stamps[sid] is not None: self.clearstamp(sid) if n is not None and i >= n: @@ -1230,9 +1212,7 @@ def changeturtle( self._turtle_group.append(self._turtle_alt_sprite) self._drawturtle() else: - raise TypeError( - 'Argument must be "str", a "displayio.TileGrid" or nothing.' - ) + raise TypeError('Argument must be "str", a "displayio.TileGrid" or nothing.') # pylint:enable=too-many-statements, too-many-branches @@ -1247,9 +1227,7 @@ def _turn(self, angle: float) -> None: self._heading %= self._fullcircle # wrap return start_angle = self._heading - steps = math.ceil( - (self._pensize * 2) * 3.1415 * (abs(angle) / self._fullcircle) - ) + steps = math.ceil((self._pensize * 2) * 3.1415 * (abs(angle) / self._fullcircle)) if steps < 1: d_angle = angle steps = 1 diff --git a/docs/api.rst b/docs/api.rst index db048c0..31d0e34 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -4,5 +4,8 @@ .. 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:: adafruit_turtle :members: diff --git a/docs/conf.py b/docs/conf.py index e4137e6..f4402aa 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,12 +1,10 @@ -# -*- coding: utf-8 -*- - # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # # SPDX-License-Identifier: MIT +import datetime import os import sys -import datetime sys.path.insert(0, os.path.abspath("..")) @@ -70,9 +68,7 @@ creation_year = "2019" current_year = str(datetime.datetime.now().year) year_duration = ( - current_year - if current_year == creation_year - else creation_year + " - " + current_year + current_year if current_year == creation_year else creation_year + " - " + current_year ) copyright = year_duration + " Adafruit" author = "Adafruit" diff --git a/examples/turtle_benzene.py b/examples/turtle_benzene.py index 5c1eb91..d9c470e 100644 --- a/examples/turtle_benzene.py +++ b/examples/turtle_benzene.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: MIT import board + from adafruit_turtle import Color, turtle turtle = turtle(board.DISPLAY) diff --git a/examples/turtle_bgpic_changeturtle.py b/examples/turtle_bgpic_changeturtle.py index e461854..e2b0d91 100644 --- a/examples/turtle_bgpic_changeturtle.py +++ b/examples/turtle_bgpic_changeturtle.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: MIT import board + from adafruit_turtle import Color, turtle turtle = turtle(board.DISPLAY) diff --git a/examples/turtle_circle.py b/examples/turtle_circle.py index 51c111e..d4ca9aa 100644 --- a/examples/turtle_circle.py +++ b/examples/turtle_circle.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: MIT import board + from adafruit_turtle import Color, turtle turtle = turtle(board.DISPLAY) diff --git a/examples/turtle_circle_hex.py b/examples/turtle_circle_hex.py index 5f02a4a..af4f0b5 100644 --- a/examples/turtle_circle_hex.py +++ b/examples/turtle_circle_hex.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: MIT import board + from adafruit_turtle import turtle turtle = turtle(board.DISPLAY) diff --git a/examples/turtle_dots.py b/examples/turtle_dots.py index 3baa449..9297ad8 100644 --- a/examples/turtle_dots.py +++ b/examples/turtle_dots.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: MIT import board + from adafruit_turtle import turtle print("Turtle time! Lets draw a square with dots") diff --git a/examples/turtle_hilbert.py b/examples/turtle_hilbert.py index 6413d3a..8427712 100644 --- a/examples/turtle_hilbert.py +++ b/examples/turtle_hilbert.py @@ -1,9 +1,8 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT -# pylint: disable=unnecessary-lambda-assignment - import board + from adafruit_turtle import turtle diff --git a/examples/turtle_koch.py b/examples/turtle_koch.py index f04c919..1e5b681 100644 --- a/examples/turtle_koch.py +++ b/examples/turtle_koch.py @@ -1,9 +1,8 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT -# pylint: disable=unnecessary-lambda-assignment - import board + from adafruit_turtle import turtle diff --git a/examples/turtle_manual_hex.py b/examples/turtle_manual_hex.py index 11e54a4..d407a6c 100644 --- a/examples/turtle_manual_hex.py +++ b/examples/turtle_manual_hex.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: MIT import board + from adafruit_turtle import turtle turtle = turtle(board.DISPLAY) diff --git a/examples/turtle_overlayed_koch.py b/examples/turtle_overlayed_koch.py index 0bfe018..662ae92 100644 --- a/examples/turtle_overlayed_koch.py +++ b/examples/turtle_overlayed_koch.py @@ -1,10 +1,9 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT -# pylint: disable=unnecessary-lambda-assignment - import board -from adafruit_turtle import turtle, Color + +from adafruit_turtle import Color, turtle generation_colors = [Color.RED, Color.BLUE, Color.GREEN, Color.YELLOW] diff --git a/examples/turtle_sierpinski.py b/examples/turtle_sierpinski.py index 5c63ea5..c01f039 100644 --- a/examples/turtle_sierpinski.py +++ b/examples/turtle_sierpinski.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: MIT import board + from adafruit_turtle import turtle diff --git a/examples/turtle_simpletest.py b/examples/turtle_simpletest.py index 7a0c68e..6f1681a 100644 --- a/examples/turtle_simpletest.py +++ b/examples/turtle_simpletest.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: MIT import board + from adafruit_turtle import Color, turtle turtle = turtle(board.DISPLAY) diff --git a/examples/turtle_square.py b/examples/turtle_square.py index 6d9486f..0a3aaaf 100644 --- a/examples/turtle_square.py +++ b/examples/turtle_square.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: MIT import board + from adafruit_turtle import Color, turtle turtle = turtle(board.DISPLAY) diff --git a/examples/turtle_star.py b/examples/turtle_star.py index 7a0c68e..6f1681a 100644 --- a/examples/turtle_star.py +++ b/examples/turtle_star.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: MIT import board + from adafruit_turtle import Color, turtle turtle = turtle(board.DISPLAY) diff --git a/examples/turtle_swirl.py b/examples/turtle_swirl.py index fab441e..62ca218 100644 --- a/examples/turtle_swirl.py +++ b/examples/turtle_swirl.py @@ -2,7 +2,8 @@ # SPDX-License-Identifier: MIT import board -from adafruit_turtle import turtle, Color + +from adafruit_turtle import Color, turtle turtle = turtle(board.DISPLAY) diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..f732478 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,111 @@ +# 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 + "PLR0913", # too-many-arguments + "PLR0915", # too-many-statements + "PLR0917", # too-many-positional-arguments + "PLR0904", # too-many-public-methods + "PLR0912", # too-many-branches + "PLR0916", # too-many-boolean-expressions + "PLR6301", # could-be-static no-self-use + "PLC0415", # import outside toplevel + "PLC2701", # private import + "UP007", # x | y typing + "UP006", # builtin instead of typing import + "PLR0914", # too many locals +] + +[format] +line-ending = "lf" From 3446470fa1687dedea1c0f68cd4659396937c22e Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 27 May 2025 16:28:36 -0500 Subject: [PATCH 47/47] displayio API update --- adafruit_turtle.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/adafruit_turtle.py b/adafruit_turtle.py index 2288978..4022ed9 100644 --- a/adafruit_turtle.py +++ b/adafruit_turtle.py @@ -36,6 +36,8 @@ try: from typing import List, Optional, Tuple, Union + + import busdisplay except ImportError: pass @@ -212,7 +214,7 @@ def __repr__(self) -> str: class turtle: """A Turtle that can be given commands to draw.""" - def __init__(self, display: Optional[displayio.Display] = None, scale: float = 1) -> None: + def __init__(self, display: Optional[busdisplay.BusDisplay] = None, scale: float = 1) -> None: if display: self._display = display else: