forked from Checkmk/checkmk
-
Notifications
You must be signed in to change notification settings - Fork 3
/
pyproject.toml
396 lines (379 loc) · 13.4 KB
/
pyproject.toml
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
[tool.ruff]
extend-exclude = ["agents/plugins/mk_sap_2.py", "doc/**/*.py"]
target-version = "py312"
line-length = 100
[tool.ruff.lint]
select = ["E", "F", "I", "W", "C90", "PL", "UP"]
ignore = [
# Black is our formatting tool, so ignore any formatting-related findings.
"E501", # line too long
# Ignore findings which are incompatible with our "import" techonology.
"F401", # 'FOO' imported but unused
"E402", # module level import not at top of file
"F403", # 'from FOO import *' used; unable to detect undefined names
"F405", # 'FOO' may be undefined, or defined from star imports: BAR
# We should probably have a look at these findings.
"E731", # do not assign a lambda expression, use a def
"E741", # ambiguous variable name 'FOO'
# pylint doesn't complain about these
"PLC0414", # Import alias does not rename original package
"PLR0911", # Too many return statements
"PLR0912", # Too many branches
"PLR0913", # Too many arguments in function definition
"PLR0915", # Too many statements
"PLR2004", # Magic value used in comparison, consider replacing `FOO` with a constant variable
"PLR2044", # Line with empty comment
"PLW0603", # Using the global statement to update `FOO` is discouraged
"PLW2901", # `for` loop variable `FOO` overwritten by assignment target
# Basically a TODO list...
"UP004", # Class `_MockHttpResponse` inherits from `object`
"UP006", # Use `collections.defaultdict` instead of `DefaultDict` for type annotation
"UP007", # Use `X | Y` for type annotations
"UP009", # UTF-8 encoding declaration is unnecessary
"UP010", # Unnecessary `__future__` import `with_statement` for target Python version
"UP012", # Unnecessary call to `encode` as UTF-8
"UP015", # Unnecessary open mode parameters
"UP017", # Use `datetime.UTC` alias
"UP024", # Replace aliased errors with `OSError`
"UP025", # Remove unicode literals from strings
"UP026", # `mock` is deprecated, use `unittest.mock`
"UP028", # Replace `yield` over `for` loop with `yield from`
"UP031", # Use format specifiers instead of percent format
"UP032", # Use f-string instead of `format` call
"UP035", # Import from `FOO` instead: `BAR`
"UP036", # Version block is outdated for minimum Python version
"UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)`
"UP040", # Type alias `FOO` uses `TypeAlias` annotation instead of the `type` keyword
"UP041", # Replace aliased errors with `TimeoutError`
]
[tool.ruff.lint.mccabe]
max-complexity = 64 # TODO: This is far too much, we need to lower this!
[tool.ruff.lint.isort]
# combine-as-imports = true # This would arguably be nicer.
known-first-party = ["cmk"]
order-by-type = false # TODO: Why do we actually want this?
section-order = [
"future",
"standard-library",
"third-party",
"werks",
"cmc_proto",
"testlib",
"integrationtests",
"compositiontests",
"unittests",
"livestatus",
"omd",
"cmk_ccc",
"cmk_utils",
"cmk_events",
"cmk_automations",
"cmk_snmplib",
"cmk_fetchers",
"cmk_checkengine",
"cmk_base",
"cmk_ec",
"cmk_gui",
"cmk_cee",
"cmk_notification_plugins",
"first-party",
"local-folder",
]
[tool.ruff.lint.isort.sections]
werks = ["werks"]
cmc_proto = ["cmc_proto"]
testlib = ["tests.testlib"]
integrationtests = ["tests.integration"]
compositiontests = ["tests.composition"]
unittests = ["tests.unit", "tests.plugins_integration", "tests.update"]
livestatus = ["livestatus"]
omd = ["omdlib"]
cmk_ccc = ["cmk.ccc"]
cmk_events = ["cmk.events"]
cmk_utils = ["cmk.utils"]
cmk_automations = ["cmk.automations"]
cmk_snmplib = ["cmk.snmplib"]
cmk_fetchers = ["cmk.fetchers"]
cmk_checkengine = ["cmk.checkengine"]
cmk_base = ["cmk.base"]
cmk_ec = ["cmk.ec"]
cmk_gui = ["cmk.gui"]
cmk_cee = ["cmk.cee.dcd", "cmk.cee.liveproxy", "cmk.cee.mknotifyd"]
cmk_notification_plugins = ["cmk.notification_plugins"]
# NOTE: Keep this is sync with mypy-raw.ini!
# The number of errors/files below are just a snapshot to give a rough idea. In
# addition, a single cause can imply multiple symptoms, so these numbers have to
# be taken with a grain of salt...
[tool.mypy]
# Global options.
# Add per-module options as [[tool.mypy.overrides]].
explicit_package_bases = true
# TODO: `mypy_path` shouldn't be required with Bazel.
mypy_path = """\
$MYPY_CONFIG_FILE_DIR:\
$MYPY_CONFIG_FILE_DIR/non-free/cmc-protocols:\
$MYPY_CONFIG_FILE_DIR/non-free/cmk-update-agent:\
$MYPY_CONFIG_FILE_DIR/livestatus/api/python:\
$MYPY_CONFIG_FILE_DIR/omd/packages/omd:\
$MYPY_CONFIG_FILE_DIR/tests/typeshed:\
$MYPY_CONFIG_FILE_DIR/packages/cmk-trace\
"""
plugins = ["pydantic.mypy"]
python_version = "3.12"
scripts_are_modules = true
# do not descend into 3rd party dependencies
follow_imports = "silent"
follow_imports_for_stubs = true
# hidden flags for PEP 688 compat, see https://github.com/python/mypy/issues/15313
disable_bytearray_promotion = true
disable_memoryview_promotion = true
# global options enabled with strict
check_untyped_defs = true
warn_redundant_casts = true
warn_unused_configs = true
[[tool.mypy.overrides]]
module = [
# active_checks
"check_sql",
"check_elasticsearch_query",
"check_bi_aggr",
"check_uniserv",
"check_form_submit",
"check_notify_count",
"agents.modules.windows.tests.integration.conftest",
"agents.plugins.*",
# agents/special/*
"agent_activemq",
"agent_alertmanager",
"agent_allnet_ip_sensoric",
"agent_appdynamics",
"agent_aws",
"agent_aws_status",
"agent_azure",
"agent_azure_status",
"agent_bi",
"agent_cisco_meraki",
"agent_cisco_prime",
"agent_couchbase",
"agent_datadog",
"agent_ddn_s2a",
"agent_elasticsearch",
"agent_emcvnx",
"agent_gcp",
"agent_gcp_status",
"agent_graylog",
"agent_hivemanager",
"agent_hivemanager_ng",
"agent_hp_msa",
"agent_ibmsvc",
"agent_innovaphone",
"agent_ipmi_sensors",
"agent_jira",
"agent_jolokia",
"agent_kube",
"agent_mobileiron",
"agent_mqtt",
"agent_netapp_ontap",
"agent_prism",
"agent_prometheus",
"agent_proxmox_ve",
"agent_pure_storage_fa",
"agent_rabbitmq",
"agent_random",
"agent_ruckus_spot",
"agent_salesforce",
"agent_siemens_plc",
"agent_smb_share",
"agent_splunk",
"agent_storeonce",
"agent_storeonce4x",
"agent_tinkerforge",
"agent_ucs_bladecenter",
"agent_vnx_quotas",
"agent_vsphere",
"agent_zerto",
"agents.wnx.tests.*",
"buildscripts.*",
"cmk.*",
"cmk_update_agent",
# omd/packages/maintenance
"diskspace",
"doc.*",
# doc/*
"foo.check",
"import-memory",
"figheader",
#
"logdate",
"omd.*",
"omdlib.*",
"scripts.create_build_environment_variables",
"tests.*",
# tests/agent-plugin-unit/*
"test_apache_status",
"test_mk_filestats",
"test_mk_jolokia",
"test_mk_logwatch",
"test_mk_mongodb",
"test_mk_postgres",
"test_mk_sap",
"test_mtr",
"test_plesk_backups",
"test_plesk_domains",
]
enable_error_code = [
# "explicit-override", # 9999 errors in 762 files
"ignore-without-code",
# "mutable-override", # 336 errors in 71 files
# "possibly-undefined", # 401 errors in 183 files
# "redundant-expr", # 115 errors in 86 files
"redundant-self",
"truthy-bool",
"truthy-iterable",
"unimported-reveal",
"unused-awaitable",
"unused-ignore",
]
# When all of these are true, we can enable --strict
disallow_any_generics = false # 1904 errors in 507 files
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = false # 6427 errors in 1077 files
disallow_untyped_decorators = true
disallow_untyped_defs = false # 6738 errors in 1571
extra_checks = true
no_implicit_reexport = true
strict_equality = true
warn_return_any = false # 622 errors in 267 files
warn_unused_ignores = true
# Miscellaneous stuff not in --strict
disallow_any_decorated = false # 3433 errors in 997 files
disallow_any_explicit = false # 2854 errors in 836 files
disallow_any_expr = false # 112427 errors in 3304 files
disallow_any_unimported = false # 291 errors in 46 files
no_implicit_optional = true
strict_optional = true
warn_unreachable = false # 240 errors in 133 files
[[tool.mypy.overrides]]
module = [
"cmk.active_checks.check_sftp",
"cmk.cee.bakery.*",
"cmk.gui.background_job.*",
"cmk.gui.mobile.views",
"cmk.gui.views.layout.*",
"cmk.gui.wato.pages.bulk_discovery",
"cmk.gui.wato.pages.bulk_edit",
"cmk.gui.wato.pages.folders",
"cmk.gui.wato.pages.parentscan",
"cmk.gui.watolib.auth_php",
"cmk.gui.watolib.bulk_discovery",
"cmk.gui.watolib.config_sync",
"cmk.gui.watolib.main_menu",
"cmk.gui.watolib.network_scan",
"cmk.gui.watolib.registration",
"cmk.notification_plugins.*",
"cmk.update_config.*",
"cmk.utils.livestatus_helpers.*",
"tests.gui_e2e.*",
"tests.unit.cmk.ec.*",
"tests.unit.cmk.update_config.*",
]
disallow_untyped_calls = true
disallow_untyped_defs = true
warn_return_any = true
warn_unused_ignores = true
[[tool.mypy.overrides]]
module = ["cmk.gui.form_specs.*"]
disallow_any_generics = true
[[tool.mypy.overrides]]
module = ["cmk.ec.*"]
disallow_any_generics = true
disallow_untyped_calls = true
disallow_untyped_defs = true
warn_unreachable = true
[[tool.mypy.overrides]]
module = "cmk.agent_based.*"
strict = true
enable_error_code = [
"explicit-override",
"ignore-without-code",
"mutable-override",
"possibly-undefined",
# Needs to be investigated
# "redundant-expr",
"redundant-self",
"truthy-bool",
"truthy-iterable",
"unimported-reveal",
"unused-awaitable",
"unused-ignore",
]
# Miscellaneous stuff not in --strict
disallow_any_decorated = true
disallow_any_explicit = true
disallow_any_expr = true
disallow_any_generics = true
disallow_any_unimported = true
disallow_subclassing_any = true
no_implicit_optional = true
strict_optional = true
warn_unreachable = true
[tool.pydantic-mypy]
init_forbid_extra = true
init_typed = true
warn_required_dynamic_aliases = true
warn_untyped_fields = true
[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = [
# Live logs initially look like a good idea to pin down problems in the tests
# quickly, but with the current state of our tests it's simply too much noise.
# Even in a successful unit test run, you get more than 70 log messages
# cluttering up the output and making it hard to use: saml2.client logs already
# at load time, tons of our own tests emit warnings up to ERROR even when
# successful, etc. etc. We might reconsinder lowering the live log level when we
# have cleaned up things...
"--log-cli-level=CRITICAL",
"--log-cli-format=%(asctime)s %(levelname)s %(message)s",
# Show summary of skipped tests
"-rs",
# Show N slowest setup/test durations
"--durations=20",
# Disable a few plugins which slow down the pytest startup even when not used
"-p no:faker",
"-p no:schemathesis",
"-p no:hypothesispytest",
]
markers = [
"checks: Run all existing test cases for checks.",
"slow: Run tests which take relatively larger time to execute.",
]
# See: https://docs.python.org/3/library/warnings.html#the-warnings-filter
filterwarnings = [
# Breaking change, only in new major version, see https://github.com/marshmallow-code/apispec/pull/759
'ignore:^distutils Version classes are deprecated\. Use packaging.version instead\.$:DeprecationWarning:apispec.utils:0',
# Internal copy of distutils in setuptools :-P
'ignore:^distutils Version classes are deprecated\. Use packaging.version instead\.$:DeprecationWarning:distutils.version:0',
# We have a doctest which intentionally checks for a failure
'ignore:^Invalid value for tag-group tag_agent. None$:UserWarning:cmk.gui.fields.definitions:0',
# Make marshmallow warnings errors, otherwise typos may go unnoticed.
'error::marshmallow.warnings.RemovedInMarshmallow4Warning',
# Fun fact: pkg_resources calls declare_namespace() itself when it processes namespace_packages.txt files.
'ignore:Deprecated call to `pkg_resources\.declare_namespace:DeprecationWarning:pkg_resources:0',
# ignore schemathesis testing related warnings
'ignore:^jsonschema\.RefResolver is deprecated.*$:DeprecationWarning:schemathesis\..*:0',
'ignore:^jsonschema\.exceptions\.RefResolutionError is deprecated.*$:DeprecationWarning:schemathesis\..*:0',
'ignore:^Generating overly large repr.*$:Warning:hypothesis\..*:0',
# ignore DeprecationWarning for ast.NameConstant in reportlab <= 4.2
'ignore:^ast\.NameConstant is deprecated and will be removed in Python 3\.14\; use ast\.Constant instead$:DeprecationWarning:reportlab\..*:0',
# ignore warnings caused by probuf 4.25.3 until updating to 5.x
'ignore:^Type google\._upb\._message.MessageMapContainer uses PyType_Spec with a metaclass that has custom tp_new\. This is deprecated and will no longer be allowed in Python 3\.14\.$:DeprecationWarning:importlib._bootstrap:488',
'ignore:^Type google\._upb\._message.ScalarMapContainer uses PyType_Spec with a metaclass that has custom tp_new\. This is deprecated and will no longer be allowed in Python 3\.14\.$:DeprecationWarning:importlib._bootstrap:488',
# ignore PytestCollectionWarning caused by webtest
'ignore:^cannot collect test class .* because it has a __init__ constructor.*$:UserWarning:.*webtest.*:0',
# openapi collector uses pkg resources
'ignore:pkg_resources:DeprecationWarning:.*opentelemetry.*',
]
# When writing a junit.xml, also write the output of a test to the junit
# file in addition to the console.
junit_logging = "all"