Skip to content

Commit b5c95d4

Browse files
authored
docs: mention prek (#696)
* docs: mention prek Signed-off-by: Henry Schreiner <[email protected]> * chore: support running with prek Signed-off-by: Henry Schreiner <[email protected]> * fix: also mention prek in the CONTRIBUTING.md Signed-off-by: Henry Schreiner <[email protected]> * chore: move noxfiles to using prek Signed-off-by: Henry Schreiner <[email protected]> --------- Signed-off-by: Henry Schreiner <[email protected]>
1 parent 86eba41 commit b5c95d4

File tree

6 files changed

+51
-26
lines changed

6 files changed

+51
-26
lines changed

.prekignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/*cookiecutter*/

docs/pages/guides/style.md

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,39 @@ custom_title: Style and static checks
1313

1414
## Pre-commit
1515

16-
{% rr PY006 %} Scientific Python projects often use [pre-commit][] to check code
17-
style. It can be installed through `brew` (macOS) or `pip` (anywhere). There are
18-
two modes to use it locally; you can check manually with `pre-commit run`
19-
(changes only) or `pre-commit run --all-files` (all). You can also run
16+
{% rr PY006 %} Scientific Python projects often use [pre-commit][] (or [prek][])
17+
to check code style. The original, `pre-commit`, has support for more languages,
18+
but `prek` is a faster Rust rewrite that supports most real world usage.
19+
20+
{% tabs runner %} {% tab pre-commit Pre-commit %}
21+
22+
Pre-commit can be installed through `brew` (macOS) or `pipx/uv` (anywhere).
23+
There are two modes to use it locally; you can check manually with
24+
`pre-commit run` (changes only) or `pre-commit run -a` (all). You can also run
2025
`pre-commit install` to add checks as a git pre-commit hook (which is where it
21-
gets its name). It's worth trying, even if you've tried and failed to set up a
22-
custom pre-commit hook before; it's quite elegant and does not add or commit the
23-
changes, it just makes the changes and allows you to check and add them. You can
24-
always override the hook with `-n`.
26+
gets its name).
27+
28+
Pre-commit's setup is much slower than prek, but you can install `pre-commit-uv`
29+
with pre-commit to speed up the setup time quite a bit.
30+
31+
{% endtab %} {% tab prek Prek %}
32+
33+
Prek can be installed through `brew` (macOS) or `pipx/uv` (anywhere). There are
34+
two modes to use it locally; you can check manually with `prek run` (hanges
35+
only) or `prek run -a` (all). You can omit the `run`, as well; such as
36+
`prek -a`. You can also run `prek install` to add checks as a git pre-commit
37+
hook.
38+
39+
{% endtab %} {% endtabs %}
40+
41+
Local runs (with `-a`) are the standard way to use it. That will run all the
42+
checks in optimized, isolated environments. After the first run, it's quite fast
43+
(either pre-commit or prek).
44+
45+
It's worth trying the install command, even if you've tried and failed to set up
46+
a custom pre-commit hook before; it's quite elegant and does not add or commit
47+
the changes, it just makes the changes and allows you to check and add them. You
48+
can always override the hook with `-n`.
2549

2650
[pre-commit]: https://pre-commit.com
2751

docs/pages/guides/tasks.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ will likely look similar across different projects:
170170

171171
#### Lint
172172

173-
Ideally, all developers should be using pre-commit directly, but this helps new
174-
users.
173+
Ideally, all developers should be using pre-commit or prek directly, but this
174+
helps new users.
175175

