Skip to content

Commit

Permalink
move to using nox and uv (#135)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
joshuadavidthomas and pre-commit-ci[bot] authored Oct 10, 2024
1 parent b7d8e0e commit 4b3c687
Show file tree
Hide file tree
Showing 9 changed files with 1,814 additions and 235 deletions.
14 changes: 5 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,15 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
python-version: "3.13"
allow-prereleases: true

- name: Install dependencies
run: |
python -m pip install -U pip uv
python -m uv pip install --system hatch
enable-cache: true
version: "0.4.x"

- name: Build package
run: |
hatch build
uv build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
64 changes: 30 additions & 34 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
python-version: "3.8"
allow-prereleases: true
enable-cache: true
version: "0.4.x"

- name: Install dependencies
- name: Install Python
run: |
python -m pip install -U pip uv
python -m uv pip install --system nox
uv python install 3.10
- id: set-matrix
- name: Generate matrix
id: set-matrix
run: |
python -m nox --session "gha_matrix"
uv run nox --session "gha_matrix"
test:
name: Python ${{ matrix.python-version }}, Django ${{ matrix.django-version }}
Expand All @@ -46,19 +47,18 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
python-version: "${{ matrix.python-version }}"
allow-prereleases: true
enable-cache: true
version: "0.4.x"

- name: Install dependencies
run: |
python -m pip install -U pip uv
python -m uv pip install --system nox
- name: Install Python
run: uv python install ${{ matrix.python-version }}

- name: Run tests
run: |
nox --session "tests(python='${{ matrix.python-version }}', django='${{ matrix.django-version }}')"
uv run nox --session "tests(python='${{ matrix.python-version }}', django='${{ matrix.django-version }}')"
tests:
runs-on: ubuntu-latest
Expand All @@ -77,35 +77,31 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
python-version: "3.13"
allow-prereleases: true
enable-cache: true
version: "0.4.x"

- name: Install dependencies
- name: Install Python
run: |
python -m pip install -U pip uv
python -m uv pip install --system nox
uv python install 3.13
- name: Run mypy
- name: Run type checks
run: |
python -m nox --session "mypy"
uv run nox --session "types"
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
python-version: "3.8"
allow-prereleases: true

- name: Install dependencies
run: |
python -m pip install -U pip uv
python -m uv pip install --system nox
enable-cache: true
version: "0.4.x"

- name: Run coverage
- name: Generate code coverage
run: |
python -m nox --session "coverage"
uv run nox --session "coverage"
36 changes: 36 additions & 0 deletions .just/copier.just
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
set unstable := true

justfile := justfile_directory() + "/.just/copier.just"

[private]
default:
@just --list --justfile {{ justfile }}

[private]
fmt:
@just --fmt --justfile {{ justfile }}

# Create a copier answers file
[no-cd]
copy TEMPLATE_PATH DESTINATION_PATH=".":
uv run copier copy --trust {{ TEMPLATE_PATH }} {{ DESTINATION_PATH }}

# Recopy the project from the original template
[no-cd]
recopy ANSWERS_FILE *ARGS:
uv run copier recopy --trust --answers-file {{ ANSWERS_FILE }} {{ ARGS }}

# Loop through all answers files and recopy the project using copier
[no-cd]
@recopy-all *ARGS:
for file in `ls .copier/`; do just copier recopy .copier/$file "{{ ARGS }}"; done

# Update the project using a copier answers file
[no-cd]
update ANSWERS_FILE *ARGS:
uv run copier update --trust --answers-file {{ ANSWERS_FILE }} {{ ARGS }}

# Loop through all answers files and update the project using copier
[no-cd]
@update-all *ARGS:
for file in `ls .copier/`; do just copier update .copier/$file "{{ ARGS }}"; done
31 changes: 31 additions & 0 deletions .just/documentation.just
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
set unstable := true

justfile := justfile_directory() + "/.just/documentation.just"

[private]
default:
@just --list --justfile {{ justfile }}

[private]
fmt:
@just --fmt --justfile {{ justfile }}

# Build documentation using Sphinx
[no-cd]
build LOCATION="docs/_build/html": cog
uv run --extra docs sphinx-build docs {{ LOCATION }}

# Serve documentation locally
[no-cd]
serve PORT="8000": cog
#!/usr/bin/env sh
HOST="localhost"
if [ -f "/.dockerenv" ]; then
HOST="0.0.0.0"
fi
uv run --extra docs sphinx-autobuild docs docs/_build/html --host "$HOST" --port {{ PORT }}
[no-cd]
[private]
cog:
uv run --extra docs cog -r docs/development/just.md
22 changes: 8 additions & 14 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,18 @@
version: 2

build:
jobs:
pre_build:
- asdf plugin add just && asdf install just latest && asdf global just latest
- just _cog
os: ubuntu-22.04
tools:
python: "3.12"
commands:
- asdf plugin add just && asdf install just latest && asdf global just latest
- asdf plugin add uv && asdf install uv latest && asdf global uv latest
- just docs cog
- just docs build $READTHEDOCS_OUTPUT/html

sphinx:
configuration: docs/conf.py
configuration: docs/conf.py

formats:
- pdf
- epub

python:
install:
- method: pip
path: .
extra_requirements:
- docs
- pdf
- epub
133 changes: 30 additions & 103 deletions Justfile
Original file line number Diff line number Diff line change
@@ -1,118 +1,45 @@
set dotenv-load := true
set unstable := true

@_default:
just --list
mod copier ".just/copier.just"
mod docs ".just/documentation.just"

demo:
python -m nox -session "demo"

# ----------------------------------------------------------------------
# DEPENDENCIES
# ----------------------------------------------------------------------

bootstrap:
@just pup
@just install
[private]
default:
@just --list

install:
python -m uv pip install --editable '.[dev]'

pup:
python -m pip install --upgrade pip uv

# ----------------------------------------------------------------------
# TESTING/TYPES
# ----------------------------------------------------------------------
[private]
fmt:
@just --fmt
@just copier fmt
@just docs fmt

test *ARGS:
python -m nox --session "test" -- "{{ ARGS }}"
[private]
nox SESSION *ARGS:
uv run nox --session "{{ SESSION }}" -- "{{ ARGS }}"

testall *ARGS:
python -m nox --session "tests" -- "{{ ARGS }}"
bootstrap:
uv python install
uv sync --frozen

coverage:
python -m nox --session "coverage"

types:
python -m nox --session "mypy"

# ----------------------------------------------------------------------
# DJANGO
# ----------------------------------------------------------------------

manage *COMMAND:
#!/usr/bin/env python
import sys
try:
from django.conf import settings
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
@just nox coverage

settings.configure(INSTALLED_APPS=["django_simple_nav"])
execute_from_command_line(sys.argv + "{{ COMMAND }}".split(" "))

alias mm := makemigrations

makemigrations *APPS:
@just manage makemigrations {{ APPS }}

migrate *ARGS:
@just manage migrate {{ ARGS }}

# ----------------------------------------------------------------------
# DOCS
# ----------------------------------------------------------------------

@docs-install:
@just pup
python -m uv pip install 'django-simple-nav[docs] @ .'

@docs-serve:
#!/usr/bin/env sh
just _cog
if [ -f "/.dockerenv" ]; then
sphinx-autobuild docs docs/_build/html --host "0.0.0.0"
else
sphinx-autobuild docs docs/_build/html --host "localhost"
fi
@docs-build LOCATION="docs/_build/html":
just _cog
sphinx-build docs {{ LOCATION }}

_cog:
cog -r docs/development/just.md

# ----------------------------------------------------------------------
# UTILS
# ----------------------------------------------------------------------

# format justfile
fmt:
just --fmt --unstable
demo:
@just nox demo

# run pre-commit on all files
lint:
python -m nox --session "lint"
uv run --with pre-commit-uv pre-commit run --all-files
just fmt

# ----------------------------------------------------------------------
# COPIER
# ----------------------------------------------------------------------
lock *ARGS:
uv lock {{ ARGS }}

# apply a copier template to project
copier-copy TEMPLATE_PATH DESTINATION_PATH=".":
copier copy {{ TEMPLATE_PATH }} {{ DESTINATION_PATH }}
test *ARGS:
@just nox test {{ ARGS }}

# update the project using a copier answers file
copier-update ANSWERS_FILE *ARGS:
copier update --trust --answers-file {{ ANSWERS_FILE }} {{ ARGS }}
testall *ARGS:
@just nox tests {{ ARGS }}

# loop through all answers files and update the project using copier
@copier-update-all *ARGS:
for file in `ls .copier/`; do just copier-update .copier/$file "{{ ARGS }}"; done
types *ARGS:
@just nox types {{ ARGS }}
Loading

0 comments on commit 4b3c687

Please sign in to comment.