From 338428dd4ca410bb2890b5012a06649f02e85fd9 Mon Sep 17 00:00:00 2001 From: Patrick Roddy Date: Tue, 15 Sep 2026 13:10:14 +0100 Subject: [PATCH 1/2] Swap out references to `pre-commit` with `prek` --- .github/workflows/linting.yml | 24 +++++++++---------- CONTRIBUTING.md | 6 ++--- docs/pages/tutorial.md | 16 ++++++------- .../.github/workflows/linting.yml | 12 +++++----- tests/data/test_package_generation/README.md | 2 +- .../test_package_generation/pyproject.toml | 2 +- .../.github/workflows/linting.yml | 12 +++++----- {{cookiecutter.project_slug}}/README.md | 2 +- {{cookiecutter.project_slug}}/pyproject.toml | 2 +- 9 files changed, 39 insertions(+), 39 deletions(-) diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index accd7691..01fcb79a 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -14,11 +14,11 @@ jobs: - name: Checkout source uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 - - name: Cache pre-commit + - name: Cache prek uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 with: - path: ~/.cache/pre-commit - key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} + path: ~/.cache/prek + key: prek-${{ hashFiles('.pre-commit-config.yaml') }} - name: Set up python uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 @@ -26,10 +26,10 @@ jobs: python-version: "3.x" - name: Install dependencies - run: python -m pip install pre-commit + run: python -m pip install prek - - name: Run pre-commit - run: pre-commit run --all-files --color always --verbose + - name: Run prek + run: prek run --all-files --color always --verbose lint-the-template: runs-on: ubuntu-latest @@ -37,11 +37,11 @@ jobs: - name: Checkout source uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 - - name: Cache pre-commit + - name: Cache prek uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 with: - path: ~/.cache/pre-commit - key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} + path: ~/.cache/prek + key: prek-${{ hashFiles('.pre-commit-config.yaml') }} - name: Set up python uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 @@ -49,15 +49,15 @@ jobs: python-version: "3.x" - name: Install dependencies - run: python -m pip install cookiecutter pre-commit + run: python -m pip install cookiecutter prek - name: Create template run: cookiecutter . --no-input --output-dir cookie-template - - name: Run pre-commit + - name: Run prek run: |- git add . - pre-commit run --all-files --color always --verbose + prek run --all-files --color always --verbose working-directory: cookie-template/python-template lint-prose: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 93393475..17d5c2d0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,8 +26,8 @@ To contribute a change, please: 1. Create a new branch (or fork if you're not in [@UCL-ARC/collaborations]). 2. Modify an existing page, create a new one, or tweak the template. a. Run - [pre-commit] which will lint your changes. b. Check - the tests pass if you modified the template (`pytest -s`). + [prek] which will lint your changes. b. Check the tests pass if you modified + the template (`pytest -s`). 3. Open a _pull request_ (PR) with changes. 4. Ask someone who did not contribute to the PR from [@UCL-ARC/collaborations] to review it. If it should have two reviewers, you can also request a review @@ -90,7 +90,7 @@ See the [jekyll docs] for more info. [open an issue]: https://github.com/UCL-ARC/python-tooling/issues/new/choose [Discussions tab]: https://github.com/UCL-ARC/python-tooling/discussions [Research software engineers]: https://society-rse.org/about/history -[pre-commit]: https://pre-commit.com +[prek]: https://prek.j178.dev [@UCL-ARC/collaborations]: https://github.com/orgs/UCL-ARC/teams/collaborations [@UCL-ARC/collaborations-python-tooling]: https://github.com/orgs/UCL-ARC/teams/collaborations-python-tooling [uv tool]: https://docs.astral.sh/uv/guides/tools diff --git a/docs/pages/tutorial.md b/docs/pages/tutorial.md index 49e40324..f8290cac 100644 --- a/docs/pages/tutorial.md +++ b/docs/pages/tutorial.md @@ -396,18 +396,18 @@ tox -e docs from the root of the project repository. The built documentation will be output to a directory `site`. -## ✅ Using `pre-commit` to run checks when committing +## ✅ Using `prek` to run checks when committing -The package is set-up to use [pre-commit](https://pre-commit.com/), a framework for running [Git hook scripts](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) on each commit to the repository. +The package is set-up to use [prek](https://prek.j178.dev/), a framework for running [Git hook scripts](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) on each commit to the repository. There is a `.pre-commit-config.yaml` configuration file which you can take a look at. -With this setup `pre-commit` will run a series of fast linters, checks and formatters on the repository on every commit. +With this setup `prek` will run a series of fast linters, checks and formatters on the repository on every commit. The main tools we recommend are [ruff](https://docs.astral.sh/ruff/), [ty](https://docs.astral.sh/ty/) and [prettier](https://prettier.io/). These Git hook scripts can be installed locally by running ```sh -pre-commit install +prek install ``` from the root of the project repository. @@ -415,14 +415,14 @@ You will only need to do this once per `git clone` of the code. Once installed, the scripts will be called to inspect the changes each time `git commit` is run. Any failures of the checks will need to be fixed before the changes can be committed. -Some of the `pre-commit` hooks include support for auto-fixing easy problems - in this case you will be alerted that a file has been changed by a hook and these changes need to be staged using `git add` before recommitting. +Some of the `prek` hooks include support for auto-fixing easy problems - in this case you will be alerted that a file has been changed by a hook and these changes need to be staged using `git add` before recommitting. The hooks typically only run on the files _changed_ in a commit. -The `pre-commit` hooks can be run against _all files in the repository_ by running +The `prek` hooks can be run against _all files in the repository_ by running ```sh -pre-commit run --all-files +prek run --all-files ``` from the root of the project repository. -This is useful to check they will pass if the `pre-commit` configuration is updated, for example, when [adding a new plug-in](https://pre-commit.com/#plugins). +This is useful to check they will pass if the `prek` configuration is updated, for example, when [adding a new plug-in](https://prek.j178.dev/authoring-hooks). diff --git a/tests/data/test_package_generation/.github/workflows/linting.yml b/tests/data/test_package_generation/.github/workflows/linting.yml index 0da23c2d..e538881b 100644 --- a/tests/data/test_package_generation/.github/workflows/linting.yml +++ b/tests/data/test_package_generation/.github/workflows/linting.yml @@ -13,11 +13,11 @@ jobs: - name: Checkout source uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 - - name: Cache pre-commit + - name: Cache prek uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 with: - path: ~/.cache/pre-commit - key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} + path: ~/.cache/prek + key: prek-${{ hashFiles('.pre-commit-config.yaml') }} - name: Set up python uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 @@ -27,7 +27,7 @@ jobs: cache-dependency-path: pyproject.toml - name: Install dependencies - run: python -m pip install pre-commit + run: python -m pip install prek - - name: Run pre-commit - run: pre-commit run --all-files --color always --verbose + - name: Run prek + run: prek run --all-files --color always --verbose diff --git a/tests/data/test_package_generation/README.md b/tests/data/test_package_generation/README.md index 32102cd9..77b805d2 100644 --- a/tests/data/test_package_generation/README.md +++ b/tests/data/test_package_generation/README.md @@ -1,6 +1,6 @@ # Cookiecutter Test -[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit) +[![prek](https://img.shields.io/badge/prek-enabled-brightgreen?logo=prek&logoColor=white)](https://github.com/j178/prek) [![Tests status][tests-badge]][tests-link] [![Linting status][linting-badge]][linting-link] [![Documentation status][documentation-badge]][documentation-link] diff --git a/tests/data/test_package_generation/pyproject.toml b/tests/data/test_package_generation/pyproject.toml index 327367af..92fbc13c 100644 --- a/tests/data/test_package_generation/pyproject.toml +++ b/tests/data/test_package_generation/pyproject.toml @@ -8,7 +8,7 @@ requires = [ [dependency-groups] dev = [ "build", - "pre-commit", + "prek", "ruff", "tox", "twine", diff --git a/{{cookiecutter.project_slug}}/.github/workflows/linting.yml b/{{cookiecutter.project_slug}}/.github/workflows/linting.yml index eb5e6018..e150f691 100644 --- a/{{cookiecutter.project_slug}}/.github/workflows/linting.yml +++ b/{{cookiecutter.project_slug}}/.github/workflows/linting.yml @@ -13,11 +13,11 @@ jobs: - name: Checkout source uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 - - name: Cache pre-commit + - name: Cache prek uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 with: - path: ~/.cache/pre-commit - key: pre-commit-${{ '{{' }} hashFiles('.pre-commit-config.yaml') {{ '}}' }} + path: ~/.cache/prek + key: prek-${{ '{{' }} hashFiles('.pre-commit-config.yaml') {{ '}}' }} - name: Set up python uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 @@ -27,7 +27,7 @@ jobs: cache-dependency-path: pyproject.toml - name: Install dependencies - run: python -m pip install pre-commit + run: python -m pip install prek - - name: Run pre-commit - run: pre-commit run --all-files --color always --verbose + - name: Run prek + run: prek run --all-files --color always --verbose diff --git a/{{cookiecutter.project_slug}}/README.md b/{{cookiecutter.project_slug}}/README.md index 53e0cfd7..cb3469a0 100644 --- a/{{cookiecutter.project_slug}}/README.md +++ b/{{cookiecutter.project_slug}}/README.md @@ -1,6 +1,6 @@ # {{cookiecutter.project_name}} -[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit) +[![prek](https://img.shields.io/badge/prek-enabled-brightgreen?logo=prek&logoColor=white)](https://github.com/j178/prek) [![Tests status][tests-badge]][tests-link] [![Linting status][linting-badge]][linting-link] [![Documentation status][documentation-badge]][documentation-link] diff --git a/{{cookiecutter.project_slug}}/pyproject.toml b/{{cookiecutter.project_slug}}/pyproject.toml index 433e5d89..2ee72ba0 100644 --- a/{{cookiecutter.project_slug}}/pyproject.toml +++ b/{{cookiecutter.project_slug}}/pyproject.toml @@ -8,7 +8,7 @@ requires = [ [dependency-groups] dev = [ "build", - "pre-commit", + "prek", "ruff", "tox", "twine", From 943e99f3d70eaf235ed692fd5bc7ce15013c41fd Mon Sep 17 00:00:00 2001 From: Patrick Roddy Date: Tue, 15 Sep 2026 13:34:22 +0100 Subject: [PATCH 2/2] Change `pre-commit` recommendations --- docs/pages/ci.md | 2 +- docs/pages/linting.md | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/pages/ci.md b/docs/pages/ci.md index 523fb7aa..b3aef31a 100644 --- a/docs/pages/ci.md +++ b/docs/pages/ci.md @@ -11,7 +11,7 @@ layout: default | [AppVeyor](https://www.appveyor.com/docs/) | Continuous integration and continuous delivery platform. | Good | | [Bamboo](https://confluence.atlassian.com/bamboo/bamboo-documentation-289276551.html) | Atlassian continuous integration and continuous delivery platform. | Good | | [Travis CI](https://docs.travis-ci.com/) | Continuous integration and continuous delivery platform. | Good | -| [pre-commit.ci](https://pre-commit.ci/) | A bot that adds a pre-commit job to your GitHub Actions CI, and can automatically fix most trivial linting failures. Free for open-source projects. | Best | +| [pre-commit.ci](https://pre-commit.ci/) | A bot that adds a pre-commit job to your GitHub Actions CI, and can automatically fix most trivial linting failures. Free for open-source projects. | Good |
Best explanation We have many projects using GitHub CI and, it has good integration with GitHub itself, and is free for public repositories (with limited free monthly minutes for private repositories). diff --git a/docs/pages/linting.md b/docs/pages/linting.md index 942179da..e426d7e6 100644 --- a/docs/pages/linting.md +++ b/docs/pages/linting.md @@ -13,7 +13,8 @@ for some of these. | Name | Short description | 🚦 | | ------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------: | -| [pre-commit](https://pre-commit.com/) | Universal tool which performs a git hook on commit, allows you to run linters/formatters on any code. A tool to automatically run many of the tools listed below. | Best | +| [prek](https://prek.j178.dev/) | A rust-powered improvement on `pre-commit`. Known for its friendlier community and feature rich implementation. | Best | +| [pre-commit](https://pre-commit.com/) | Universal tool which performs a git hook on commit, allows you to run linters/formatters on any code. A tool to automatically run many of the tools listed below. | Good | | [ruff-format](https://github.com/astral-sh/ruff) | A drop-in replacement for `black` (and also super fast). A nice "no-need to think" code formatter. If you have your own opinions about code style, you might not like this. | Best | | [ruff](https://github.com/astral-sh/ruff) | A fast linter which incorporates a range of other linters. Notably [isort](https://pycqa.github.io/isort/) can be included as a [ruff rule](https://docs.astral.sh/ruff/rules/) (which we recommend). | Best | | [toml-sort](https://github.com/pappasam/toml-sort) | Sorts TOML files which are now part of PEP 8. | Best |