From 055788bbef305fd42284b1b40c72a470f339e4dc Mon Sep 17 00:00:00 2001 From: "Dr.-Ing. Amilcar do Carmo Lucas" Date: Tue, 14 Jan 2025 11:53:26 +0100 Subject: [PATCH] IMPROVEMENT: simplify and speedup pypi publishing --- .github/workflows/python-publish.yml | 16 +++++++++--- pyproject.toml | 6 ++--- setup.py | 38 ++++++++++++++++++++++++++++ test_pip_package.sh | 25 +++++++++++++----- 4 files changed, 71 insertions(+), 14 deletions(-) create mode 100755 setup.py diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index e42fe086..796e6f8c 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -22,10 +22,19 @@ jobs: permissions: id-token: write + env: + UV_SYSTEM_PYTHON: 1 + steps: - name: Checkout uses: actions/checkout@v4 + # https://docs.astral.sh/uv/guides/integration/github/ + - name: Install uv and set the python version + uses: astral-sh/setup-uv@v4 + with: + python-version: '3.12' + - name: Set up Python 3.12 uses: actions/setup-python@v5 with: @@ -33,11 +42,10 @@ jobs: - name: Install dependencies run: | - python -m pip install -U pip wheel pymavlink build - pip install -U . + uv pip install build packaging pip setuptools wheel - name: Build package - run: python -m build --wheel + run: python -m build - - name: Publish package distribuitions to PyPI + - name: Publish package distributions to PyPI uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/pyproject.toml b/pyproject.toml index abaaf248..b1657456 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -85,9 +85,9 @@ changelog = "https://github.com/ArduPilot/MethodicConfigurator/releases" [tool.setuptools] packages = ["ardupilot_methodic_configurator"] -package-data = {ardupilot_methodic_configurator = ["*.param", "*.jpg", "*.json", "*.xml", "*.mo", "*.png"]} -exclude-package-data = {ardupilot_methodic_configurator = ["test.xml"]} -include-package-data = true + +[tool.setuptools.package-data] +ardupilot_methodic_configurator = ["*.param", "*.jpg", "*.json", "*.xml", "*.mo", "*.png"] [tool.setuptools.dynamic] version = {attr = "ardupilot_methodic_configurator.__version__"} diff --git a/setup.py b/setup.py new file mode 100755 index 00000000..318613c9 --- /dev/null +++ b/setup.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 + +""" +Creates the ardupilot_methodic_configurator pip python package. + +This file is part of Ardupilot methodic configurator. https://github.com/ArduPilot/MethodicConfigurator + +SPDX-FileCopyrightText: 2024 Amilcar do Carmo Lucas + +SPDX-License-Identifier: GPL-3.0-or-later +""" + +import fnmatch +import os + +from setuptools import setup + + +# recursively find all files that match the globs and return tuples with their directory and a list of relative paths +def find_data_files(globs: list[str]) -> list[tuple[str, list[str]]]: + data_files_path_base = "ardupilot_methodic_configurator" + ret = [] + for dirpath, _dirnames, filenames in os.walk(data_files_path_base): + data_files = [] + for glob in globs: + for filename in fnmatch.filter(filenames, glob): + relative_path = os.path.join(dirpath, filename) + data_files.append(relative_path) + if data_files: + ret.append((os.path.relpath(dirpath, data_files_path_base), data_files)) + return ret + + +setup( + packages=["ardupilot_methodic_configurator"], + # this is used by bdist + data_files=[*find_data_files(["*.param", "*.jpg", "*.json", "*.xml", "*.mo"])], +) diff --git a/test_pip_package.sh b/test_pip_package.sh index d358ac96..77cc49ba 100755 --- a/test_pip_package.sh +++ b/test_pip_package.sh @@ -1,25 +1,36 @@ #!/bin/bash +sudo pip uninstall -y MethodicConfigurator +pip uninstall -y MethodicConfigurator +sudo rm -Rf /usr/local/MethodicConfigurator/ + sudo pip uninstall -y ardupilot_methodic_configurator pip uninstall -y ardupilot_methodic_configurator sudo rm -Rf /usr/local/ardupilot_methodic_configurator/ + sudo rm -Rf /usr/local/vehicle_templates/ sudo rm -Rf /usr/local/locale/ rm -Rf ~/.local/locale rm -Rf ~/.local/vehicle_templates + +rm -Rf ~/.local/MethodicConfigurator +rm -Rf ~/.local/bin/MethodicConfigurator +rm -Rf build dist/ MethodicConfigurator.egg-info/ + rm -Rf ~/.local/ardupilot_methodic_configurator +rm -Rf ~/.local/bin/ardupilot_methodic_configurator rm -Rf build dist/ ardupilot_methodic_configurator.egg-info/ -python -m build --wheel . -# Use either this -sudo pip install -U dist/ardupilot_methodic_configurator-0.9.16-py3-none-any.whl +uv venv --python 3.12 +source .venv/bin/activate +uv pip install -U build packaging pip setuptools wheel -# Or this -#pip install -U dist/ardupilot_methodic_configurator-0.9.16-py3-none-any.whl +python -m build +uv pip install -U dist/ardupilot_methodic_configurator-1.0.8-py3-none-any.whl cd .. -ardupilot_methodic_configurator --language=pt -~/.local/bin/ardupilot_methodic_configurator --language=pt + +ardupilot_methodic_configurator --language=pt --loglevel=DEBUG ls -larct /usr/local