Skip to content

Commit ae056af

Browse files
authored
Clarify priority scope across repos (#1251)
1 parent 6a55318 commit ae056af

File tree

2 files changed

+52
-12
lines changed

2 files changed

+52
-12
lines changed

docs/configuration.md

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ For more details and examples, see [Workspace Mode - File Processing Behavior](w
8989

9090
Each hook can set an explicit `priority` (a non-negative integer) that controls when it runs and with which hooks it may execute in parallel.
9191

92+
Scope:
93+
94+
- `priority` is evaluated **within a single `.pre-commit-config.yaml`** and is compared across **all hooks in that file**, even if they appear under different `repos:` entries.
95+
- `priority` does **not** coordinate across different `.pre-commit-config.yaml` files. In workspace mode (nested projects), each project’s config file is scheduled independently.
96+
9297
Hooks run in ascending priority order: **lower `priority` values run earlier**. Hooks that share the same `priority` value run concurrently, subject to the global concurrency limit (defaults to the number of CPU cores; set `PREK_NO_CONCURRENCY=1` to force concurrency to `1`).
9398

9499
When `priority` is omitted, prek automatically assigns the hook a value equal to its index in the configuration file, preserving the original sequential behavior.
@@ -105,24 +110,43 @@ repos:
105110
entry: python3 -m ruff format
106111
always_run: true
107112
priority: 0 # runs first
108-
- id: lint-py
109-
name: Python Lint
110-
language: system
111-
entry: python3 -m ruff check
112-
always_run: true
113-
priority: 10 # runs in parallel with lint-sh
113+
114+
# No explicit priority: automatically assigned based on position.
115+
# In this example it is the next hook in the file, so it gets priority=1.
114116
- id: lint-sh
115117
name: Shell Lint
116118
language: system
117119
entry: shellcheck
118120
always_run: true
119-
priority: 10 # shares group with lint-py
121+
122+
# These two hooks are defined under different repos, but share the same
123+
# priority value, so they can run concurrently.
124+
- repo: https://github.com/astral-sh/ruff-pre-commit
125+
rev: v0.8.4
126+
hooks:
127+
- id: ruff
128+
name: Python Lint
129+
args: [--fix]
130+
always_run: true
131+
priority: 10
132+
133+
- repo: local
134+
hooks:
135+
- id: lint-py
136+
name: Python Lint (alt)
137+
language: system
138+
entry: python3 -m ruff check
139+
always_run: true
140+
priority: 10
141+
142+
- repo: local
143+
hooks:
120144
- id: tests
121145
name: Integration Tests
122146
language: system
123147
entry: just test
124148
always_run: true
125-
priority: 20 # starts after both lint hooks finish
149+
priority: 20 # starts after the priority=10 group completes
126150
```
127151

128152
If a hook must be completely isolated, give it a unique priority value so no other hook can join its group.

docs/proposals/concurrency.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ When `priority` is omitted, the scheduler assigns the hook a priority equal to i
2626

2727
Execution is driven purely by priority numbers:
2828

29+
### Scope
30+
31+
`priority` is **global within a single configuration file**. That is, priorities are compared across **all hooks in the same `.pre-commit-config.yaml`**, even if the hooks live under different `repos:` entries.
32+
33+
`priority` does **not** apply across *different* `.pre-commit-config.yaml` files (or separate `prek` runs with different configs). Each config file is scheduled independently.
34+
2935
1. **Ordering**: Hooks run from the lowest priority value to the highest.
3036
2. **Concurrency**: Hooks that share the same priority execute concurrently, subject to the global concurrency limit (default: number of CPUs).
3137
3. **Defaults**: Without explicit priorities, each hook receives a unique priority derived from its position, so execution remains sequential and backwards-compatible.
@@ -46,6 +52,8 @@ The existing `require_serial` configuration key often causes confusion. In this
4652

4753
Implicit priorities are always derived from the hook's position in the configuration (0-based), regardless of any explicitly configured priorities on other hooks.
4854

55+
Positions are taken from the **fully flattened hook list for the current `.pre-commit-config.yaml`**, in the order hooks appear as `repos:` and `hooks:` are read. In other words, implicit priorities are assigned across the whole file, not per-repo.
56+
4957
Example:
5058

5159
* Hook at index `0` with no `priority` gets implicit priority `0`.
@@ -86,23 +94,31 @@ repos:
8694
name: Format Rust
8795
entry: cargo fmt
8896
language: system
89-
priority: 0 # Earliest priority, runs first
97+
priority: 0 # Runs first
9098
99+
# These hooks are in different repos, but share the same priority,
100+
# so they can run concurrently.
101+
- repo: local
102+
hooks:
91103
- id: ruff
92104
name: Lint Python
93105
entry: ruff check
94106
language: system
95-
priority: 10 # Same number means concurrent execution
107+
priority: 10
96108
109+
- repo: local
110+
hooks:
97111
- id: shellcheck
98112
name: Lint Shell
99113
entry: shellcheck
100114
language: system
101-
priority: 10 # Runs parallel with ruff
115+
priority: 10
102116
117+
- repo: local
118+
hooks:
103119
- id: integration-tests
104120
name: Integration Tests
105121
entry: just test
106122
language: system
107-
priority: 20 # Starts after the lint group completes
123+
priority: 20 # Starts after priority=10 group completes
108124
```

0 commit comments

Comments
 (0)