Skip to content

Commit 7d794bd

Browse files
authored
Swap out references to pre-commit with prek (#645)
This PR removes the repos reliance on `pre-commit` in favour of `prek`. `prek` is faster, has a welcoming community, and is the future of linting. `prek` supports `.pre-commit-config.yaml` so no need to change anything really, and in the future we could consider moving towards its custom `prek.toml` format. As part of this work I have uninstalled @pre-commit-ci. We weren't configuring it any more (i.e. no `ci:` block in `.pre-commit-config.yaml`) and it was causing bugs #644. Fixes #644.
1 parent f8cdc4d commit 7d794bd

11 files changed

Lines changed: 42 additions & 41 deletions

File tree

‎.github/workflows/linting.yml‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,50 @@ jobs:
1414
- name: Checkout source
1515
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
1616

17-
- name: Cache pre-commit
17+
- name: Cache prek
1818
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
1919
with:
20-
path: ~/.cache/pre-commit
21-
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
20+
path: ~/.cache/prek
21+
key: prek-${{ hashFiles('.pre-commit-config.yaml') }}
2222

2323
- name: Set up python
2424
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
2525
with:
2626
python-version: "3.x"
2727

2828
- name: Install dependencies
29-
run: python -m pip install pre-commit
29+
run: python -m pip install prek
3030

31-
- name: Run pre-commit
32-
run: pre-commit run --all-files --color always --verbose
31+
- name: Run prek
32+
run: prek run --all-files --color always --verbose
3333

3434
lint-the-template:
3535
runs-on: ubuntu-latest
3636
steps:
3737
- name: Checkout source
3838
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
3939

40-
- name: Cache pre-commit
40+
- name: Cache prek
4141
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
4242
with:
43-
path: ~/.cache/pre-commit
44-
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
43+
path: ~/.cache/prek
44+
key: prek-${{ hashFiles('.pre-commit-config.yaml') }}
4545

4646
- name: Set up python
4747
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
4848
with:
4949
python-version: "3.x"
5050

5151
- name: Install dependencies
52-
run: python -m pip install cookiecutter pre-commit
52+
run: python -m pip install cookiecutter prek
5353

5454
- name: Create template
5555
run: cookiecutter . --no-input --output-dir cookie-template
5656

57-
- name: Run pre-commit
57+
- name: Run prek
5858
run: |-
5959
git add .
60-
pre-commit run --all-files --color always --verbose
60+
prek run --all-files --color always --verbose
6161
working-directory: cookie-template/python-template
6262

6363
lint-prose:

‎CONTRIBUTING.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ To contribute a change, please:
2626

2727
1. Create a new branch (or fork if you're not in [@UCL-ARC/collaborations]).
2828
2. Modify an existing page, create a new one, or tweak the template. a. Run
29-
[pre-commit] which will lint your changes. b. Check
30-
the tests pass if you modified the template (`pytest -s`).
29+
[prek] which will lint your changes. b. Check the tests pass if you modified
30+
the template (`pytest -s`).
3131
3. Open a _pull request_ (PR) with changes.
3232
4. Ask someone who did not contribute to the PR from [@UCL-ARC/collaborations]
3333
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.
9090
[open an issue]: https://github.com/UCL-ARC/python-tooling/issues/new/choose
9191
[Discussions tab]: https://github.com/UCL-ARC/python-tooling/discussions
9292
[Research software engineers]: https://society-rse.org/about/history
93-
[pre-commit]: https://pre-commit.com
93+
[prek]: https://prek.j178.dev
9494
[@UCL-ARC/collaborations]: https://github.com/orgs/UCL-ARC/teams/collaborations
9595
[@UCL-ARC/collaborations-python-tooling]: https://github.com/orgs/UCL-ARC/teams/collaborations-python-tooling
9696
[uv tool]: https://docs.astral.sh/uv/guides/tools

‎docs/pages/ci.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ layout: default
1111
| [AppVeyor](https://www.appveyor.com/docs/) | Continuous integration and continuous delivery platform. | <span class="label label-yellow">Good</span> |
1212
| [Bamboo](https://confluence.atlassian.com/bamboo/bamboo-documentation-289276551.html) | Atlassian continuous integration and continuous delivery platform. | <span class="label label-yellow">Good</span> |
1313
| [Travis CI](https://docs.travis-ci.com/) | Continuous integration and continuous delivery platform. | <span class="label label-yellow">Good</span> |
14-
| [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. | <span class="label label-green">Best</span> |
14+
| [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. | <span class="label label-yellow">Good</span> |
1515

1616
<details><summary> <span class="label label-green">Best</span> explanation</summary><!-- markdownlint-disable-line MD033 -->
1717
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).

‎docs/pages/linting.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ for some of these.
1313

1414
| Name | Short description | 🚦 |
1515
| ------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------: |
16-
| [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. | <span class="label label-green">Best</span> |
16+
| [prek](https://prek.j178.dev/) | A rust-powered improvement on `pre-commit`. Known for its friendlier community and feature rich implementation. | <span class="label label-green">Best</span> |
17+
| [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. | <span class="label label-yellow">Good</span> |
1718
| [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. | <span class="label label-green">Best</span> |
1819
| [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). | <span class="label label-green">Best</span> |
1920
| [toml-sort](https://github.com/pappasam/toml-sort) | Sorts TOML files which are now part of PEP 8. | <span class="label label-green">Best</span> |

‎docs/pages/tutorial.md‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -396,33 +396,33 @@ tox -e docs
396396
from the root of the project repository.
397397
The built documentation will be output to a directory `site`.
398398

399-
## ✅ Using `pre-commit` to run checks when committing
399+
## ✅ Using `prek` to run checks when committing
400400

401-
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.
401+
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.
402402

403403
There is a `.pre-commit-config.yaml` configuration file which you can take a look at.
404-
With this setup `pre-commit` will run a series of fast linters, checks and formatters on the repository on every commit.
404+
With this setup `prek` will run a series of fast linters, checks and formatters on the repository on every commit.
405405

406406
The main tools we recommend are [ruff](https://docs.astral.sh/ruff/), [ty](https://docs.astral.sh/ty/) and [prettier](https://prettier.io/).
407407
These Git hook scripts can be installed locally by running
408408

409409
```sh
410-
pre-commit install
410+
prek install
411411
```
412412

413413
from the root of the project repository.
414414
You will only need to do this once per `git clone` of the code.
415415

416416
Once installed, the scripts will be called to inspect the changes each time `git commit` is run.
417417
Any failures of the checks will need to be fixed before the changes can be committed.
418-
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.
418+
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.
419419

420420
The hooks typically only run on the files _changed_ in a commit.
421-
The `pre-commit` hooks can be run against _all files in the repository_ by running
421+
The `prek` hooks can be run against _all files in the repository_ by running
422422

423423
```sh
424-
pre-commit run --all-files
424+
prek run --all-files
425425
```
426426

427427
from the root of the project repository.
428-
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).
428+
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).

‎tests/data/test_package_generation/.github/workflows/linting.yml‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ jobs:
1313
- name: Checkout source
1414
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
1515

16-
- name: Cache pre-commit
16+
- name: Cache prek
1717
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
1818
with:
19-
path: ~/.cache/pre-commit
20-
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
19+
path: ~/.cache/prek
20+
key: prek-${{ hashFiles('.pre-commit-config.yaml') }}
2121

2222
- name: Set up python
2323
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
@@ -27,7 +27,7 @@ jobs:
2727
cache-dependency-path: pyproject.toml
2828

2929
- name: Install dependencies
30-
run: python -m pip install pre-commit
30+
run: python -m pip install prek
3131

32-
- name: Run pre-commit
33-
run: pre-commit run --all-files --color always --verbose
32+
- name: Run prek
33+
run: prek run --all-files --color always --verbose

‎tests/data/test_package_generation/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Cookiecutter Test
22

3-
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
3+
[![prek](https://img.shields.io/badge/prek-enabled-brightgreen?logo=prek&logoColor=white)](https://github.com/j178/prek)
44
[![Tests status][tests-badge]][tests-link]
55
[![Linting status][linting-badge]][linting-link]
66
[![Documentation status][documentation-badge]][documentation-link]

‎tests/data/test_package_generation/pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ requires = [
88
[dependency-groups]
99
dev = [
1010
"build",
11-
"pre-commit",
11+
"prek",
1212
"ruff",
1313
"tox",
1414
"twine",

‎{{cookiecutter.project_slug}}/.github/workflows/linting.yml‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ jobs:
1313
- name: Checkout source
1414
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
1515

16-
- name: Cache pre-commit
16+
- name: Cache prek
1717
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
1818
with:
19-
path: ~/.cache/pre-commit
20-
key: pre-commit-${{ '{{' }} hashFiles('.pre-commit-config.yaml') {{ '}}' }}
19+
path: ~/.cache/prek
20+
key: prek-${{ '{{' }} hashFiles('.pre-commit-config.yaml') {{ '}}' }}
2121

2222
- name: Set up python
2323
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
@@ -27,7 +27,7 @@ jobs:
2727
cache-dependency-path: pyproject.toml
2828

2929
- name: Install dependencies
30-
run: python -m pip install pre-commit
30+
run: python -m pip install prek
3131

32-
- name: Run pre-commit
33-
run: pre-commit run --all-files --color always --verbose
32+
- name: Run prek
33+
run: prek run --all-files --color always --verbose

‎{{cookiecutter.project_slug}}/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# {{cookiecutter.project_name}}
22

3-
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
3+
[![prek](https://img.shields.io/badge/prek-enabled-brightgreen?logo=prek&logoColor=white)](https://github.com/j178/prek)
44
[![Tests status][tests-badge]][tests-link]
55
[![Linting status][linting-badge]][linting-link]
66
[![Documentation status][documentation-badge]][documentation-link]

0 commit comments

Comments
 (0)