176176
<!-- [[[cog
177177
with code_fence("python"):
@@ -184,9 +184,9 @@ def lint(session: nox.Session) -> None:
184184
"""
185185
Run the linter.
186186
"""
187-
session.install("pre-commit")
187+
session.install("prek")
188188
session.run(
189-
"pre-commit", "run", "--all-files", "--show-diff-on-failure", *session.posargs
189+
"prek", "run", "--all-files", "--show-diff-on-failure", *session.posargs
190190
)
191191
```
192192
<!-- prettier-ignore-end -->

noxfile.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,15 @@ def diff_files(p1: Path, p2: Path) -> bool:
202202
@nox.parametrize("vcs", [False, True], ids=["novcs", "vcs"])
203203
@nox.parametrize("backend", BACKENDS, ids=BACKENDS)
204204
def lint(session: nox.Session, backend: str, vcs: bool, docs: Docs) -> None:
205-
session.install("cookiecutter", "pre-commit")
205+
session.install("cookiecutter", "prek")
206206

207207
tmp_dir = session.create_tmp()
208208
session.cd(tmp_dir)
209209
cookie = make_cookie(session, backend, vcs, docs)
210210
session.chdir(cookie)
211211

212212
session.run(
213-
"pre-commit",
213+
"prek",
214214
"run",
215215
"--all-files",
216216
"--hook-stage=manual",
@@ -221,14 +221,14 @@ def lint(session: nox.Session, backend: str, vcs: bool, docs: Docs) -> None:
221221
@nox.session(default=False)
222222
@nox.parametrize("backend", BACKENDS, ids=BACKENDS)
223223
def autoupdate(session: nox.Session, backend: str) -> None:
224-
session.install("cookiecutter", "pre-commit")
224+
session.install("cookiecutter", "prek")
225225

226226
tmp_dir = session.create_tmp()
227227
session.cd(tmp_dir)
228228
cookie = make_cookie(session, backend, True, Docs.Sphinx)
229229
session.chdir(cookie)
230230

231-
session.run("pre-commit", "autoupdate")
231+
session.run("prek", "autoupdate")
232232
session.run("git", "diff", "--exit-code", external=True)
233233

234234

@@ -419,14 +419,14 @@ def compare_cruft(session):
419419
@nox.session(reuse_venv=True, default=False)
420420
def pc_bump(session: nox.Session) -> None:
421421
"""
422-
Bump the pre-commit versions.
422+
Bump the prek versions.
423423
"""
424424
session.install("lastversion>=3.4")
425425
versions = {}
426426
pages = [
427427
Path("docs/pages/guides/style.md"),
428-
Path("{{cookiecutter.project_name}}/.pre-commit-config.yaml"),
429-
Path(".pre-commit-config.yaml"),
428+
Path("{{cookiecutter.project_name}}/.prek-config.yaml"),
429+
Path(".prek-config.yaml"),
430430
]
431431

432432
for page in pages:
@@ -548,8 +548,8 @@ def rr_lint(session: nox.Session) -> None:
548548
"""
549549
Run the linter.
550550
"""
551-
session.install("pre-commit")
552-
session.run("pre-commit", "run", "--all-files", *session.posargs)
551+
session.install("prek")
552+
session.run("prek", "run", "--all-files", *session.posargs)
553553

554554

555555
@nox.session
@@ -558,7 +558,7 @@ def rr_pylint(session: nox.Session) -> None:
558558
Run Pylint.
559559
"""
560560
# This needs to be installed into the package environment, and is slower
561-
# than a pre-commit check
561+
# than a prek check
562562
session.install("-e.[cli]", "pylint")
563563
session.run("pylint", "src", *session.posargs)
564564

{{cookiecutter.project_name}}/.github/CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ uv sync
3535

3636
# Pre-commit
3737

38-
You should prepare pre-commit, which will help you by checking that commits pass
39-
required checks:
38+
You should prepare pre-commit or prek, which will help you by checking that
39+
commits pass required checks:
4040

4141
```bash
4242
uv tool install pre-commit # or brew install pre-commit on macOS

{{cookiecutter.project_name}}/noxfile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ def lint(session: nox.Session) -> None:
2020
"""
2121
Run the linter.
2222
"""
23-
session.install("pre-commit")
23+
session.install("prek")
2424
session.run(
25-
"pre-commit", "run", "--all-files", "--show-diff-on-failure", *session.posargs
25+
"prek", "run", "--all-files", "--show-diff-on-failure", *session.posargs
2626
)
2727

2828

0 commit comments

Comments
 (0)