-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.pre-commit-config.yaml
196 lines (177 loc) · 7 KB
/
.pre-commit-config.yaml
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
minimum_pre_commit_version: 4.0.1
# run `pre-commit autoupdate --freeze` to update all hooks
default_install_hook_types: [pre-commit, post-checkout]
repos:
# Git-related
- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 38980559e3a605691d6579f96222c30778e5a69e # frozen: 3.0.0
hooks:
- id: git-dirty
# package management
- repo: local
hooks:
- id: uv-check
name: check pyproject.toml for valid uv config
entry: bash -c 'uv lock --check'
language: system
pass_filenames: false
verbose: true
files: '^pyproject.toml$|^uv.lock$'
- id: sync-dependencies-on-commit
name: ensure python dependencies are up to date during commits
stages: [pre-commit]
# When the install does change things, it exits 0, so needed to check for the phrase 'operations' in stdout in order to cause things pre-commit command to fail
entry: python -c "import subprocess,sys; results=subprocess.run(['uv', 'sync', '--frozen'],timeout=360,capture_output=True); print ('stdout- ' + results.stdout.decode('utf-8', 'strict')); print ('stderr- ' + results.stderr.decode('utf-8', 'strict')); sys.exit(int(results.returncode or int('Installed' in results.stdout.decode('utf-8', 'strict'))));"
# don't pass filenames else the command line sees them twice
pass_filenames: false
language: system
files: 'uv.lock$'
verbose: true
- id: sync-dependencies-post-checkout
name: ensure python dependencies are up to date during checkouts
stages: [post-checkout]
entry: bash -c 'uv sync --frozen'
pass_filenames: false
language: system
always_run: true
verbose: true
# Reformatting (should generally come before any file format or other checks, because reformatting can change things)
- repo: https://github.com/crate-ci/typos
rev: b1b019a4372e6055cd23b7a8e299c56f9d522a94 # frozen: dictgen-v0.3.1
hooks:
- id: typos
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # frozen: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
# the XML formatter hook doesn't leave a blank line at the end, so excluding XML files from this hook to avoid conflicts
exclude: | # the extra trailing newline in the pull request template makes it easier to click there in the github console. The CLI that programmatically generates devcontainer-lock.json always ends the file incompatible with this hook.
(?x)^(
.github/pull_request_template.md|
template/.github/pull_request_template.md|
template/.copier-answers.yml.jinja-base|
template/template/.copier-answers.yml.jinja|
template/.copier-answers.yml.jinja|
.devcontainer/devcontainer-lock.json|
.copier-answers.yml|
.*\.xml|
)$
- id: pretty-format-json
exclude: |
(?x)^(
.devcontainer/devcontainer.json|
.devcontainer/devcontainer-lock.json|
.*devcontainer.json|
.*pyrightconfig.json|
)$
args: [--autofix, --no-sort-keys]
- repo: https://github.com/myint/docformatter
# black seems to be working on formatting docstrings, but use this for now
rev: eb1df347edd128b30cd3368dddc3aa65edcfac38 # tip of main that is compatible with pre-commit v4
hooks:
- id: docformatter
exclude: (tests*)|(exceptions\.py)|(warnings\.py)
args:
- --in-place
- --wrap-summaries=150
- --wrap-descriptions=150
- repo: https://github.com/pamoller/xmlformatter
rev: 47ae0fb9cf2a515f8a2666050fac66fd719ae530 # frozen: v0.2.8
hooks:
- id: xml-formatter
exclude: |
(?x)^(
.*/__snapshots__/.*|
)$
# Invalid File Checks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # frozen: v5.0.0
hooks:
- id: check-added-large-files
args: ['--maxkb=123']
exclude: (uv.lock)
- id: check-json
# exclude JSON5 or JSONC files with comments
exclude: |
(?x)^(
.devcontainer/devcontainer.json|
.devcontainer/devcontainer-lock.json|
.*devcontainer.json|
.*pyrightconfig.json|
)$
- id: check-yaml
exclude: .copier-answers.yml # This is an autogenerated YAML file by Copier that throws 'found unhashable key' errors
- id: check-xml
- id: check-merge-conflict
- id: check-case-conflict
- repo: https://github.com/maresb/check-json5
rev: 893a2b5a0a27c3540bd8fcafe2968ccc05237179 # 1.0
hooks:
- id: check-json5
files: |
(?x)^(
.devcontainer/devcontainer.json|
.devcontainer/devcontainer-lock.json|
.*devcontainer.json|
.*pyrightconfig.json|
)$
- repo: local
hooks:
- id: forbidden-files
name: forbidden files
entry: found copier update rejection files; review them and remove them
language: fail
files: "\\.rej$"
# Safety/Security Issues
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # frozen: v5.0.0
hooks:
- id: detect-private-key
# Linting
- repo: https://github.com/Lucas-C/pre-commit-hooks-markup
rev: 501f3d60cee13c712492103343bc23efdc7b3d1f #v1.0.1
hooks:
- id: rst-linter
# this hook fails on Sphinx documentation https://github.com/Lucas-C/pre-commit-hooks-markup/issues/13
exclude: docs/.*\.rst$
- repo: https://github.com/hadolint/hadolint
rev: c3dc18df7a501f02a560a2cc7ba3c69a85ca01d3 # frozen: v2.13.1-beta
hooks:
- id: hadolint-docker
name: Lint Dockerfiles
description: Runs hadolint to lint Dockerfiles
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 89c421dff2e1026ba12cdb9ebd731f4a83aa8021 # frozen: v0.8.6
hooks:
- id: ruff
name: ruff-src
args: [ --fix, --config=./ruff.toml ]
files: src/.+\.py$
- id: ruff
name: ruff-tests
args: [ --fix, --config=./ruff-test.toml ]
files: tests?/.+\.py$
- id: ruff-format
- repo: https://github.com/pylint-dev/pylint
rev: c28580be76fe1ec55a6cac41833c0bd68070d2f7 # frozen: v3.3.3
hooks:
- id: pylint
name: pylint
args:
- --rcfile=./pylintrc.toml
verbose: true
- repo: local
hooks:
- id: pyright
name: pyright
entry: bash -c "uv run pyright"
files: '.+\.py$'
# don't pass filenames else the command line sees them twice
pass_filenames: false
language: system
types: [python]
# use require_serial so that script is only called once per commit
require_serial: true
# print the number of files as a sanity-check
verbose: true