Skip to content

Commit

Permalink
Convert project/packaging config to uv (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
JWCook committed Jan 18, 2025
2 parents bc8d6e4 + 11b70b7 commit 75c58c2
Show file tree
Hide file tree
Showing 7 changed files with 2,101 additions and 2,815 deletions.
12 changes: 4 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,22 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- uses: snok/[email protected]
with:
virtualenvs-in-project: true
- uses: yezz123/setup-uv@v4

# Cache packages per python version, and reuse until lockfile changes
- name: Cache python packages
id: cache
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
key: venv-${{ matrix.python-version }}-${{ hashFiles('uv.lock') }}
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: poetry install -v -E all
run: uv sync --all-extras

# Run tests with coverage report
- name: Run tests
run: |
source $VENV
nox -e cov -- xml
run: uv run nox -e cov -- xml

# Latest python version: send coverage report to codecov
- name: "Upload coverage report to Codecov"
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: ${{ env.LATEST_PY_VERSION }}
- uses: snok/[email protected]
with:
virtualenvs-in-project: true
- uses: yezz123/setup-uv@v4

- name: Set pre-release version
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
env:
pre-release-suffix: ${{ github.event.inputs.pre-release-suffix || 'dev' }}
pre-release-version: ${{ github.event.inputs.pre-release-version || github.run_number }}
run: |
poetry version $(poetry version -s).${{ env.pre-release-suffix }}${{ env.pre-release-version }}
poetry version
PKG_VERSION=$(uvx --from=toml-cli toml get --toml-path=pyproject.toml project.version)
DEV_VERSION=$PKG_VERSION.${{ env.pre-release-suffix }}${{ env.pre-release-version }}
echo "Setting pre-release version to $DEV_VERSION"
uvx --from=toml-cli toml set --toml-path=pyproject.toml project.version $DEV_VERSION
- name: Build package distributions
run: poetry build
run: uv build
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
14 changes: 8 additions & 6 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ sphinx:
configuration: docs/conf.py

build:
os: 'ubuntu-22.04'
os: 'ubuntu-24.04'
tools:
python: '3.11'

python: '3.12'
jobs:
# Use uv to export optional + documentation dependencies
post_create_environment:
- pip install uv
- uv export -q --no-dev --group docs --no-emit-project -o docs/requirements.txt
python:
install:
- method: pip
path: .
extra_requirements:
- all
- docs
- requirements: docs/requirements.txt
24 changes: 17 additions & 7 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from shutil import rmtree

import nox
from nox_poetry import session

nox.options.reuse_existing_virtualenvs = True
nox.options.sessions = ['lint', 'cov']
Expand All @@ -17,23 +16,34 @@
DEFAULT_COVERAGE_FORMATS = ['html', 'term']


@session(python=['3.10', '3.11', '3.12', '3.13'])
def install_deps(session):
"""Install project and test dependencies into a nox session using uv"""
session.env['UV_PROJECT_ENVIRONMENT'] = session.virtualenv.location
session.run_install(
'uv',
'sync',
'--frozen',
'--all-extras',
)


@nox.session(python=['3.10', '3.11', '3.12', '3.13'], venv_backend='uv')
def test(session):
"""Run tests for a specific python version"""
test_paths = session.posargs or ['test']
session.install('.', 'pytest', 'pytest-xdist')
install_deps(session)
session.run('pytest', '-n', 'auto', *test_paths)


@session(python=False)
@nox.session(python=False)
def clean(session):
"""Clean up temporary build + documentation files"""
for dir in CLEAN_DIRS:
print(f'Removing {dir}')
rmtree(dir, ignore_errors=True)


@session(python=False, name='cov')
@nox.session(python=False, name='cov')
def coverage(session):
"""Run tests and generate coverage report"""
cmd = ['pytest', '-n', 'auto', '--cov']
Expand All @@ -44,14 +54,14 @@ def coverage(session):
session.run(*cmd)


@session(python=False)
@nox.session(python=False)
def docs(session):
"""Build Sphinx documentation"""
cmd = 'sphinx-build docs docs/_build/html -j auto'
session.run(*cmd.split(' '))


@session(python=False)
@nox.session(python=False)
def lint(session):
"""Run linters and code formatters via pre-commit"""
cmd = 'pre-commit run --all-files'
Expand Down
Loading

0 comments on commit 75c58c2

Please sign in to comment.