Skip to content

Commit

Permalink
WIP: Convert project & packaging config to uv
Browse files Browse the repository at this point in the history
  • Loading branch information
JWCook committed Jan 16, 2025
1 parent 848f3b5 commit b9c649e
Show file tree
Hide file tree
Showing 8 changed files with 2,771 additions and 3,346 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ 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
Expand All @@ -39,11 +37,11 @@ jobs:
key: venv-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: poetry install -v -E all
run: uv sync

# Run tests with coverage report
- name: Run tests
run: poetry run pytest -rs -x -vv ${{ env.XDIST_ARGS }} ${{ env.COVERAGE_ARGS }}
run: uv run pytest -rs -x -vv ${{ env.XDIST_ARGS }} ${{ env.COVERAGE_ARGS }}

# Latest python version: send coverage report to codecov
- name: "Upload coverage report to Codecov"
Expand Down
23 changes: 6 additions & 17 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,19 @@ 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=$(sed -n "s/^version\s*=\s*'\(.*\)'/\1/p")
DEV_VERSION=$PKG_VERSION.${{ env.pre-release-suffix }}${{ env.pre-release-version }}
echo "Setting version to $DEV_VERSION"
sed -i "s/^version\s*=.*/version='$DEV_VERSION'/" pyproject.toml
- name: Build package distributions
run: poetry build
run: uvx --from build pyproject-build --installer uv
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

# Notify Docker image repo that there's a new release available
#- name: Repository Dispatch
# if: ${{ startsWith(github.ref, 'refs/tags/v') }}
# uses: peter-evans/repository-dispatch@v1
# with:
# token: ${{ secrets.DOCKERHUB_TRIGGER_TOKEN }}
# repository: JWCook/pyinaturalist-notebook
# event-type: post-release
# client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ eggs
lib
lib64
parts
scratch
sdist
var
venv/
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ Contributions are welcome, and they are greatly appreciated! Every
little bit helps, and credit will always be given.

## Installation
To set up for local development (requires [poetry](https://python-poetry.org)):
To set up for local development (requires [uv](https://docs.astral.sh/uv)):
```bash
$ git clone https://github.com/pyinat/pyinaturalist.git
$ cd pyinaturalist
$ poetry install -v -E docs
$ uv sync --all-extras
```

## Contribution Guidelines
Expand Down
14 changes: 6 additions & 8 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 @@ -25,38 +24,37 @@
]


@session(python=['3.8', '3.9', '3.10', '3.11', '3.12', '3.13'])
@nox.session(python=['3.8', '3.9', '3.10', '3.11', '3.12', '3.13'])
def test(session):
"""Run tests for a specific python version"""
test_paths = session.posargs or ['test']
session.install('.', 'pytest', 'pytest-sugar', 'pytest-xdist', 'requests-mock')
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)
@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 --cov-report=term --cov-report=html'
session.run(*cmd.split(' '))


@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 livedocs(session):
"""Auto-build docs with live reload in browser.
Add `-- open` to also open the browser after starting.
Expand All @@ -73,7 +71,7 @@ def livedocs(session):
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 b9c649e

Please sign in to comment.