Skip to content

Commit 3606afd

Browse files
jbamptonpaulirwin
andauthored
ci(performance): add prek hook priorities for parallel execution (apache#1379)
Co-authored-by: Paul Irwin <paulirwin@gmail.com>
1 parent 3fe4c42 commit 3606afd

1 file changed

Lines changed: 46 additions & 2 deletions

File tree

.pre-commit-config.yaml

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,50 @@
1616
# under the License.
1717

1818
---
19-
# https://pre-commit.com/#installation
19+
# prek-style priority keys enables prek to run independent hooks in parallel, improving pre-commit check times.
20+
# The priority values are assigned to structure the hook execution into logical stages, ensuring correct ordering of
21+
# file modifications and maximum concurrency of read-only checks.
22+
23+
# Priority Levels: Hooks can be assigned different priority numbers. Hooks with a priority of 0 (or a higher numerical
24+
# value, depending on configuration) run first or alongside other zero-priority hooks to decrease total end-to-end
25+
# execution time.
26+
27+
# Priority Groups and Ordering Design
28+
29+
# | Stage / Priority | Hooks | Rationale |
30+
# |---|---|---|
31+
# | **Priority 10** | `identity`, `check-hooks-apply` | **Meta & Setup**: Ensure environment is valid before executing heavy checks. |
32+
# | **Priority 20** | `fix-byte-order-marker` | **File Cleanups (Broad)**: Fix BOM first so subsequent steps work with clean UTF-8 text. |
33+
# | **Priority 30** | `trailing-whitespace` | **Formatting (Broad)**: Cleans up whitespace on files before other hooks validate them. |
34+
# | **Priority 40** | `doctoc`, `oxipng`, `file-contents-sorter` | **Disjoint Modifiers**: These modify different sets of files (`README.md`, `.png` files, and `codespell.txt` respectively). Running them concurrently is safe. |
35+
# | **Priority 50** | `codespell`, `check-ast`, `check-builtin-literals`, `check-case-conflict`, `check-executables-have-shebangs`, `check-illegal-windows-names`, `check-json`, `check-merge-conflict`, `check-vcs-permalinks`, `check-xml`, `check-yaml`, `debug-statements`, `detect-aws-credentials`, `detect-private-key`, `forbid-submodules`, `gitleaks`, `bandit`|
36+
# | | **Read-Only / Syntax / Security**: The bulk of the suite. These hooks only read and validate files without modifying them, allowing full parallel execution. |
37+
38+
# https://prek.j178.dev/installation/
2039
default_stages: [pre-commit, pre-push]
2140
default_language_version:
2241
# force all unspecified Python hooks to run python3
2342
python: python3
24-
minimum_pre_commit_version: '3.2.0'
43+
minimum_prek_version: '0.3.4'
2544
repos:
2645
- repo: meta
2746
hooks:
2847
- id: identity
2948
name: run identity check
3049
description: check you have set your git identity
50+
priority: 10
3151
- id: check-hooks-apply
3252
name: run check hooks apply
3353
description: check that all the hooks apply to the repository
54+
priority: 10
3455
- repo: https://github.com/thlorenz/doctoc.git
3556
rev: 59dcae910a6ad4bbe8711275b854e3cd5c30f08b # frozen: v2.5.0
3657
hooks:
3758
- id: doctoc
3859
name: add TOC for Markdown files
3960
description: automatically keeps your table of contents up to date
4061
files: ^README\.md$
62+
priority: 40
4163
- repo: https://github.com/codespell-project/codespell
4264
rev: 2ccb47ff45ad361a21071a7eedda4c37e6ae8c5a # frozen: v2.4.2
4365
hooks:
@@ -46,13 +68,15 @@ repos:
4668
description: check spelling with codespell
4769
exclude: ^src/Lucene\.Net\.Analysis\.Common/Analysis/../.*\.rslp$|^.*Lucene\.Net\.Tests.*$
4870
args: [--ignore-words=.github/linters/codespell.txt]
71+
priority: 50
4972
- repo: https://github.com/oxipng/oxipng
5073
rev: 628e241e23f368097883807fa6e985ccf7c00357 # frozen: v10.1.1
5174
hooks:
5275
- id: oxipng
5376
name: run oxipng
5477
description: check PNG files with oxipng
5578
args: [ '--fix', '-o', '4', '--strip', 'safe', '--alpha' ]
79+
priority: 40
5680
- repo: https://github.com/pre-commit/pre-commit-hooks
5781
rev: 3e8a8703264a2f4a69428a0aa4dcb512790b2c8c # frozen: v6.0.0
5882
hooks:
@@ -61,63 +85,81 @@ repos:
6185
description: trims trailing whitespace
6286
files: \.(bat|config|json|md|props|ps1|rdf|targets|tmpl|xml|ya?ml)$
6387
args: [--markdown-linebreak-ext=md]
88+
priority: 30
6489
- id: check-ast
6590
name: run check-ast
6691
description: check Python files for syntax errors
92+
priority: 50
6793
- id: check-builtin-literals
6894
name: run check-builtin-literals
6995
description: check Python files for proper use of built-in literals
96+
priority: 50
7097
- id: check-case-conflict
7198
name: run check-case-conflict
7299
description: check for case conflicts in file names
100+
priority: 50
73101
- id: check-executables-have-shebangs
74102
name: run check-executables-have-shebangs
75103
description: check that executable scripts have shebang lines
104+
priority: 50
76105
- id: check-illegal-windows-names
77106
name: run check-illegal-windows-names
78107
description: check for Windows-illegal file names
108+
priority: 50
79109
- id: check-json
80110
name: run check-json
81111
description: check JSON files for syntax errors
112+
priority: 50
82113
- id: check-merge-conflict
83114
name: run check-merge-conflict
84115
description: check for merge conflict markers
116+
priority: 50
85117
- id: check-vcs-permalinks
86118
name: run check-vcs-permalinks
87119
description: ensures that links to vcs websites are permalinks
120+
priority: 50
88121
- id: check-xml
89122
name: run check-xml
90123
description: attempts to load all xml files to verify syntax
124+
priority: 50
91125
- id: check-yaml
92126
name: run check-yaml
93127
description: attempts to load all yaml files to verify syntax
128+
priority: 50
94129
- id: debug-statements
95130
name: run debug-statements
96131
description: check for debugger imports and py37+ `breakpoint()` calls in python source.
132+
priority: 50
97133
- id: detect-aws-credentials
98134
name: run detect-aws-credentials
99135
description: checks for the existence of AWS secrets that you have set up with the AWS CLI
100136
args: [--allow-missing-credentials]
137+
priority: 50
101138
- id: detect-private-key
102139
name: run detect-private-key
103140
description: checks for the existence of private keys
141+
priority: 50
104142
- id: file-contents-sorter
105143
name: run file-contents-sorter
106144
description: sort the lines in specified files (defaults to alphabetical)
107145
args: [--unique]
108146
files: ^\.github/linters/codespell\.txt$
147+
priority: 40
109148
- id: forbid-submodules
110149
name: run forbid-submodules
111150
description: forbids any submodules in the repository
151+
priority: 50
112152
- id: fix-byte-order-marker
113153
name: run fix-byte-order-marker
114154
description: fixes files with UTF-8 byte order markers
155+
priority: 20
115156
- repo: https://github.com/gitleaks/gitleaks
116157
rev: 83d9cd684c87d95d656c1458ef04895a7f1cbd8e # frozen: v8.30.1
117158
hooks:
118159
- id: gitleaks
119160
name: run gitleaks
120161
description: check for secrets with gitleaks
162+
priority: 50
121163
- repo: https://github.com/PyCQA/bandit
122164
rev: 92ae8b82fb422a639f0ed8d99e96cea769594e08 # frozen: 1.9.4
123165
hooks:
@@ -126,6 +168,7 @@ repos:
126168
description: check Python code for security issues
127169
args: ['-c=pyproject.toml']
128170
additional_dependencies: ['bandit[toml]']
171+
priority: 50
129172
- repo: https://github.com/igorshubovych/markdownlint-cli
130173
rev: a4d5d37e66ebcd6b3705204a1d6dbb56dea66338 # frozen: v0.49.0
131174
hooks:
@@ -136,3 +179,4 @@ repos:
136179
exclude: ^\.github/.*$
137180
types: [markdown]
138181
files: \.md$
182+
priority: 50

0 commit comments

Comments
 (0)