diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index abfed55..2c56f02 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -1,43 +1,122 @@ +# 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 # 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/ -name: Python package - -on: [push, pull_request] +# See:"Building and Publishing" on the Python Packaging User Guide +# https://packaging.python.org/en/latest/guides/section-build-and-publish/ +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 + + # 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 + 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: | + python -m pip install --upgrade pip + python -m pip install build --user + - name: Build a binary wheel and a source tarball + run: python -m build + - name: Store the distribution packages + uses: actions/upload-artifact@v4 + with: + 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 test PyPI + needs: + - build + runs-on: ubuntu-22.04 + # https://test.pypi.org/manage/project/beelabel/settings/publishing/ + environment: + name: testpypi + url: https://test.pypi.org/p/beelabel/ + permissions: + # IMPORTANT: mandatory for trusted publishing + 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 + 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 + # # 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 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/ + # https://github.com/marketplace/actions/pypi-publish + - name: Publish distribution to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 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 diff --git a/pyproject.toml b/pyproject.toml index 52263ab..0e7dc10 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 = [ @@ -45,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'