Skip to content

chore(dev): add prek git hooks for Python, ruff, uv and Django - #249

Merged
matrixise merged 9 commits into
masterfrom
chore/prek-hooks
Sep 25, 2026
Merged

matrixise merged 9 commits into
masterfrom
chore/prek-hooks

Conversation

@matrixise

@matrixise matrixise commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Set up prek, a Rust drop-in replacement for pre-commit that reads .pre-commit-config.yaml, with a base set of hooks for Python, ruff, uv and Django.

Installation choice

Like uv, prek is a machine tool, not a project dependency: it is not in pyproject.toml nor uv.lock. It is pinned in mise.toml next to uv (mise install), and can also be installed with brew install prek or uv tool install prek. Then run prek install in the clone. The ruff and Django hooks still need the project environment (uv sync --all-groups).

Hooks

  • pre-commit-hooks v6.0.0: trailing-whitespace, end-of-file-fixer, mixed-line-ending (LF), check-yaml, check-toml, check-json, check-merge-conflict, check-case-conflict, check-added-large-files (500 KB), debug-statements, detect-private-key
  • astral-sh/uv-pre-commit 0.12.19: uv-lock (rev aligned with the uv pinned in mise.toml and the dev group)
  • django-upgrade 1.32.0: --target-version 6.0
  • local hooks through uv run --frozen: ruff check --fix, ruff format, manage.py check, manage.py makemigrations --check --dry-run

Ruff runs as a local hook instead of astral-sh/ruff-pre-commit: the version comes from uv.lock, so the hook, CI and the editor cannot drift, and there is no rev to keep aligned with pyproject.toml.

The Django hooks unset DATABASE_URL so they always use the local SQLite database, even when a shell exports a remote DATABASE_URL.

Vendored assets under pythonie/core/static/{css,fonts,js} (Bootstrap, Font Awesome, SmartMenus) are excluded.

Not added: djLint. On the current templates it reports 12 lint errors (missing lang/alt, type on scripts, orphan tag, tag spacing) and would reformat all 13 templates. It is worth a follow-up PR that fixes the templates first.

Fixes from the first prek run --all-files (separate commits)

  • style: whitespace/EOF only: .coveragerc, CLAUDE.md, development.env, base.html, core/meetup.html, core/segment.html, navbar_tree.html
  • refactor: django-upgrade: drop USE_L10N (removed in Django 5.0), include from django.urls, path() instead of re_path() for the admin/ and documents/ prefixes, @admin.register in sponsors/admin.py

No behavior change.

CI

New prek job in test.yml, parallel to the existing test job: uv sync --all-groups (for the local ruff and Django hooks), then j178/prek-action@v3.0.0, which installs prek, caches the hook environments and runs prek run --show-diff-on-failure --all-files. The existing ruff, pip-audit and test steps are kept unchanged: the ruff steps overlap with the hooks but take under a second and remain the explicit gates of the test job.

Renovate

The pre-commit manager is disabled by default in Renovate: it is now enabled. Hook revisions are grouped in a weekly "pre-commit hooks" PR, and astral-sh/uv-pre-commit joins the existing uv group so it moves together with the uv dev dependency, Dockerfile and mise.toml.

Docs

README.md, CONTRIBUTING.md, DEVELOPMENT.md and CLAUDE.md: uv and prek listed as prerequisites, a uv sync --all-groups && prek install step in both the Docker and the local setup guides (the hooks run on the host even with Docker), usage, and emergency bypass (SKIP=<hook-id>, git commit --no-verify).

Test plan

  • prek run --all-files: all hooks pass
  • uv run ruff format --check pythonie and uv run ruff check pythonie
  • uv run python pythonie/manage.py test pythonie --settings=pythonie.settings.tests (SQLite): 7 tests OK
  • renovate-config-validator renovate.json
  • CI green (prek job and test job)

🤖 Generated with Claude Code

matrixise and others added 9 commits September 25, 2026 08:54
Add prek (Rust reimplementation of pre-commit) to the dev dependency group
and a .pre-commit-config.yaml with:

- pre-commit-hooks: whitespace, EOF, line endings, YAML/TOML/JSON syntax,
  merge conflicts, large files, debug statements, private keys
- uv-lock to keep uv.lock in sync with pyproject.toml
- django-upgrade targeting Django 6.0
- local hooks running ruff check/format, `manage.py check` and a missing
  migrations check through `uv run`, so the versions come from uv.lock

Vendored static assets (Bootstrap, Font Awesome, SmartMenus) are excluded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mass fixes from the trailing-whitespace and end-of-file-fixer hooks on the
first `prek run --all-files`. Whitespace only, no behavior change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mass fixes from the django-upgrade hook (--target-version 6.0), followed
by ruff merging the resulting imports:

- drop USE_L10N, removed in Django 5.0 (localization is always on)
- import include from django.urls instead of django.conf.urls
- use path() instead of re_path() for the plain admin/ and documents/
  prefixes
- register sponsors admin classes with the @admin.register decorator

No behavior change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add a dedicated prek job, in parallel with the test job, running every hook
with the versions locked in uv.lock. Hook environments are cached per
.pre-commit-config.yaml hash. The existing ruff, pip-audit and test steps
are kept unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Enable the pre-commit manager (disabled by default in Renovate), group hook
revision bumps in a weekly PR and keep the uv-lock hook in the uv group so
it moves together with the uv dev dependency, Dockerfile and mise.toml.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
prek is a developer tool installed once per machine (mise, Homebrew or
uv tool), not a project dependency: drop it from the dev group and
uv.lock. CI installs it with j178/prek-action, which also caches the hook
environments. Docs now use `prek` directly instead of `uv run prek`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
prek is a machine tool like uv: pin it in mise.toml so `mise install`
provides it, and document mise as the default way to get it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
List uv and prek as prerequisites (pinned in mise.toml) and add the
`uv sync --all-groups && prek install` step to the Docker and local setup
guides in README.md, CONTRIBUTING.md and DEVELOPMENT.md: the hooks run on
the host even when developing with Docker. README.md gets a Git Hooks
section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@matrixise
matrixise merged commit 90cf69d into master Sep 25, 2026
4 checks passed
@matrixise
matrixise deleted the chore/prek-hooks branch September 25, 2026 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant