Skip to content

Commit

Permalink
chore: Modernize packaging (#301)
Browse files Browse the repository at this point in the history
Switch to modern packaging backed by setuptools and setuptools-scm,
including a VCS-backed versioning scheme, as well as trusted publishing
configuration for PyPI.
  • Loading branch information
antonagestam authored Sep 15, 2024
1 parent 3b920ec commit 7589e5b
Show file tree
Hide file tree
Showing 15 changed files with 941 additions and 364 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ jobs:
# Keep in sync with version in .readthedocs.yml.
python-version: "3.11"
cache: pip
cache-dependency-path: docs/requirements.txt
cache-dependency-path: docs-requirements.txt
- name: Install dependencies
run: pip install --require-hashes -r docs/requirements.txt
run: pip install --require-hashes --no-dependencies -r docs-requirements.txt
- name: Install package
run: pip install --no-dependencies .
- name: Build docs
run: sphinx-build -W -b html docs docs/_build

Expand All @@ -52,9 +54,9 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: setup.cfg
cache-dependency-path: pyproject.toml
- name: Install minimum requirements
run: pip install --upgrade -e '.[test]'
run: pip install --upgrade '.[test]'
- name: Run all tests that don't require extra dependencies
run: >-
coverage run --append -m pytest
Expand All @@ -63,7 +65,7 @@ jobs:
--ignore=tests/pydantic
--ignore=tests/ext
- name: Install extra requirements
run: pip install --upgrade -e '.[all,test]'
run: pip install --upgrade '.[all,test]'
- name: Run all tests that require extra dependencies
run: >-
coverage run --append -m pytest
Expand Down
43 changes: 40 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,43 @@ on:

jobs:
build-and-publish:
uses: less-action/reusables/.github/workflows/python-publish.yaml@main
secrets:
pypi_api_token: ${{ secrets.PYPI_API_TOKEN }}
name: Build and publish
runs-on: ubuntu-latest
permissions:
# permission required for trusted publishing
id-token: write
environment:
name: pypi
url: https://pypi.org/p/immoney
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.12
cache: pip
cache-dependency-path: pyproject.toml
check-latest: true
- name: Install dependencies
run: python3 -m pip install --upgrade build pkginfo
- name: Build
run: python3 -m build --sdist --wheel .
- name: Inspect built wheel version
id: inspect-wheel-version
run: |
python3 << 'EOF' >> $GITHUB_OUTPUT
from pathlib import Path
from pkginfo import Wheel
[wheel_path] = Path("dist").glob("*.whl")
wheel = Wheel(wheel_path)
print(f"version={wheel.version}")
EOF
- name: Fail on version mismatch
if: ${{ steps.inspect-wheel-version.outputs.version != github.event.release.tag_name }}
run: |
echo "💥 The version of the built wheel does not match the release tag."
echo
echo "Release tag: '${{ github.event.release.tag_name }}'"
echo "Packaged version: '${{ steps.inspect-wheel-version.outputs.version }}'"
exit 1
- name: Publish
uses: pypa/gh-action-pypi-publish@release/v1
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,6 @@ dmypy.json

# pytype static type analyzer
.pytype/

# Dynamic version file
src/phantom/_version.py
4 changes: 3 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,6 @@ repos:
- id: check-manifest
args: ["--no-build-isolation"]
additional_dependencies:
- setuptools==67.4.0
- setuptools==74.1.2
- setuptools-scm==8.1.0
- wheel==0.44.0
4 changes: 3 additions & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ build:
python: "3.11"
python:
install:
- requirements: docs/requirements.txt
- requirements: docs-requirements.txt
- method: pip
path: .
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ exclude *.yaml
exclude *.yml
include README.md
include LICENSE
exclude .gitignore
exclude setup.cfg
exclude *requirements.txt
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ test-typing:
.PHONY: clean
clean:
rm -rf {**/,}*.egg-info **{/**,}/__pycache__ build dist .coverage coverage.xml

docs-requirements: export CUSTOM_COMPILE_COMMAND='make docs-requirements'
docs-requirements:
@pip install --upgrade pip-tools
@pip-compile
782 changes: 782 additions & 0 deletions docs-requirements.txt

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,3 @@ help:
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)


requirements: export CUSTOM_COMPILE_COMMAND='make requirements'
requirements:
@pip-compile
22 changes: 0 additions & 22 deletions docs/pyproject.toml

This file was deleted.

Loading

0 comments on commit 7589e5b

Please sign in to comment.