Repository navigation
Expand file tree
/
Copy path.pre-commit-config.yaml
More file actions
115 lines (107 loc) · 4.51 KB
/
Copy path.pre-commit-config.yaml
File metadata and controls
115 lines (107 loc) · 4.51 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
ci:
autoupdate_schedule: monthly
autofix_prs: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
# tests/data/ holds byte-exact API response captures (TSV/RDB with
# significant trailing tabs, plus pinned JSON). Skip whitespace and
# EOL normalization there so we don't silently change fixture bytes.
- id: trailing-whitespace
exclude: ^tests/data/
- id: end-of-file-fixer
exclude: ^tests/data/
- id: mixed-line-ending
exclude: ^tests/data/
- id: check-docstring-first
- id: check-json
- id: check-yaml
- id: debug-statements
- repo: local
hooks:
- id: doubled-word
name: doubled word
language: pygrep
entry: \b([A-Za-z]+)[ \t]+\1\b
types: [text]
exclude: ^tests/data/
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.16.5
hooks:
- id: ruff-check
args: [--fix]
- id: ruff-format
# Type-check with mypy --strict (config lives in pyproject [tool.mypy]).
# Pinned to the same major as CI's `mypy<2`. httpx/anyio are installed into
# the isolated hook env so their types resolve — without them mypy falls back
# to `Any` and mis-reports (the runtime deps aren't in the hook's venv).
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.20.2
hooks:
- id: mypy
pass_filenames: false
additional_dependencies: [httpx, anyio]
# Complexity ratchet. Thresholds are the tightest the package currently
# passes, so this holds the line rather than demanding a refactor: no block
# above rank C (cyclomatic complexity 20), no module below B, average at A.
# Tightening a letter is a deliberate commit, and the failure names the
# offending block, so the fix is local. Applied to the package only --
# tests legitimately contain long, branchy fixtures.
- repo: https://github.com/rubik/xenon
rev: v0.9.3
hooks:
- id: xenon
# The package path is in args, not passed by pre-commit: --max-average
# and --max-modules are whole-package judgements, and computing them
# over only the changed files would let the average drift upward one
# commit at a time. ``files`` decides whether to run, not what to scan.
args:
- "--max-absolute"
- "C"
- "--max-modules"
- "B"
- "--max-average"
- "A"
- "dataretrieval"
files: ^dataretrieval/.*\.py$
pass_filenames: false
# Cognitive-complexity ratchet, the counterpart to xenon's cyclomatic one.
# The two measure different things: xenon counts branches, complexipy counts
# how hard the control flow is to hold in your head, so nesting and early
# exits weigh differently. 25 is the package's current maximum
# (``nwis._read_json``), so this holds the line rather than demanding a
# refactor. Unlike xenon this one is per-function, so scanning only the
# changed files gives the same verdict CI gives for the whole package.
- repo: https://github.com/rohaquinlop/complexipy-pre-commit
rev: v6.2.0
hooks:
- id: complexipy
files: ^dataretrieval/.*\.py$
# Dependency-direction contracts (ADR 0003, 0005, 0006, 0007). Complements
# tests/architecture_test.py, which enforces named pairwise claims by parsing
# the AST; this checks the whole layer stack over the *transitive* graph, so
# a service reaching transport through OGC fails here. Runs in about a
# second. Declared as a local hook rather than using the upstream one, which
# is ``language: system`` and so needs lint-imports already on PATH.
- repo: local
hooks:
- id: import-linter
name: import-linter
description: Enforce the dependency layers declared in .importlinter
entry: lint-imports
language: python
additional_dependencies: ["import-linter==2.13"]
# Reads the package tree from the repo root, not a file list; grimp
# resolves ``dataretrieval`` relative to the working directory, so the
# hook needs neither the package nor its runtime deps installed.
pass_filenames: false
files: ^(dataretrieval/.*\.py|\.importlinter)$
# Strip cell outputs + execution_count from notebooks on commit so the
# diff is the source, not the rendered run. Demos still execute fine
# locally; clean commits keep PRs reviewable and avoid quota/timestamp
# churn on every re-run.
- repo: https://github.com/kynan/nbstripout
rev: 0.8.1
hooks:
- id: nbstripout