From 7c828f1846362abb01f2364c65020ba12757c72a Mon Sep 17 00:00:00 2001 From: bugobliterator Date: Fri, 28 Feb 2025 17:14:38 +1100 Subject: [PATCH 1/3] .github: fix CI by dropping python 3.7 from the check matrix also add 3.11 and 3.12 to the matrix --- .github/workflows/python-package.yml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index c468df3..6116615 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -16,14 +16,28 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.7, 3.8, 3.9, '3.10'] + python-version: ['3.7', 3.8, 3.9, '3.10', '3.11', '3.12'] steps: - uses: actions/checkout@v2 + + - name: Set up Python 3.7 from deadsnakes + if: matrix.python-version == '3.7' + run: | + sudo add-apt-repository ppa:deadsnakes/ppa + sudo apt-get update + sudo apt-get install -y python3.7 python3.7-dev python3.7-distutils + python3.7 -m venv py37_env --without-pip + source py37_env/bin/activate + curl -sS https://bootstrap.pypa.io/pip/3.7/get-pip.py | python + echo "PATH=$PWD/py37_env/bin:$PATH" >> $GITHUB_ENV + - name: Set up Python ${{ matrix.python-version }} + if: matrix.python-version != '3.7' uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} + - name: Install dependencies run: | python -m pip install --upgrade pip @@ -33,8 +47,8 @@ jobs: run: | # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + # exit-zero treats all errors as warnings + flake8 . --count --exit-zero --statistics - name: Download DSDL Specifications run: | From 8375125b56fd14cb11b4b61bf76e598fe62d849b Mon Sep 17 00:00:00 2001 From: bugobliterator Date: Fri, 28 Feb 2025 17:24:09 +1100 Subject: [PATCH 2/3] dronecan: replace pkg_resources with importlib.resources for latest Python compatibility --- dronecan/__init__.py | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/dronecan/__init__.py b/dronecan/__init__.py index b5ed506..3bed0ee 100644 --- a/dronecan/__init__.py +++ b/dronecan/__init__.py @@ -16,10 +16,35 @@ import os import sys import struct -import pkg_resources import time from logging import getLogger +# Remove deprecated pkg_resources +try: + # Use importlib.resources if available (Python 3.7+) + try: + from importlib import resources as importlib_resources + except ImportError: + # Fall back to importlib_resources backport for Python < 3.7 + import importlib_resources + + def get_resource_path(package, resource): + """Get path to a resource file using importlib.resources""" + try: + # Python 3.9+ + return importlib_resources.files(package).joinpath(resource) + except AttributeError: + # Python 3.7, 3.8 with importlib_resources backport + with importlib_resources.path(package, resource) as path: + return path +except ImportError: + # Last resort fallback to pkg_resources + import pkg_resources + + def get_resource_path(package, resource): + """Get path to a resource file using pkg_resources""" + return pkg_resources.resource_filename(package, resource) + try: # noinspection PyStatementEffect time.monotonic # Works natively in Python 3.3+ @@ -124,15 +149,19 @@ def load_dsdl(*paths, **args): # noinspection PyBroadException try: if not args.get("exclude_dist", None): - dsdl_path = pkg_resources.resource_filename(__name__, "dsdl_specs") # @UndefinedVariable - # check if we are a package, if not directly use relative DSDL path - if not os.path.exists(dsdl_path): + try: + dsdl_path = str(get_resource_path(__name__, "dsdl_specs")) + except (ImportError, FileNotFoundError): + dsdl_path = None + + # Check if we are a package, if not directly use relative DSDL path + if not dsdl_path or not os.path.exists(dsdl_path): DSDL_paths = [ "../../DSDL", "../../../../../DroneCAN/DSDL", "../../../../dsdl"] for p in DSDL_paths: dpath = os.path.join(os.path.dirname(__file__), p) if os.path.exists(dpath): dsdl_path = dpath - logger.debug('Found DSDL at: '.format(dsdl_path)) + logger.debug('Found DSDL at: {}'.format(dsdl_path)) break if not os.path.exists(dsdl_path): raise UAVCANException('failed to find DSDL path') From 45bfe06be38a34ebd8866659e2b3a2043752dc7a Mon Sep 17 00:00:00 2001 From: bugobliterator Date: Tue, 4 Mar 2025 14:02:18 +1100 Subject: [PATCH 3/3] add .flake8 --- .flake8 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..6b21da4 --- /dev/null +++ b/.flake8 @@ -0,0 +1,15 @@ +[flake8] +exclude = + .git, + __pycache__, + build, + dist, + *.egg-info, + venv, + py37_env, + */dsdl_specs/*, + .eggs, + .tox, + docs/conf.py +max-line-length = 127 +max-complexity = 10