Repository navigation
Expand file tree
/
Copy path.pre-commit-config.yaml
More file actions
322 lines (322 loc) · 13.9 KB
/
Copy path.pre-commit-config.yaml
File metadata and controls
322 lines (322 loc) · 13.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
---
# Parser and transport fixtures retain the exact bytes their manifests describe.
exclude: ^tests/regime_finder/((examples|source_fixtures)/.*\.py\.txt$|data/)
repos:
- repo: meta
hooks:
- id: check-hooks-apply
- id: check-useless-excludes
- repo: https://github.com/tox-dev/pyproject-fmt
rev: v2.30.3
hooks:
- id: pyproject-fmt
- repo: https://github.com/lyz-code/yamlfix
rev: 1.19.1
hooks:
- id: yamlfix
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: check-added-large-files
args:
- --maxkb=10000
- id: check-ast
language_version: python3.14
- id: check-case-conflict
- id: check-docstring-first
- id: check-merge-conflict
- id: check-toml
- id: check-vcs-permalinks
- id: check-yaml
- id: debug-statements
language_version: python3.14
- id: end-of-file-fixer
- id: fix-byte-order-marker
types:
- text
- id: mixed-line-ending
args:
- --fix=lf
description: Forces to replace line ending by the UNIX 'lf' character.
- id: name-tests-test
args:
- --pytest-test-first
exclude: tests/mock_regime.py|tests/collective_fixtures.py|tests/envelope_configs.py|^tests/test_models/|^tests/data/|^tests/egm/_|^tests/execution/_|^tests/params/_|^tests/regime_building/_|^tests/solution/_|^tests/simulation/_|^tests/simulation/initial_conditions/_|^tests/ci/|^tests/candidate_certificate/|^tests/conformance_solver/|^tests/regime_finder/(?!test_).*\.py$
- id: no-commit-to-branch
args:
- --branch
- main
- id: trailing-whitespace
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.38.0
hooks:
- id: yamllint
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.39.0
hooks:
- id: check-github-workflows
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.17.3
hooks:
- id: ruff-check
args:
- --fix
types_or:
- jupyter
- pyi
- python
- id: ruff-check
alias: test-signature-annotations
name: changed test signatures are annotated
# A changed test file must have complete signatures. Keep this on the
# push range so untouched legacy files do not block all-files formatting.
stages:
- pre-push
files: ^tests/.*\.py$
args:
- --select=ANN
- --ignore=ANN401
- --config
- lint.per-file-ignores = {}
- id: ruff-format
# Keep the imported checker source stable for comparison with its reviewed
# implementation. Its directory has a separate Ruff lint configuration.
exclude: ^src/_lcm_regime_finder/(?!implicit/)
types_or:
- jupyter
- pyi
- python
- repo: https://github.com/astral-sh/ty-pre-commit
rev: v0.0.95
hooks:
- id: ty
# Run ty directly so import resolution uses `[tool.ty] environment.python`.
# Keep this dependency pin aligned with the hook revision above.
entry: ty check
additional_dependencies:
- ty==0.0.95
- repo: https://github.com/kynan/nbstripout
rev: 0.9.1
hooks:
- id: nbstripout
args:
- --extra-keys
- metadata.language_info.version metadata.vscode
- repo: https://github.com/codespell-project/codespell
rev: v2.4.3
hooks:
- id: codespell
additional_dependencies:
- tomli
- repo: https://github.com/executablebooks/mdformat
rev: 1.0.0
hooks:
- id: mdformat
additional_dependencies:
- mdformat-gfm
- mdformat-gfm-alerts
- mdformat-ruff
args:
- --wrap
- '88'
files: (AGENTS\.md|README\.md)
- id: mdformat
additional_dependencies:
- mdformat-myst
- mdformat-ruff
args:
- --wrap
- '88'
files: (docs/.)
# mdformat-myst rewrites any MyST directive into escaped literal text: it
# escapes the opening brace and collapses the block onto one line. Every
# page carrying a directive is therefore excluded, or its admonitions and
# grids would render as `:::\{important}` prose.
exclude: |
(?x)^docs/(
index
|reference/solvers
|user_guide/choosing_a_solver
|examples/precautionary_savings_health
|examples/mahler_yum_2024
)\.md$
- repo: local
hooks:
# Runs at pre-commit stage and fails if the config declares pre-push hooks
# that this clone never installed — otherwise they look active and silently
# never fire.
- id: pre-push-hooks-installed
name: pre-push hooks are installed in this clone
entry: .ai-instructions/hooks/check_pre_push_installed.py
language: script
pass_filenames: false
always_run: true
# The candidate certificate pins every certified source by digest in two
# files, the generated inventory and the hand-maintained seal map. An edit
# under `src/` that leaves them stale fails the certificate tests on every
# CI platform and nowhere earlier; this check takes well under a second
# and names the `--fix` that reseals both. Exit 2 means the drift is an
# AST corridor pin instead, which `repin_corridors.py` re-anchors for the
# sources whose edit was intended; see docs/development/certification.md.
- id: candidate-certificate-seals
name: candidate certificate seals match the tree
entry: pixi run python tests/candidate_certificate/check_seals.py
language: system
pass_filenames: false
files: ^(src/.*\.py|tests/candidate_certificate/.*|tests/test_grid_search_candidate_certificate\.py)$
- id: candidate-certificate-anchors
name: candidate certificate mutation anchors resolve once
entry: >-
pixi run -e tests-cpu python
tests/candidate_certificate/check_mutation_anchors.py
language: system
pass_filenames: false
files: ^(src/.*\.py|tests/candidate_certificate/.*|tests/test_simulation_candidate_program_certificate\.py)$
# `--check` re-solves and compares without writing, so it cannot dirty the
# worktree. pre-push, not pre-commit: a mid-branch commit may legitimately
# lag the lock, but a push with a stale lock burns a CI cycle.
- id: pixi-lock-check
name: pixi.lock is in sync with the manifest
entry: pixi lock --check
language: system
pass_filenames: false
files: ^(pyproject\.toml|pixi\.toml|pixi\.lock)$
stages:
- pre-push
- id: ci-workload-manifest-format
name: CI workload manifest has canonical bytes
entry: pixi run -e tests-cpu python -m tests.ci.ci_workloads canonicalize
language: system
pass_filenames: false
files: ^tests/ci/ci-workloads\.json$
# Shard weights come only from CI. On every commit this fills in the
# weights the `workload-weights` CI gate names as missing in
# tests/ci/ci-workloads.json, from the latest completed CPU run of the
# branch's open pull request that measured each file, and stages the
# file. Existing weights are never rewritten, and with nothing missing it
# looks nothing up. No pull request, no completed run, or no network
# leaves the file unchanged and prints why; it never fails a commit.
- id: ci-workload-weights
name: shard weights are refreshed from the last CI run
entry: pixi run -e tests-cpu python -m tests.ci.workload_weights refresh
language: system
pass_filenames: false
always_run: true
verbose: true
- id: notebook-cell-source-format
name: notebook cell source is a JSON array of lines
entry: .ai-instructions/hooks/fix_notebook_cell_source.py
language: script
types:
- jupyter
- id: keyword-only-convention
name: functions with two named arguments are keyword-only
entry: pixi run -e type-checking python -m tests.ci.keyword_only_convention
language: system
exclude: ^(src/_lcm_regime_finder|tests/regime_finder)/
types_or:
- python
- jupyter
- markdown
# One invocation sees every file, so its closing summary counts the whole run.
- id: precise-annotations
name: annotations name precise types
entry: pixi run -e type-checking python -m tests.ci.precise_annotations
language: system
files: ^((src|tests|benchmarks)/.*\.py|docs/.*\.ipynb)$
exclude: ^src/_lcm_regime_finder/
require_serial: true
# Whole-repository analysis: a change in one file can orphan code in another.
- id: dead-code
name: no internal or test code without a caller
entry: pixi run -e type-checking python -m tests.ci.dead_code
language: system
pass_filenames: false
files: ^(src|tests|benchmarks|tools|docs|acceptance)/.*\.py$|^tests/ci/dead-code-allowlist\.toml$
- id: no-hardcoded-user-paths
name: no hardcoded user-specific absolute paths
language: pygrep
entry: (/home/[A-Za-z0-9_.-]+/|/Users/[A-Za-z0-9_.-]+/|[A-Za-z]:\\Users\\)
types_or:
- python
- toml
# Gates the bare ruler only — a comment line that is nothing but fill
# characters. A titled `# --- Section ---`, a ruler under ten fill
# characters, and a ruler in a notebook or a Markdown file all stay a
# review responsibility; docstring underlines carry no `#` and are not
# in scope.
#
# Override, where a ruler earns its place: state the reason on the ruler
# line itself, e.g. `# ---- 8< ---- everything below is generated`. The
# line stops being decoration and the reason lands in the diff, so the
# override is self-documenting. `SKIP=no-section-separator-comments git
# commit …` also works but drops the hook from the run *without printing
# a line for it*, leaving no record; if you use it, put the reason in the
# commit message.
- id: no-section-separator-comments
name: no decorative section-separator comments
language: pygrep
entry: ^\s*#\s*[-=#_*]{10,}\s*$
types:
- python
# A custom JVP that reads its tangents is not *automatically*
# transposable, and JAX says so: "Transpose rule ... not implemented".
# That is a missing rule, not a missing transpose — the differential of a
# finite affine segment is linear and its transpose is the coefficient
# vector, and bit-level scaling by a power of two is the same linear map
# as multiplying by it. Documenting the refusal as a mathematical
# impossibility has been written and corrected repeatedly, so the claim
# is gated here rather than left to review.
#
# Say what is true instead: "carries no transpose rule", "no reverse rule
# is registered", "not automatically transposable" — all of which pass.
# A map that genuinely has no transpose is nonlinear, and saying which
# nonlinearity rewrites the sentence anyway. `SKIP=no-impossible-transpose
# git commit …` drops the hook without printing a line for it, so put the
# reason in the commit message if you use it.
#
# Line-scoped, like its siblings: a claim split across two lines by the
# formatter is not caught and stays a review responsibility.
- id: no-impossible-transpose
name: no claim that a linear map has no transpose
language: pygrep
entry: (?i:\b(?:has|have|had)\s+no\s+transpose\b(?!\s+rule))|(?i:\b(?:does|do|did)\s+not\s+have\s+an?\s+transpose\b)|(?i:\bnothing\s+to\s+transpose\b)|(?i:\bnone\s+to\s+transpose\b)|(?i:\bno\s+map\s+to\s+transpose\b)
types_or:
- python
- markdown
# Catches the labelled forms only — PR/issue numbers, `E<n>`/`F<n>`
# finding labels, `round-<n>`, `pre-fix`. Prose that rehearses history
# without a label stays a review responsibility.
- id: no-internal-references
name: no references a reader cannot reach from the checkout
language: pygrep
entry: (?:^|[\s(\[])\#[0-9]{2,5}\b(?!\.[0-9])|(?i:\b(?:round|wave)-[0-9]+\b)|(?i:\b(?:audit|review|finding|witness|defect|bug|fix|guard)\s+)(?:finding\s+)?[EF][0-9]{1,2}\b|\b[EF][0-9]{1,2}(?i:\s+(?:fix|guard|bug|defect|witness|signature|regression|finding|audit)\b)|(?:^|\s)\((?:the\s+)?(?!(?:F8|F16|F32|F64)\b)[EF][0-9]{1,2}['’]?(?:\s*[,/]\s*[EF][0-9]{1,2}['’]?)*(?:[,)\s])|(?i:\b(?:pre|post)-fix\b)
types:
- python
ci:
autoupdate_schedule: monthly
# pre-commit.ci has no pixi environments and blocks network at hook runtime;
# the GitHub Actions run-ty job covers type checking and the keyword-only and
# precise-annotation conventions, while pixi-lock-check needs a pixi binary
# that pre-commit.ci does not provide.
# CPU manifest contract tests also check canonical bytes; the local fixing
# hook requires Pixi and therefore runs only in developer clones.
#
# The two script hooks live in the `.ai-instructions` submodule, which
# pre-commit.ci does not check out, so there they fail as a missing
# executable rather than running. `pre-push-hooks-installed` asks about the
# local clone and is meaningless on a runner anyway; the notebook check does
# lose CI coverage and holds only where the submodule is present, which is
# every developer clone and no CI job here.
skip:
- candidate-certificate-seals
- candidate-certificate-anchors
- keyword-only-convention
- precise-annotations
- dead-code
- ty
- pixi-lock-check
- ci-workload-manifest-format
- ci-workload-weights
- pre-push-hooks-installed
- notebook-cell-source-format