Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_language_version:
python: python311
python: python312

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,28 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

### Added

- Template is linted and bootstrapped after generation.
- Added a `gha_matrix` nox session to template for generating GHA job matrix.

### Changed

- Template now uses `uv` as a project and dependency management tool.
- GitHub Actions in template now use `astral-sh/setup-uv` for Python installation, dependency installation, and command running.
- Moved documentation and copier commands to separate Just sub-modules.
- Now using `uv` dev dependencies instead of `[dev]` extra.
- Moved template's test dependencies to dedicated `[tests]` extra.

### Removed

- Python 3.8 support for `django-twc-package` project.
- Removed `[lint]` extra from template's optional dependencies. This is now handled by `uv run`.

### Fixed

- Added correct Python version skip logic for Django 5.1 in template's `noxfile.py`.

## [2024.27]

### Added
Expand Down
14 changes: 14 additions & 0 deletions copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,17 @@ test_django_main:
type: bool
help: Test against the Django `main` branch?
default: true

# ----------------------------------------------------------------------
# POST GENERATION TASKS
# ----------------------------------------------------------------------

_tasks:
# run pre-commit after generation, first without ruff-format hook since it
# always formats pyproject.toml to sort (since it finally has a module name
# to sort by) -- this is to check no errors. then run a second time but pipe
# any errors to /dev/null since if a file is formatted, that exits with an
# error and we want to continue anyway
- "SKIP=ruff-format just lint"
- "just lint 2>/dev/null || echo 'Pre-commit run on all files.'"
- "just bootstrap"
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dynamic = ["version"]
license = {file = "LICENSE"}
name = "django-twc-package"
readme = "README.md"
requires-python = ">= 3.8"
requires-python = ">= 3.9"

[tool.bumpver]
commit = true
Expand Down Expand Up @@ -56,8 +56,8 @@ extend-include = ["*.pyi?"]
indent-width = 4
# Same as Black.
line-length = 88
# Assume Python >3.8.
target-version = "py38"
# Assume Python >3.9.
target-version = "py39"

[tool.ruff.format]
# Like Black, indent with spaces, rather than tabs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ jobs:
uses: ./.github/workflows/test.yml

pypi:
if: ${% raw %}{{ github.event_name == 'release' }}{% endraw %}
runs-on: ubuntu-latest
needs: test
environment: release
Expand All @@ -22,19 +21,15 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
python-version: "{{ python_max_version }}"
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
66 changes: 32 additions & 34 deletions src/django_twc_package/.github/workflows/test.yml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ concurrency:
env:
PYTHONUNBUFFERED: "1"
FORCE_COLOR: "1"
PY_MAX_VERSION: "{{ python_max_version }}"
PY_MIN_VERSION: "{{ python_min_version }}"
UV_VERSION: "0.4.x"

jobs:
generate-matrix:
Expand All @@ -22,19 +25,18 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
python-version: "{{ python_min_version }}"
allow-prereleases: true
enable-cache: true
version: ${% raw %}{{ env.UV_VERSION }}{% endraw %}

- 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 ${% raw %}{{ env.PY_MIN_VERSION }}{% endraw %}

- id: set-matrix
run: |
echo "matrix=$(python -m nox -l --json | jq -c '[.[] | select(.name == "tests") | {"python-version": .python, "django-version": .call_spec.django}] | {include: .}')" >> $GITHUB_OUTPUT
uv run nox --session "gha_matrix"

test:
name: Python ${% raw %}{{ matrix.python-version }}{% endraw %}, Django ${% raw %}{{ matrix.django-version }}{% endraw %}
Expand All @@ -46,19 +48,18 @@ jobs:
steps:
- uses: actions/checkout@v4

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

- 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 ${% raw %}{{ matrix.python-version }}{% endraw %}

- name: Run tests
run: |
python -m nox --session "tests(python='${% raw %}{{ matrix.python-version }}{% endraw %}', django='${% raw %}{{ matrix.django-version }}{% endraw %}')"
uv run nox --session "tests(python='${% raw %}{{ matrix.python-version }}{% endraw %}', django='${% raw %}{{ matrix.django-version }}{% endraw %}')"

tests:
runs-on: ubuntu-latest
Expand All @@ -76,36 +77,33 @@ jobs:
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: "{{ python_max_version }}"
allow-prereleases: true
enable-cache: true
version: ${% raw %}{{ env.UV_VERSION }}{% endraw %}

- 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 ${% raw %}{{ env.PY_MAX_VERSION }}{% endraw %}

- name: Run mypy
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: "{{ python_min_version }}"
allow-prereleases: true
enable-cache: true
version: ${% raw %}{{ env.UV_VERSION }}{% endraw %}

- 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 ${% raw %}{{ env.PY_MIN_VERSION }}{% endraw %}

- name: Run coverage
- name: Run mypy
run: |
python -m nox --session "coverage"
uv run nox --session "coverage"
36 changes: 36 additions & 0 deletions src/django_twc_package/.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 src/django_twc_package/.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
16 changes: 5 additions & 11 deletions src/django_twc_package/.readthedocs.yaml.jinja
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: "{{ python_max_version }}"
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
- uv run --extra docs sphinx-build docs $READTHEDOCS_OUTPUT/html

sphinx:
configuration: docs/conf.py

formats:
- pdf
- epub

python:
install:
- method: pip
path: .
extra_requirements:
- docs
42 changes: 42 additions & 0 deletions src/django_twc_package/Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
set dotenv-load := true
set unstable := true

mod copier ".just/copier.just"
mod docs ".just/documentation.just"

[private]
default:
@just --list

[private]
fmt:
@just --fmt
@just copier fmt
@just docs fmt

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

bootstrap:
uv python install
uv sync --frozen

coverage:
@just nox coverage

lint:
uv run --with pre-commit-uv pre-commit run --all-files
just fmt

lock *ARGS:
uv lock {{ ARGS }}

test *ARGS:
@just nox test {{ ARGS }}

testall *ARGS:
@just nox tests {{ ARGS }}

types *ARGS:
@just nox types {{ ARGS }}
Loading