From 984058e34caa668ff985e4aae56ffa983553c411 Mon Sep 17 00:00:00 2001 From: Taheera Ahmed Date: Tue, 31 Mar 2026 14:15:34 +0200 Subject: [PATCH] chg: use prek instead of pre-commit --- .../workflows/{pre-commit.yml => prek.yml} | 15 ++-- .pre-commit-config-extra.yaml | 8 --- .pre-commit-config.yaml | 70 ------------------- README.md | 24 ++++--- ctt.toml | 4 +- prek-extra.toml | 9 +++ prek.toml | 70 +++++++++++++++++++ .../workflows/{pre-commit.yml => prek.yml} | 9 ++- python/.pre-commit-config.yaml.jinja | 1 - python/README.md.jinja | 20 +++--- python/prek.toml.jinja | 1 + ...if docker %}.dockerignore{% endif %}.jinja | 3 +- scripts/maintenance.sh | 6 +- 13 files changed, 126 insertions(+), 114 deletions(-) rename .github/workflows/{pre-commit.yml => prek.yml} (72%) delete mode 100644 .pre-commit-config-extra.yaml delete mode 100644 .pre-commit-config.yaml create mode 100644 prek-extra.toml create mode 100644 prek.toml rename python/.github/workflows/{pre-commit.yml => prek.yml} (79%) delete mode 100644 python/.pre-commit-config.yaml.jinja create mode 100644 python/prek.toml.jinja diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/prek.yml similarity index 72% rename from .github/workflows/pre-commit.yml rename to .github/workflows/prek.yml index a0d69c2..5646a09 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/prek.yml @@ -8,7 +8,7 @@ on: permissions: {} jobs: - pre-commit: + prek: runs-on: ubuntu-latest permissions: contents: read @@ -35,10 +35,11 @@ jobs: - name: Install deptry run: uv tool install deptry - - name: Run pre-commit - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 + - name: Install prek + run: uv tool install prek - - name: Run pre-commit (extra) - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 - with: - extra_args: --config .pre-commit-config-extra.yaml + - name: Run prek + run: prek run --all-files --show-diff-on-failure + + - name: Run prek (extra) + run: prek run --all-files --show-diff-on-failure --config prek-extra.toml diff --git a/.pre-commit-config-extra.yaml b/.pre-commit-config-extra.yaml deleted file mode 100644 index d218f2f..0000000 --- a/.pre-commit-config-extra.yaml +++ /dev/null @@ -1,8 +0,0 @@ -default_stages: [pre-commit] - -repos: - - repo: https://github.com/KyleKing/copier-template-tester - rev: 2.3.0 - hooks: - - id: copier-template-tester - additional_dependencies: [copier-template-extensions] diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 100644 index 45e352b..0000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1,70 +0,0 @@ -default_stages: [pre-commit] - -repos: - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v6.0.0 - hooks: - - id: trailing-whitespace - - id: end-of-file-fixer - - id: check-json - - id: check-toml - - id: check-xml - - id: check-yaml - - id: debug-statements - - id: check-builtin-literals - - id: check-case-conflict - - id: check-docstring-first - - id: detect-private-key - # Prevent committing inline conflict markers - - id: check-merge-conflict - args: [--assume-in-merge] - - - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks - rev: v2.16.0 - hooks: - - id: pretty-format-toml - args: [--autofix] - exclude: ^uv\.lock$ - - - repo: https://github.com/Yelp/detect-secrets - rev: v1.5.0 - hooks: - - id: detect-secrets - args: [--exclude-files=django/src/fixtures/users.json] - - - repo: local - hooks: - # Prevent committing .rej files - - id: forbidden-files - name: forbidden files - entry: found Copier update rejection files - description: - review and remove .rej files before - merging. - language: fail - files: "\\.rej$" - - - repo: https://github.com/woodruffw/zizmor-pre-commit - rev: v1.23.1 - hooks: - - id: zizmor - - - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.15.7 - hooks: - - id: ruff - - id: ruff-format - - - repo: https://github.com/astral-sh/uv-pre-commit - rev: 0.10.12 - hooks: - - id: uv-lock - - - repo: local - hooks: - - id: deptry - name: deptry - entry: uv run deptry . - language: system - types: [python] - pass_filenames: false diff --git a/README.md b/README.md index bb930f6..cd01aba 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Why should I use this template: - **Auto formatting and code checking** using `ruff` - **Updatable template** - Easy to keep up to date with latest practices - **Visual Studio Code** configurations included -- **Pre-commit hooks** for code quality enforcement +- **Git hooks with prek** for code quality enforcement - **GitHub Actions** workflows for CI/CD ### Optional features @@ -62,22 +62,28 @@ In both cases, copier will try to check differences between your project and the Check this [page](https://copier.readthedocs.io/en/stable/updating/) for more specific info about this feature. -## Running pre-commit +## Running prek -[pre-commit](https://github.com/pre-commit/pre-commit) is a framework for managing pre-commit git hooks. The pre-commit git hooks are ways to identify issues in your code before pushing your changes to the repository, for instance missing semicolons, trailing whitespace, unused dependencies. +[prek](https://prek.j178.dev/) is a fast, Rust-based framework for managing git hooks. It's 100% compatible with pre-commit configs but significantly faster. Git hooks help identify issues in your code before pushing to the repository, such as missing semicolons, trailing whitespace, or unused dependencies. -:sparkles: pre-commit doesn't change the functionality of your code +:sparkles: prek doesn't change the functionality of your code -To run pre-commit on your code, first install pre-commit: +To run prek on your code, first install prek: ``` -uv tool install pre-commit +uv tool install prek ``` -Then run: +Then install the git hooks: ``` -pre-commit run --all +prek install +``` + +To run manually on all files: + +``` +prek run --all-files ``` ## Struggling with a template? @@ -91,7 +97,7 @@ Install development dependencies: ## Testing the template To test the template using copier-template-tester, run: ```bash -pre-commit run -c .pre-commit-config-extra.yaml +prek run -c prek-extra.toml ``` ## Maintenance diff --git a/ctt.toml b/ctt.toml index 3ed2662..60119e2 100644 --- a/ctt.toml +++ b/ctt.toml @@ -1,10 +1,10 @@ [defaults] -# Test pre-commit functionality +# Test prek functionality _extra_tasks = [ "git init", "git add .", "uv sync --dev", - "uv run pre-commit run --all-files end-of-file-fixer || uv run pre-commit run --all-files" + "uv run prek run --all-files end-of-file-fixer || uv run prek run --all-files" ] author_name = "Test Author" debug = true diff --git a/prek-extra.toml b/prek-extra.toml new file mode 100644 index 0000000..d3a4473 --- /dev/null +++ b/prek-extra.toml @@ -0,0 +1,9 @@ +# See https://prek.j178.dev for more information. +# :schema https://www.schemastore.org/prek.json + +default_stages = ["pre-commit"] + +[[repos]] +hooks = [{id = "copier-template-tester", additional_dependencies = ["copier-template-extensions"]}] +repo = "https://github.com/KyleKing/copier-template-tester" +rev = "2.3.0" diff --git a/prek.toml b/prek.toml new file mode 100644 index 0000000..8557c4c --- /dev/null +++ b/prek.toml @@ -0,0 +1,70 @@ +# See https://prek.j178.dev for more information. +# schema: https://www.schemastore.org/prek.json + +default_stages = ["pre-commit"] + +[[repos]] +hooks = [ + {id = "trailing-whitespace"}, + {id = "end-of-file-fixer"}, + {id = "check-json"}, + {id = "check-toml"}, + {id = "check-xml"}, + {id = "check-yaml"}, + {id = "debug-statements"}, + {id = "check-builtin-literals"}, + {id = "check-case-conflict"}, + {id = "check-docstring-first"}, + {id = "detect-private-key"}, + {id = "check-merge-conflict", args = ["--assume-in-merge"]} +] +repo = "https://github.com/pre-commit/pre-commit-hooks" +rev = "v6.0.0" + +[[repos]] +hooks = [ + {id = "pretty-format-toml", args = ["--autofix"], exclude = '^uv\.lock$'} +] +repo = "https://github.com/macisamuele/language-formatters-pre-commit-hooks" +rev = "v2.16.0" + +[[repos]] +hooks = [ + {id = "detect-secrets", args = ["--exclude-files=django/src/fixtures/users.json"]} +] +repo = "https://github.com/Yelp/detect-secrets" +rev = "v1.5.0" + +[[repos]] +hooks = [ + {id = "forbidden-files", name = "forbidden files", entry = "found Copier update rejection files", description = "review and remove .rej files before merging.", language = "fail", files = '\.rej$'} +] +repo = "local" + +[[repos]] +hooks = [ + {id = "zizmor"} +] +repo = "https://github.com/woodruffw/zizmor-pre-commit" +rev = "v1.23.1" + +[[repos]] +hooks = [ + {id = "ruff"}, + {id = "ruff-format"} +] +repo = "https://github.com/astral-sh/ruff-pre-commit" +rev = "v0.15.7" + +[[repos]] +hooks = [ + {id = "uv-lock"} +] +repo = "https://github.com/astral-sh/uv-pre-commit" +rev = "0.10.12" + +[[repos]] +hooks = [ + {id = "deptry", name = "deptry", entry = "uv run deptry .", language = "system", types = ["python"], pass_filenames = false} +] +repo = "local" diff --git a/python/.github/workflows/pre-commit.yml b/python/.github/workflows/prek.yml similarity index 79% rename from python/.github/workflows/pre-commit.yml rename to python/.github/workflows/prek.yml index 4b624ec..4ed3780 100644 --- a/python/.github/workflows/pre-commit.yml +++ b/python/.github/workflows/prek.yml @@ -8,7 +8,7 @@ on: permissions: {} jobs: - pre-commit: + prek: runs-on: ubuntu-latest permissions: contents: read @@ -27,5 +27,8 @@ jobs: - name: Install deptry run: uv tool install deptry - - name: Run pre-commit - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 + - name: Install prek + run: uv tool install prek + + - name: Run prek + run: prek run --all-files --show-diff-on-failure diff --git a/python/.pre-commit-config.yaml.jinja b/python/.pre-commit-config.yaml.jinja deleted file mode 100644 index 325813d..0000000 --- a/python/.pre-commit-config.yaml.jinja +++ /dev/null @@ -1 +0,0 @@ -{% include_raw '.pre-commit-config.yaml' %} diff --git a/python/README.md.jinja b/python/README.md.jinja index bc49d53..0088e7c 100644 --- a/python/README.md.jinja +++ b/python/README.md.jinja @@ -8,7 +8,7 @@ git init uv sync --dev git add . git commit -m "Initial commit" -uv run pre-commit install # optional +uv run prek install # optional ``` {% if notebook %} @@ -60,22 +60,22 @@ You can keep your previous answers by using: uvx --with copier-template-extensions copier update --trust --defaults ``` -### (Optional) pre-commit -pre-commit is a set of tools that help you ensure code quality. It runs every time you make a commit. +### (Optional) prek +prek is a fast, Rust-based tool for managing git hooks (100% compatible with pre-commit). It helps ensure code quality by running checks every time you make a commit. -First, install pre-commit: +First, install prek: ```bash -uv tool install pre-commit +uv tool install prek ``` -Then install pre-commit hooks: +Then install git hooks: ```bash -pre-commit install +prek install ``` -To run pre-commit on all files: +To run prek on all files: ```bash -pre-commit run --all-files +prek run --all-files ``` ### How to install a package @@ -97,7 +97,7 @@ docker compose up --build watch ### Tools installed - uv -- pre-commit (optional) +- prek (optional) #### What is an environment variable? and why should I use them? Environment variables are variables that are not populated in your code but rather in the environment diff --git a/python/prek.toml.jinja b/python/prek.toml.jinja new file mode 100644 index 0000000..43f157e --- /dev/null +++ b/python/prek.toml.jinja @@ -0,0 +1 @@ +{% include_raw 'prek.toml' %} diff --git a/python/{% if docker %}.dockerignore{% endif %}.jinja b/python/{% if docker %}.dockerignore{% endif %}.jinja index 929df11..716fbea 100644 --- a/python/{% if docker %}.dockerignore{% endif %}.jinja +++ b/python/{% if docker %}.dockerignore{% endif %}.jinja @@ -2,7 +2,8 @@ _build/ __pycache__/ .vscode .git -.pre-commit-config.yaml +prek.toml +prek-extra.toml .venv .env {% block extra %}{% endblock %} diff --git a/scripts/maintenance.sh b/scripts/maintenance.sh index 622adb5..7a9968c 100755 --- a/scripts/maintenance.sh +++ b/scripts/maintenance.sh @@ -3,9 +3,9 @@ set -e echo "🔧 Running maintenance tasks..." -echo "📦 Updating pre-commit hooks..." -uvx pre-commit autoupdate -uvx pre-commit autoupdate --config .pre-commit-config-extra.yaml +echo "📦 Updating prek hooks..." +prek autoupdate +prek autoupdate --config prek-extra.toml echo "🚀 Updating pinned GitHub Actions..." pinact run --update