From 763ef5c31859af8bb42140da465909f61723f696 Mon Sep 17 00:00:00 2001 From: Joe Heffer Date: Fri, 8 Mar 2024 14:42:08 +0000 Subject: [PATCH 01/12] docs: add link to dynamic version page --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 52263ab..fe74701 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,6 +14,7 @@ build-backend = "setuptools.build_meta" name = "beelabel" description = "3D flight path inference using bee tracking images with retroreflection detection methods." readme = "README.md" +# https://packaging.python.org/en/latest/guides/single-sourcing-package-version/ dynamic = ["version"] requires-python = ">= 3.8" dependencies = [ From 053e1ec6cdf55d0ff78ea90912e682b84f9ac333 Mon Sep 17 00:00:00 2001 From: Joe Heffer Date: Fri, 8 Mar 2024 14:42:57 +0000 Subject: [PATCH 02/12] feature: Add deployment to test pypi --- .github/workflows/python-package.yml | 98 +++++++++++++++++++++------- 1 file changed, 74 insertions(+), 24 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index abfed55..5c0f0a9 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -1,3 +1,4 @@ +# This is a GitHub Actions workflow that builds the package and publishes it to the PyPI, the Python Package Index. # This workflow will install Python dependencies, run tests and lint with a variety of Python versions # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python @@ -7,37 +8,86 @@ # Publishing package distribution releases using GitHub Actions CI/CD workflows # https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ -name: Python package +# See:"Building and Publishing" on the Python Packaging User Guide +# https://packaging.python.org/en/latest/guides/section-build-and-publish/ -on: [push, pull_request] +# This workflow was designed based on this guide: +# Publishing package distribution releases using GitHub Actions CI/CD workflows +# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ +# It runs whenever we publish a new release. +# https://docs.github.com/en/repositories/releasing-projects-on-github +on: push +name: Python package jobs: - build: + test: # https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners - runs-on: ["ubuntu-22.04"] + runs-on: ubuntu-22.04 strategy: fail-fast: true matrix: # https://devguide.python.org/versions/ - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: [ "3.9", "3.10", "3.11", "3.12" ] + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + # Install package in editable mode with extra testing dependencies + pip install -e .[test] + - name: Lint with flake8 + 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 + - name: Test with pytest + run: | + pytest + + build: + name: Build distribution + runs-on: ubuntu-2022 + needs: test + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + - name: Install build + run: >- + python3 -m pip install --upgrade pip + 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@v4 + with: + name: python-package-distributions + path: dist/ + publish-to-test-pypi: + name: Publish Python distribution to test PyPI + needs: + - build + runs-on: ubuntu-2022 + environment: + name: testpypi + url: https://test.pypi.org/project/beelabel/ + permissions: + # IMPORTANT: mandatory for trusted publishing + id-token: write steps: - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - # Install package in editable mode with extra testing dependencies - pip install -e .[test] - - name: Lint with flake8 - 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 - - name: Test with pytest - run: | - pytest + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 From aa3e753ad0f8e67d24f7bc1c0e0276fa1f5fcf61 Mon Sep 17 00:00:00 2001 From: Joe Heffer Date: Fri, 8 Mar 2024 14:45:16 +0000 Subject: [PATCH 03/12] fix: ubuntu runner name --- .github/workflows/python-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 5c0f0a9..d613aef 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -52,7 +52,7 @@ jobs: build: name: Build distribution - runs-on: ubuntu-2022 + runs-on: ubuntu-22.04 needs: test steps: - uses: actions/checkout@v4 @@ -76,7 +76,7 @@ jobs: name: Publish Python distribution to test PyPI needs: - build - runs-on: ubuntu-2022 + runs-on: ubuntu-22.04 environment: name: testpypi url: https://test.pypi.org/project/beelabel/ From 616757a0570b3d2c01862a571536bb4b53e76a45 Mon Sep 17 00:00:00 2001 From: Joe Heffer Date: Fri, 8 Mar 2024 14:48:04 +0000 Subject: [PATCH 04/12] fix: correct interpreter name --- .github/workflows/python-package.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index d613aef..b6b029e 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -62,10 +62,10 @@ jobs: python-version: "3.12" - name: Install build run: >- - python3 -m pip install --upgrade pip - python3 -m pip install build --user + python -m pip install --upgrade pip + python -m pip install build --user - name: Build a binary wheel and a source tarball - run: python3 -m build + run: python -m build - name: Store the distribution packages uses: actions/upload-artifact@v4 with: From e633c7c73c3468e2dcde41f4487e35c6858d85af Mon Sep 17 00:00:00 2001 From: Joe Heffer Date: Fri, 8 Mar 2024 14:51:06 +0000 Subject: [PATCH 05/12] fix: command syntax --- .github/workflows/python-package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index b6b029e..ef569aa 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -61,7 +61,7 @@ jobs: with: python-version: "3.12" - name: Install build - run: >- + run: | python -m pip install --upgrade pip python -m pip install build --user - name: Build a binary wheel and a source tarball From c75e81b4e3021eed3a889d60b45bae365ddb84f3 Mon Sep 17 00:00:00 2001 From: Joe Heffer Date: Fri, 8 Mar 2024 14:56:32 +0000 Subject: [PATCH 06/12] fix: env name --- .github/workflows/python-package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index ef569aa..e8af76e 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -78,7 +78,7 @@ jobs: - build runs-on: ubuntu-22.04 environment: - name: testpypi + name: development url: https://test.pypi.org/project/beelabel/ permissions: # IMPORTANT: mandatory for trusted publishing From 01f5b18bcb0c3a2dd928b66cf4f2417ee9e306d5 Mon Sep 17 00:00:00 2001 From: Joe Heffer Date: Fri, 8 Mar 2024 15:17:32 +0000 Subject: [PATCH 07/12] fix: environment name --- .github/workflows/python-package.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index e8af76e..d47fe86 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -5,18 +5,13 @@ # Workflow syntax for GitHub Actions # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions +# This workflow was designed based on this guide: # Publishing package distribution releases using GitHub Actions CI/CD workflows # https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ # See:"Building and Publishing" on the Python Packaging User Guide # https://packaging.python.org/en/latest/guides/section-build-and-publish/ -# This workflow was designed based on this guide: -# Publishing package distribution releases using GitHub Actions CI/CD workflows -# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ - -# It runs whenever we publish a new release. -# https://docs.github.com/en/repositories/releasing-projects-on-github on: push name: Python package jobs: @@ -50,6 +45,9 @@ jobs: run: | pytest + # It runs whenever we publish a new release. + # https://docs.github.com/en/repositories/releasing-projects-on-github + build: name: Build distribution runs-on: ubuntu-22.04 @@ -72,13 +70,16 @@ jobs: name: python-package-distributions path: dist/ + # OpenID Connect token that the pypi-publish actions needs to implement secretless trusted publishing to PyPI + # https://docs.pypi.org/trusted-publishers/ publish-to-test-pypi: name: Publish Python distribution to test PyPI needs: - build runs-on: ubuntu-22.04 + # https://test.pypi.org/manage/project/beelabel/settings/publishing/ environment: - name: development + name: testpypi url: https://test.pypi.org/project/beelabel/ permissions: # IMPORTANT: mandatory for trusted publishing From dc28427b7697973c7210d809bee9b7a384445c28 Mon Sep 17 00:00:00 2001 From: Joe Heffer Date: Fri, 8 Mar 2024 15:26:10 +0000 Subject: [PATCH 08/12] fix: set repository-url --- .github/workflows/python-package.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index d47fe86..8bd7d0f 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -80,7 +80,7 @@ jobs: # https://test.pypi.org/manage/project/beelabel/settings/publishing/ environment: name: testpypi - url: https://test.pypi.org/project/beelabel/ + url: https://test.pypi.org/p/beelabel/ permissions: # IMPORTANT: mandatory for trusted publishing id-token: write @@ -90,5 +90,8 @@ jobs: with: name: python-package-distributions path: dist/ + # https://github.com/marketplace/actions/pypi-publish - name: Publish distribution to PyPI uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ From 5cd7f05926549f2fa6fd388df5f685ce8414be20 Mon Sep 17 00:00:00 2001 From: Joe Heffer Date: Fri, 8 Mar 2024 15:31:40 +0000 Subject: [PATCH 09/12] feature: Set version dynamically --- pyproject.toml | 3 +++ src/beelabel/__init__.py | 1 + 2 files changed, 4 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index fe74701..0e7dc10 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,6 +46,9 @@ classifiers = [ "Programming Language :: Python :: 3.13", ] +[tool.setuptools.dynamic] +version = {attr = "beelabel.__version__"} + # https://peps.python.org/pep-0631/ [project.optional-dependencies] test = [ diff --git a/src/beelabel/__init__.py b/src/beelabel/__init__.py index e69de29..09e698c 100644 --- a/src/beelabel/__init__.py +++ b/src/beelabel/__init__.py @@ -0,0 +1 @@ +__version__ = '0.0.1rc1' From 2f5748f9bdabdacfeecc9c55ee289980e4a8340c Mon Sep 17 00:00:00 2001 From: Joe Heffer Date: Fri, 8 Mar 2024 15:52:33 +0000 Subject: [PATCH 10/12] feature: Publish to PyPI --- .github/workflows/python-package.yml | 15 ++++++++++++++- README.md | 17 +++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 8bd7d0f..83fa5ba 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -73,7 +73,7 @@ jobs: # OpenID Connect token that the pypi-publish actions needs to implement secretless trusted publishing to PyPI # https://docs.pypi.org/trusted-publishers/ publish-to-test-pypi: - name: Publish Python distribution to test PyPI + name: Publish test PyPI needs: - build runs-on: ubuntu-22.04 @@ -95,3 +95,16 @@ jobs: uses: pypa/gh-action-pypi-publish@release/v1 with: repository-url: https://test.pypi.org/legacy/ + + publish-to-pypi: + name: Publish to PyPI + # # only publish to PyPI on tag pushes + if: startsWith(github.ref, 'refs/tags/') + needs: + - publish-to-test-pypi + runs-on: ubuntu-22.04 + environment: + name: pypi + url: https://pypi.org/p/beelabel/ + permissions: + id-token: write diff --git a/README.md b/README.md index d1b07ae..31f0d2a 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,24 @@ # Bee labelling -This repository contains Python code to perform bee 3D flight path inference. This finds a trajectory for a series of retrodetected images. +This repository contains Python code to perform bee 3D flight path inference. This finds a trajectory for a series of retro-detected images. # Installation -TODO +To install this package from the [Python Package Index (PyPI)](https://pypi.org/project/beelabel/), create a virtual environment and [install using `pip`](https://pip.pypa.io/en/stable/cli/pip_install/). + +```bash +# Create a virtual environemnt +python -m venv .venv +# Activate the environment +source .venv/bin/activate +``` + +Then install this package: + +```bash +pip install beelabel +``` # Usage From 9c4cb5ce21560b145ecc30f3e42c6f1e571f6135 Mon Sep 17 00:00:00 2001 From: Joe Heffer Date: Fri, 8 Mar 2024 15:57:33 +0000 Subject: [PATCH 11/12] fix(build): Publish to PyPI - add steps --- .github/workflows/python-package.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 83fa5ba..879901c 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -108,3 +108,12 @@ jobs: url: https://pypi.org/p/beelabel/ permissions: id-token: write + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: python-package-distributions + path: dist/ + # https://github.com/marketplace/actions/pypi-publish + - name: Publish distribution to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 From 1c14fd49184e85ba8cf55898e27cbf4b27c69e79 Mon Sep 17 00:00:00 2001 From: Joe Heffer Date: Fri, 8 Mar 2024 16:03:18 +0000 Subject: [PATCH 12/12] fix(build): Test Pypi - skip existing versions https://test.pypi.org/help/#file-name-reuse --- .github/workflows/python-package.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 879901c..2c56f02 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -95,6 +95,9 @@ jobs: uses: pypa/gh-action-pypi-publish@release/v1 with: repository-url: https://test.pypi.org/legacy/ + # Don't complain on repeat uploads for the same package version + # https://github.com/marketplace/actions/pypi-publish#tolerating-release-package-file-duplicates + skip-existing: true publish-to-pypi: name: Publish to PyPI