Repository navigation
Expand file tree
/
Copy pathruff.toml
More file actions
146 lines (138 loc) · 7.12 KB
/
Copy pathruff.toml
File metadata and controls
146 lines (138 loc) · 7.12 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
# The ruff settings live apart from pyproject.toml on purpose: please don't merge them back.
#
# When ruff's settings moved here, mypy and bandit read pyproject.toml, so every edit there re-ran
# all their actions: in CI about 1420 mypy actions (52-75 CPU-minutes) and 1045 bandit actions
# (about 16 CPU-minutes), plus the 211 targets that depend on pyproject.toml, among them tests
# reading their pytest settings from it. In the year up to 2026-11-25, 168 of the 208 commits
# changing pyproject.toml changed the ruff settings, 167 of them without touching mypy's or
# bandit's (those changed in only 22 and 5 commits). Keeping ruff apart saved roughly 190-250
# CPU-hours a year in CI, plus the rebuilds developers get after rebasing across such a commit.
# mypy's settings have moved to mypy.ini since, for the same reason. bandit and the tests still
# read pyproject.toml.
extend-exclude = ["doc/**/*.py"]
target-version = "py315"
line-length = 100
[lint]
# Required to select preview/unstable rules such as pytest-fixture-autouse.
preview = true
# ...but only the ones selected by exact name/code.
explicit-preview-rules = true
select = [
"A", # flake8: builtins
"ARG", # flake8: unused args
"B005", # flake8-bugbear: strip-with-multi-characters
"B006", # flake8-bugbear: mutable-argument-default
"B012", # flake8-bugbear: jump-statement-in-finally
"B014", # flake8-bugbear: duplicate-handler-exception
"B017", # flake8-bugbear: assert-raises-exception
"B019", # flake8-bugbear: cached-instance-method
"B020", # flake8-bugbear: loop-variable-overrides-iterator
"B023", # flake8-bugbear: function-uses-loop-variable
"B024", # flake8-bugbear: abstract-base-class-without-abstract-method
"B027", # flake8-bugbear: empty-method-without-abstract-decorator
"B031", # flake8-bugbear: reuse-of-groupby-generator
"B033", # flake8-bugbear: duplicate-value
"B034", # flake8-bugbear: re-sub-positional-args
"B035", # flake8-bugbear: static-key-dict-comprehension
"B039", # flake8-bugbear: mutable-contextvar-default
"C4", # flake8: comprehensions
"C90", # mccabe
"E", # pycodestyle (error)
"F", # pyflakes
"FLY", # flake8: flynt
"G", # flake8: logging format
"N804", # pep8-naming: invalid-first-argument-name-for-class-method (cls)
"N805", # pep8-naming: invalid-first-argument-name-for-method (self)
"I", # isort
"ISC", # flake8: implicit string concat
"LOG", # flake8: logging
"PIE", # flake8: misc lints
"PL", # pylint
"RET", # flake8: return
"RSE", # flake8: raise
"RUF028", # ruff: invalid-formatter-suppression-comment
"RUF100", # ruff: unused noqa
"SIM", # flake8: simplify
"SLF", # flake8: self
"UP", # pyugrade
"W", # pycodestyle (warning)
"T10", # flake8: debugger
"T20", # flake8: print
"TID251", # flake8-tidy-imports: banned-api
"TID253", # flake8-tidy-imports: banned-module-level-imports
"TRY400", # tryceratops: use logger.exception() instead of logger.error() in except blocks
"pytest-fixture-autouse", # ruff (preview): ban autouse pytest fixtures (selected by name, no code)
]
ignore = [
# Black is our formatting tool, so ignore any formatting-related findings.
"E501", # line too long
# 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
"PLC0415", # `import` should be at the top-level of a file
"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...
"PLW1641", # Object does not implement `__hash__` method
"UP031", # Use format specifiers instead of percent format
]
[lint.mccabe]
max-complexity = 64 # TODO: This is far too much, we need to lower this!
# Files allowed to import one of these modules suppress TID251 with a noqa
# comment. The large modules have to be imported inside the functions using
# them (TID253), unless the importing process always uses them. So do the
# modules whose import has side effects, even then.
[lint.flake8-tidy-imports]
banned-module-level-imports = [
"cmk.gui.wato.pages.timeperiods_ical",
"grpc",
"icalendar",
"opentelemetry.exporter.otlp.proto.grpc",
"pypdf",
"recurring_ical_events",
"reportlab",
# It starts a thread on import, so a later fork() breaks it.
"watchdog.observers",
]
[lint.flake8-tidy-imports.banned-api]
"cmk.gui.wato.pages.timeperiods_ical".msg = "It loads the iCalendar libraries, which add several MB to every process importing them"
"grpc".msg = "It adds several MB to every process importing it"
"icalendar".msg = "It adds several MB to every process importing it, use cmk.gui.wato.pages.timeperiods_ical"
"opentelemetry.exporter.otlp.proto.grpc".msg = "It adds several MB to every process importing it, use cmk.trace"
"PIL".msg = "Use the images module at the correct layer, e.g. cmk.gui.utils.images"
"pypdf".msg = "It adds several MB to every process importing it"
"recurring_ical_events".msg = "It adds several MB to every process importing it, use cmk.gui.wato.pages.timeperiods_ical"
"reportlab".msg = "It adds several MB to every process importing it, use cmk.gui.pdf"
[lint.isort]
# Same-package detection looks for __init__.py files next to the linted file.
# The sandbox of `bazel lint` only contains the sources of the linted target,
# which often lack the __init__.py of their package, so the import order would
# differ between `bazel lint` and a plain `ruff check`.
detect-same-package = false
known-first-party = ["agents", "buildscripts", "cmk", "scripts", "tests"]
known-third-party = [
"fastapi", # avoid confusion with the cmk.fastapi package
"requirements", # avoid confusion with our toplevel directory
]
order-by-type = false
section-order = [
"future",
"standard-library",
"third-party",
"first-party-not-cmk",
"first-party",
"local-folder",
]
[lint.isort.sections]
first-party-not-cmk = ["cmc_proto", "omdlib", "livestatus"]
# TODO: This is way too high, the default is 5!
[lint.pylint]
max-positional-args = 16