forked from modular/modular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyproject.toml
More file actions
223 lines (204 loc) · 8.8 KB
/
Copy pathpyproject.toml
File metadata and controls
223 lines (204 loc) · 8.8 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
[project]
name = "modular"
version = "0"
requires-python = ">= 3.10"
# TODO: restrict utils/packaging/tests to only test_format.mojo
[tool.black]
include = '\.mojo$'
line-length = 80
preview = true
fast = true
force-exclude = '''
(
/(
third-party/llvm-project
| \.derived
| venv
| Mojo/test/mojo-parser
| Mojo/test/mojo-tool/format
| Mojo/tools/mblack
| max/python/max/serve/schemas
| utils/packaging/tests
| Faux/mojo_llm_from_scratch
)/
)
'''
[tool.ruff]
line-length = 80 # Must match above
# Honor extend-exclude even for explicitly-passed files (presubmit fast-mode
# lints changed files by path); matches [tool.black] force-exclude above.
force-exclude = true
src = ["something-that-doesnt-exist"] # Stop ruff from assuming any root directory is a python module
extend-exclude = [
".git",
# Machine-authored agent state (skills, agent scripts). Already excluded from
# rumdl and typos; these helper scripts are not shipped product code.
".claude",
"**/lit.cfg.py", # Globals that aren't imported
"*.ipynb",
"*_pb2.py", # Generated protobuf stubs
"*_pb2.pyi", # Generated protobuf stubs
"*max/serve/schemas/openai.py", # Generated file
"third-party",
# Vendored verbatim from xgrammar v0.2.2 (hack-to-own); kept unformatted so a
# future re-vendor diffs cleanly against upstream.
"*max/python/max/_xgrammar/structural_tag.py",
"*max/python/max/_xgrammar/builtin_structural_tag.py",
"*max/python/max/_xgrammar/openai_tool_call_schema.py",
"bazel/internal/llvm-lit/lit.common.cfg.py", # Globals that aren't imported
"Mojo/tools/mblack/tests",
"Faux/mojo_llm_from_scratch/**", # Experimental from-scratch LLM project
]
[tool.ruff.lint]
ignore = [
"ANN002", # TODO: Missing type annotation for *args
"ANN003", # TODO: Missing type annotation for **kwargs
"ANN204", # TODO: Missing return type annotation for special method
"ANN401", # TODO: Dynamically typed expressions (typing.Any) are disallowed in `**kwargs`
"ASYNC210", # Async functions should not call blocking HTTP methods
"ASYNC230", # Async functions should not open files with blocking methods like `open`
"ASYNC251", # Async functions should not call `time.sleep`
"B017", # Do not assert blind exception: `Exception`
"B028", # No explicit `stacklevel` keyword argument found
"BLE001", # Do not catch blind exception: `Exception`
"C408", # Rewrites `dict(foo="bar")` to `{"foo": "bar"}`, questionable readability improvement
"D105", # undocumented-magic-method
"D107", # Missing docstring in __init__ (constructor args go in class docstring)
"DTZ001", # `datetime.datetime()` called without a `tzinfo` argument
"DTZ005", # `datetime.datetime.now()` called without a `tz` argument
"DTZ006", # `datetime.datetime.fromtimestamp()` called without a `tz` argument
"DTZ007", # Naive datetime constructed using `datetime.datetime.strptime()` without %z
"DTZ011", # `datetime.date.today()` used
"E402", # TODO: import top of file
"E501", # Line length, no autofix.
"E722", # bare except
"E731", # TODO: Don't assign lambda
"E741", # TODO: Ambiguous variable name
"F821", # TODO: Undefined names, means script is invalid
"FLY002", # TODO: The strings this flags are usually quite silly looking
"FURB122", # Questionable readability improvement
"G201", # Use .exception() instead of .error() on loggers
"ISC004", # TODO: Unparenthesized implicit string concatenation in collection
"LOG015", # Use of root logger, usually low value in standalone scripts
"N999", # Invalid or non_snake_case module names. Former: TODO, latter: maybe not worth it.
"PERF402", # TODO: Use `list` or `list.copy` to create a copy of a list
"PLC0105", # Something about type variables and covariance
"PLC0414", # Import alias does not rename original package - we do this intentionally in several places
"PLW1508", # Invalid type for environment variable default - we do this a lot and it's usually valid.
"PLW1510", # subprocess.run without explicit `check` - low value
"PYI019", # Adds typing_extensions in a lot of places in pre-3.11 world. Maybe revisit when we drop 3.10.
"PYI034", # Fine, but can't be auto-applied to stubfiles, and adds typing_extensions everywhere in pre-3.11 world.
"PYI036", # TODO: `__exit__` annotations
"PYI059", # TODO: Reorders `Generic` base classes, could be slightly risky
"RUF005", # Consider iterable unpacking instead of concatenation
"RUF010", # Use explicit conversion flag
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
"RUF015", # Prefer `next(iter(iterable))` over single element slice
"S102", # Checks for `exec` (security concern, TODO maybe enable on a subset of targets)
"S110", # Checks for try-except-pass, suggests logging
"S112", # Checks for try-except-continue, suggests logging
"SIM102", # Collapsible if
"SIM105", # Suppressible exception
"SIM108", # Use ternary operator
"SIM114", # Combine arms with or
"SIM115", # Use context manager for opening files
"SIM117", # Merge with statements
"SIM300", # YODA conditions
"SIM905", # Use a list literal instead of str.split
"TRY002", # TODO: Suggests to use more specific errors than "Exception"
"TRY004", # TODO: Suggests TypeError for invalid types
]
extend-select = [
"ANN", # Require function type annotations
"B", # Bugbear lints
"D", # Pydocstyle lints
"E", # Pydocstyle lints
"FURB", # Refurb lints for modernization
"I", # Import sorting lints
"RUF", # Ruff specific lints
"SIM", # Simplify lints
"T10", # Checks for the presence of debugger calls and imports.
"UP", # Type annotations should not use Union, Optional, etc
]
[tool.ruff.lint.pydocstyle]
convention = "google"
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"] # Ignore unused imports being re-exported
# Enforce pydocstyle only for MAX API:
# NOTE: Ruff skips all "missing docstring" (D10X) rules for *.pyi files
"!max/python/max/**/{*.py,*.pyi}" = ["D"]
# With exceptions for these packages:
"max/python/max/benchmark/**/*" = ["D"]
"max/python/max/config/**/*" = ["D"]
"max/python/max/pipelines/kv_cache/connectors/**/*" = ["D"]
"max/python/max/mlir/**/*" = ["D"]
"max/python/max/nn/**/*" = ["D"]
"max/python/max/pipelines/architectures/**/*" = ["D"]
"max/python/max/pipelines/pipelines.py" = ["D"]
"max/python/max/serve/**/*" = ["D"]
"max/python/max/support/**/*" = ["D"]
# Exclude private packages and modules (NOTE: this allows max/_core/*.pyi files):
"max/python/max/_core_mojo/**/*" = ["D"]
"max/python/max/_core_types/**/*" = ["D"]
"max/python/max/_entrypoints/**/*" = ["D"]
"max/python/max/_interpreter_ops/**/*" = ["D"]
"max/python/max/_mlir/**/*" = ["D"]
"max/python/max/_core/dialects/**/*" = ["D"]
"max/python/max/_core/internal/**/*" = ["D"]
"max/python/max/**/_*.py" = ["D"]
# Disable most annotations for third-party stubfiles
# PYI001 is a valid fix but isn't autogenerated correctly by nanobind
"*/_mlir/*.pyi" = ["ANN001", "ANN201", "ANN202", "ANN205", "ANN206", "D200", "D212", "D418", "PYI001", "PYI047"]
# Be a little less strict with docs in first-party stubfiles
"*/_core/*.pyi" = ["D200", "D212", "D418", "PYI001"]
# Ignore type annotations for the llm-book tutorial files
"oss/llm-book/**/*.py" = ["ANN001", "ANN201", "ANN202"]
# Ignore type annotations, intentional math unicode (×), and common tutorial code patterns
# in mojo-gpu-puzzles (external code with its own linting standards)
"oss/mojo-gpu-puzzles/**/*.py" = ["ANN001", "ANN201", "ANN202", "ANN205", "ANN206", "RUF001"]
# Disable lints which complain about weird unicode characters in files that include
# a large number of LLM test prompts.
"max/tests/integration/test_common/test_data.py" = ["RUF001", "RUF003"]
[tool.mypy]
color_output = true
ignore_missing_imports = false
pretty = true
python_version = "3.10"
check_untyped_defs = true
warn_unused_ignores = true
disallow_any_generics = true
follow_imports = "silent"
follow_imports_for_stubs = true
plugins = "pydantic.mypy"
[[tool.mypy.overrides]]
module = "torch.*"
follow_imports = "skip"
[[tool.mypy.overrides]]
module = "transformers.*"
follow_imports = "skip"
[[tool.mypy.overrides]]
module = "absl.*"
follow_imports = "skip"
[[tool.mypy.overrides]]
module = "cyclopts.*"
ignore_missing_imports = true
# Allow missing imports in `_validation_hooks` to avoid circular dependencies.
# This file to add eager validation hooks in various parts of MAX.
[[tool.mypy.overrides]]
module = "max._validation_hooks"
disable_error_code = ["import-not-found"]
# Private MiniMax-M3 graph hooks diverge from the shared load_model template
# signatures; suppress only the files that inherit those hooks.
[[tool.mypy.overrides]]
module = "minimax_m3.model"
disable_error_code = ["misc"]
[[tool.mypy.overrides]]
module = "minimax_m3.eagle3_model"
disable_error_code = ["override"]
[tool.pydantic-mypy]
init_forbid_extra = true
init_typed = true
[tool.ty.environment]
extra-paths = [
"max/python",
]