|
| 1 | +fail_fast: true |
| 2 | +# Restrict hooks to the pre-commit stage by default so they don't also fire at |
| 3 | +# prepare-commit-msg / commit-msg (which are installed for the DCO hooks below). |
| 4 | +# The two DCO hooks override this with their own explicit `stages:`. |
| 5 | +default_stages: [pre-commit] |
| 6 | +repos: |
| 7 | + # Config-file validators run first: ruff loads its config from pyproject.toml, |
| 8 | + # so a malformed pyproject.toml makes ruff itself abort with a parser error |
| 9 | + # instead of the clean check-toml message. With fail_fast, running check-toml / |
| 10 | + # check-yaml before ruff means syntax errors are reported by the validator that |
| 11 | + # exists for that purpose, consistently between local commits and CI --all-files. |
| 12 | + - repo: https://github.com/pre-commit/pre-commit-hooks |
| 13 | + rev: v5.0.0 |
| 14 | + hooks: |
| 15 | + - id: check-toml |
| 16 | + - id: check-yaml |
| 17 | + - id: check-merge-conflict |
| 18 | + # --assume-in-merge makes the hook scan even when no merge is in |
| 19 | + # progress. Without it the hook returns early unless .git/MERGE_HEAD |
| 20 | + # exists, so it would be a no-op in CI's `pre-commit run --all-files` |
| 21 | + # (a clean checkout is never mid-merge). This lets CI catch conflict |
| 22 | + # markers that were committed (e.g. via --no-verify). |
| 23 | + args: [--assume-in-merge] |
| 24 | + - id: check-added-large-files |
| 25 | + # --enforce-all checks every file, not just staged additions, so the |
| 26 | + # hook also runs in CI's `pre-commit run --all-files` (a clean checkout |
| 27 | + # has nothing staged, so without this it would be a no-op there). |
| 28 | + # uv.lock is intentionally large (~2.3 MB) and excluded. |
| 29 | + args: [--maxkb=500, --enforce-all] |
| 30 | + exclude: ^uv\.lock$ |
| 31 | + - id: check-case-conflict |
| 32 | + - id: mixed-line-ending |
| 33 | + args: [--fix=lf] |
| 34 | + - id: end-of-file-fixer |
| 35 | + exclude: \.ipynb$ |
| 36 | + - id: trailing-whitespace |
| 37 | + exclude: \.ipynb$ |
| 38 | + |
| 39 | + - repo: https://github.com/astral-sh/ruff-pre-commit |
| 40 | + rev: v0.9.0 |
| 41 | + hooks: |
| 42 | + - id: ruff-format |
| 43 | + args: [--config=pyproject.toml] |
| 44 | + - id: ruff |
| 45 | + args: [--exit-non-zero-on-fix, --fix, --config=pyproject.toml] |
| 46 | + |
| 47 | + - repo: local |
| 48 | + hooks: |
| 49 | + - id: check-headers |
| 50 | + name: Check SPDX headers |
| 51 | + entry: python ci/check_headers.py |
| 52 | + language: system |
| 53 | + args: [--fix] |
| 54 | + files: '^(src|tests)/.*\.py$' |
| 55 | + pass_filenames: true |
| 56 | + |
| 57 | + - id: add-signoff |
| 58 | + name: Add DCO sign-off |
| 59 | + entry: python ci/add_signoff.py |
| 60 | + language: system |
| 61 | + stages: [prepare-commit-msg] |
| 62 | + |
| 63 | + - id: check-dco |
| 64 | + name: Check DCO sign-off |
| 65 | + entry: python ci/check_dco.py |
| 66 | + language: system |
| 67 | + stages: [commit-msg] |
| 68 | + |
| 69 | + - id: validate-links |
| 70 | + name: Validate links and first-party imports |
| 71 | + entry: python .pre-commit/validate_links.py |
| 72 | + language: system |
| 73 | + pass_filenames: false |
| 74 | + always_run: true |
| 75 | + files: \.(ipynb|md|py)$ |
| 76 | + |
| 77 | + - repo: https://github.com/kynan/nbstripout |
| 78 | + rev: 0.8.1 |
| 79 | + hooks: |
| 80 | + - id: nbstripout |
| 81 | + |
| 82 | + - repo: https://github.com/astral-sh/uv-pre-commit |
| 83 | + rev: 0.8.4 |
| 84 | + hooks: |
| 85 | + - id: uv-lock |
0 commit comments