From c1b294cf1cfc7248c79845664785546833a25ada Mon Sep 17 00:00:00 2001 From: Aarno Aukia Date: Sat, 8 Jun 2024 12:19:45 +0200 Subject: [PATCH] upgrade build to pyproject.toml and packaging.python.org GH actions --- .github/workflows/main.yml | 130 +++++++++++++++++++++++++++++++------ pyproject.toml | 35 +++++++++- setup.py | 41 +----------- 3 files changed, 146 insertions(+), 60 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b794135..9b32df3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,27 +27,117 @@ jobs: CODECOV_TOKEN: "889b90e8-e5a8-4139-aef6-87e6f2e1a0a4" run: tox - package: - name: "Build & verify package" - runs-on: "ubuntu-latest" + # from https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ + build: + name: Build distribution + runs-on: ubuntu-latest needs: [test] - environment: release + + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + - name: Install pypa/build + run: >- + python3 -m + pip install + build + --user + - name: Build a binary wheel and a source tarball + run: python3 -m build + - name: Store the distribution packages + uses: actions/upload-artifact@v3 + with: + name: python-package-distributions + path: dist/ + + publish-to-pypi: + name: >- + Publish Python distribution to PyPI + if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes + needs: + - build + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/controlmyspa permissions: - id-token: write + id-token: write # IMPORTANT: mandatory for trusted publishing + steps: - - uses: "actions/checkout@v4" - - uses: "actions/setup-python@v5" - with: - python-version: "3.11" - - - name: "Install pep517 and twine" - run: "python -m pip install pep517 twine" - - name: "Build package" - run: "python -m pep517.build --source --binary ." - - name: "List result" - run: "ls -l dist" - - name: "Check long_description" - run: "python -m twine check dist/*" - - name: Publish package - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + - name: Download all the dists + uses: actions/download-artifact@v3 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution to PyPI uses: pypa/gh-action-pypi-publish@release/v1 + + github-release: + name: >- + Sign the Python distribution with Sigstore + and upload them to GitHub Release + needs: + - publish-to-pypi + runs-on: ubuntu-latest + + permissions: + contents: write # IMPORTANT: mandatory for making GitHub Releases + id-token: write # IMPORTANT: mandatory for sigstore + + steps: + - name: Download all the dists + uses: actions/download-artifact@v3 + with: + name: python-package-distributions + path: dist/ + - name: Sign the dists with Sigstore + uses: sigstore/gh-action-sigstore-python@v2.1.1 + with: + inputs: >- + ./dist/*.tar.gz + ./dist/*.whl + - name: Create GitHub Release + env: + GITHUB_TOKEN: ${{ github.token }} + run: >- + gh release create + '${{ github.ref_name }}' + --repo '${{ github.repository }}' + --notes "" + - name: Upload artifact signatures to GitHub Release + env: + GITHUB_TOKEN: ${{ github.token }} + # Upload to GitHub Release using the `gh` CLI. + # `dist/` contains the built packages, and the + # sigstore-produced signatures and certificates. + run: >- + gh release upload + '${{ github.ref_name }}' dist/** + --repo '${{ github.repository }}' + + publish-to-testpypi: + name: Publish Python distribution to TestPyPI + needs: + - build + runs-on: ubuntu-latest + + environment: + name: testpypi + url: https://test.pypi.org/p/controlmyspa + + permissions: + id-token: write # IMPORTANT: mandatory for trusted publishing + + steps: + - name: Download all the dists + uses: actions/download-artifact@v3 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution to TestPyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ diff --git a/pyproject.toml b/pyproject.toml index 121a39f..e6df64e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,36 @@ [build-system] -requires = ["setuptools >= 40.6.0", "wheel"] +requires = ["setuptools>=64", "setuptools_scm>=8"] build-backend = "setuptools.build_meta" + +[tool.setuptools] +packages = ["controlmyspa"] + +[tool.setuptools.package-dir] +controlmyspa = "." + +[tool.setuptools_scm] + +[project] +name = "controlmyspa" +dynamic = ["version"] +authors = [ + { name="Aarno Aukia", email="aarno@aukia.com" }, +] +description = "Balboa ControlMySpaâ„¢ cloud API for hot tub spa systems" +readme = "README.md" +requires-python = ">=3.10" +license={text = "MIT"} +keywords=["Balboa", "Controlmyspa", "Whirlpool", "API"] +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Intended Audience :: Developers", +] +dependencies = [ + "requests>2" +] + +[project.urls] +Homepage = "https://github.com/arska/controlmyspa" +Issues = "https://github.com/arska/controlmyspa/issues" diff --git a/setup.py b/setup.py index 6716868..b908cbe 100644 --- a/setup.py +++ b/setup.py @@ -1,40 +1,3 @@ -""" -controlmyspa python module manifest -""" -from os.path import abspath, dirname, join -from setuptools import setup +import setuptools - -def read_file(filename): - """Get the contents of a file""" - here = abspath(dirname(__file__)) - with open(join(here, filename), encoding="utf-8") as file: - return file.read() - - -setup( - name="controlmyspa", - version_config={"dirty_template": "{tag}"}, - description="Get metrics and control Balboa Controlmyspa whirlpool", - long_description=read_file("README.md"), - long_description_content_type="text/markdown", - packages=["controlmyspa"], - package_dir={"controlmyspa": "."}, - keywords=["Balboa", "Controlmyspa", "Whirlpool", "API"], - classifiers=[ - "Intended Audience :: Developers", - "License :: OSI Approved :: MIT License", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - ], - url="https://github.com/arska/controlmyspa", - author="Aarno Aukia", - author_email="aarno@aukia.com", - license="MIT", - python_requires=">=3.6", - extras_require={"dev": ["tox"]}, - install_requires=["requests>=2"], - setup_requires=["setuptools-git-versioning"], -) +setuptools.setup()