Repository navigation
Expand file tree
/
Copy path.pre-commit-config.yaml
More file actions
268 lines (266 loc) · 12.3 KB
/
Copy path.pre-commit-config.yaml
File metadata and controls
268 lines (266 loc) · 12.3 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
# Notes and scripts that never ship, kept out of every hook.
exclude: ^\.ai_discussions/
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
# protoc's output is checked in exactly as written, so no hook that rewrites or lints source
# touches it; the autogen-protos hook below holds it to the generator instead.
- id: trailing-whitespace
exclude: &generated ^couchbase/protocol/couchbase2/_generated/
- id: end-of-file-fixer
exclude: *generated
- id: check-yaml
args: [--allow-multiple-documents]
- id: check-added-large-files
- id: check-toml
- id: check-merge-conflict
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.6
hooks:
- id: clang-format
files: src/.*\.(cxx|hxx)$
exclude: ^deps/
- repo: https://github.com/hhatto/autopep8
# Same rule as mypy below: keep in step with `autopep8` in dev_requirements.txt. This
# hook rewrites files, so a skew means the gate reformats differently than local.
rev: v2.3.2
hooks:
- id: autopep8
exclude: ^(deps/|src/|couchbase/protocol/couchbase2/_generated/)
- repo: https://github.com/pycqa/flake8
rev: 5.0.4
hooks:
- id: flake8
exclude: |
(?x)^(
deps/|
src/|
simple_acouchbase.py|
simple_couchbase.py|
simple_txcouchbase.py|
couchbase_kv_tests.py|
examples/|
couchbase/protocol/couchbase2/_generated/
)
args:
[
--max-line-length=120,
--max-complexity=10
]
- repo: https://github.com/astral-sh/ruff-pre-commit
# Keep in step with `ruff` in dev_requirements.txt. Rules and scope are in [tool.ruff] in
# pyproject.toml, which selects only the annotation-syntax rules for now.
rev: v0.16.9
hooks:
- id: ruff-check
- repo: https://github.com/pre-commit/mirrors-mypy
# Keep this rev in step with `mypy` in dev_requirements.txt. The hook runs in its own
# isolated env, so a skew here means the gate enforces a different mypy than the one
# anyone runs locally, and the two can disagree on what passes.
rev: v2.3.1
hooks:
- id: mypy
# Scope, settings and per-module overrides all live in [tool.mypy] in
# pyproject.toml. Passing the four trees here as well would be redundant, but
# pre-commit hands the hook a list of changed files and mypy would then check
# only those, ignoring `files`. --config-file plus passing no filenames keeps
# every run checking the whole configured scope.
pass_filenames: false
args: [--config-file=pyproject.toml]
# mypy runs in its own isolated env, so anything it needs to import for types has
# to be repeated here; it cannot see dev_requirements.txt.
additional_dependencies:
- types-requests~=2.32
- types-grpcio~=1.84
- types-protobuf
- googleapis-common-protos
- certifi
- pytest~=8.3.5
- pytest-asyncio~=1.1
- Twisted~=24.7
- opentelemetry-api~=1.22
- opentelemetry-sdk~=1.22
- repo: local
hooks:
- id: mypy-fit-performer
name: mypy on the FIT performer, against its generated protobuf code
# A separate run from the gate above because the performer's protobuf code is generated,
# not committed: the script generates it from proto/ into a temporary directory and puts
# that on the search path, so the performer's own generated/ is never touched. The mypy
# pin follows the hook above. The generators and stubs are pinned exactly, apart from the
# performer's requirements.txt, because they decide what mypy sees; the venv that runs the
# performer may differ. mypy-protobuf stays on 3.6: 3.7.0 writes each service stub with a
# type variable per RPC, and mypy's overload checks grow with their product (mypy-protobuf
# issue 707), while 4.x needs a newer protobuf than the performer runs with. The rest is
# what the performer imports for types.
entry: tools/fit_performer/bin/typecheck.sh
language: python
additional_dependencies:
- mypy==2.3.1
- grpcio-tools==1.84.1
- mypy-protobuf==3.6.0
- types-protobuf==7.35.1.20260906
- types-grpcio==1.84.0.20261021
- types-psutil~=5.9.5
- 'typing-extensions>=4.14'
- Twisted~=24.7
- opentelemetry-api~=1.22
- opentelemetry-sdk~=1.22
- opentelemetry-exporter-otlp-proto-grpc~=1.22
pass_filenames: false
files: ^(tools/fit_performer/|pyproject\.toml$|(a|tx)?couchbase/.*\.py$)
- repo: local
hooks:
- id: audit-type-ignores
name: audit type-ignore suppressions in the test trees
# mypy enforces that the annotations are right; this enforces that the escapes
# from them stay accountable. Every `# type: ignore` in the test trees has
# to name its error code, and has to carry the PYCBC key that will retire it
# unless it is permanent. Rationale and the allowlist of permanent ones are in
# the module docstring.
entry: python tools/audit_type_ignores.py
language: python
# The script walks the configured trees itself. Passing changed filenames would
# let a suppression added in one commit hide behind a later commit that does not
# touch that file.
pass_filenames: false
files: ^(tests/|(a|tx)?couchbase/tests/|tools/audit_type_ignores\.py)
- id: check-type-comments
name: no type comments in the SDK packages
# Rationale in the module docstring.
entry: python tools/check_type_comments.py
language: python
pass_filenames: false
files: ^((a|tx)?couchbase/.*\.py|tools/check_type_comments\.py)$
- id: check-protocol-free-tests
name: shared tests do not reach into the classic protocol
# A test that runs on every protocol may not import classic or its binding, or read an
# object's executor, stream or connection, unless it is declared classic-only.
# Rationale in the module docstring.
entry: python tools/check_protocol_free_tests.py
language: python
pass_filenames: false
files: ^(tests/|(a|tx)?couchbase/tests/|tools/check_protocol_free_tests\.py)
- id: check-binding-free-imports
name: modules outside classic import without the native extension, against a baseline
# Each module is imported in an interpreter that refuses the package's extensions, so it
# needs what the modules import at load: typing-extensions below 3.13, Twisted for
# txcouchbase, the OpenTelemetry API for `couchbase.otel_tracer`, and grpcio, the
# `google.rpc` messages and certifi for couchbase2. A module that fails for want of one is
# reported as unchecked, not passed. Rationale in the module docstring.
entry: python tools/check_binding_free_imports.py
language: python
additional_dependencies: ['typing-extensions>=4.14', 'Twisted~=24.7', 'opentelemetry-api~=1.22',
'grpcio>=1.71.2', 'googleapis-common-protos', 'certifi']
pass_filenames: false
files: ^((a|tx)?couchbase/.*\.py|tools/check_binding_free_imports\.py|tools/binding_free_imports_baseline\.txt)$
- id: check-api-parity
name: the three public APIs agree on their facades, against a list of explained differences
# Imports the facades, so it needs what they import at load, as the hook above does.
# Rationale in the module docstring.
entry: python tools/check_api_parity.py
language: python
additional_dependencies: ['typing-extensions>=4.14', 'Twisted~=24.7']
pass_filenames: false
files: ^((a|tx)?couchbase/.*\.py|tools/check_api_parity\.py|tools/api_parity_exemptions\.txt)$
- id: check-public-api
name: every public module's __all__ and bindings agree with the public inventory
# Imports every public module, so it needs what they import at load, as the hooks above do,
# the OpenTelemetry API included. Rationale in the module docstring.
entry: python tools/check_public_api.py
language: python
additional_dependencies: ['typing-extensions>=4.14', 'Twisted~=24.7', 'opentelemetry-api~=1.22', 'PyYAML~=6.0']
pass_filenames: false
files: ^((a|tx)?couchbase/.*\.py|examples/.*\.py|tools/check_public_api\.py|tools/public_api\.yaml)$
- id: check-capabilities
name: every capability is declared, checked and reached through require()
# Reads source only, so it needs nothing installed. Rationale in the module docstring.
entry: python tools/check_capabilities.py
language: python
pass_filenames: false
files: ^((a|tx)?couchbase/.*\.py|tools/check_capabilities\.py|tools/check_api_parity\.py)$
- id: check-license-headers
name: every source file carries the license header, and a changed one the current year
# Rewrites what fails, as autopep8 does, so the commit stops for the rewrite to be staged.
# It reads the staged files itself to know which have changed. Rationale in the module
# docstring.
entry: python tools/check_license_headers.py --fix
language: python
pass_filenames: false
files: (\.(py|pyi|sh|cxx|hxx)|(^|/)CMakeLists\.txt|Dockerfile)$
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
exclude: |
(?x)^(
deps/|
src/|
examples/txcouchbase/|
couchbase/protocol/couchbase2/_generated/
)
args:
[
"--multi-line 1",
"--force-grid-wrap 3",
"--use-parentheses True",
"--ensure-newline-before-comments True",
"--line-length 120",
"--order-by-type True"
]
- repo: local
hooks:
- id: autogen-operations
name: operations table against the Op enum it generates
entry: python -m tools.autogen operations check
language: python
additional_dependencies: [click, jinja2, pyyaml]
pass_filenames: false
files: ^(tools/autogen/(cli\.py|(config|templates|core|commands)/operations[./])|couchbase/common/_operations\.py$)
- id: autogen-protos
name: Protostellar against the code generated from it
# Downloads the pinned schema and builds a venv for the pinned grpcio-tools on the first
# run, both into ~/.cache/pycbc-autogen; later runs are offline. Rationale in the docstring
# of tools/autogen/core/protos.py.
entry: python -m tools.autogen protos check
language: python
additional_dependencies: [click, jinja2, pyyaml]
pass_filenames: false
files: ^(tools/autogen/(cli\.py|(config|core|commands)/protos[./])|couchbase/protocol/couchbase2/_generated/)
- repo: local
hooks:
- id: docgen
name: API reference pages against the public inventory and the docs layout
entry: python -m tools.docgen check
language: python
# Imports every documented module to choose each name's directive, so it needs what they
# import at load, as check-public-api does. No native binding: the generator does not read it.
additional_dependencies: [click, jinja2, pyyaml, 'typing-extensions>=4.14', 'Twisted~=24.7',
'opentelemetry-api~=1.22']
pass_filenames: false
files: ^((a|tx)?couchbase/.*\.py|tools/docgen/|tools/check_public_api\.py|tools/public_api\.yaml|docs/reference/)
- repo: https://github.com/PyCQA/bandit
rev: 1.7.9
hooks:
- id: bandit
exclude: |
(?x)^(
deps/|
src/|
acouchbase/tests/|
txcouchbase/tests/|
couchbase/tests/|
tests/|
tools/|
simple_acouchbase.py|
simple_couchbase.py|
simple_txcouchbase.py|
couchbase_kv_tests.py|
couchbase_version.py|
couchbase/protocol/couchbase2/_generated/
)
args:
[
--quiet
]