@@ -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 %} {% 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
0 commit comments