-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyproject.toml
More file actions
302 lines (268 loc) · 8.15 KB
/
Copy pathpyproject.toml
File metadata and controls
302 lines (268 loc) · 8.15 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
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
[project]
name = "zsharp"
version = "0.2.0"
description = "Sharpness-Aware Minimization with Z-Score Gradient Filtering"
authors = [
{name = "Bangyen Pham", email = "bangyen99@gmail.com"}
]
readme = "README.md"
requires-python = ">=3.9"
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
]
dependencies = [
"torch>=2.0.0",
"torchvision>=0.15.0",
"numpy",
"tqdm",
"pyyaml",
"pydantic>=2.0.0",
]
[project.optional-dependencies]
dev = [
"pytest>=7.0.0",
"pytest-cov",
"ruff",
"mypy",
"interrogate",
"pre-commit",
"types-PyYAML",
"mutmut",
"import-linter",
"deptry",
"vulture",
"hypothesis",
"bandit",
"pip-audit",
]
[tool.deptry.per_rule_ignores]
DEP002 = ["pytest", "pytest-cov", "ruff", "mypy", "interrogate", "pre-commit", "types-PyYAML", "mutmut", "import-linter", "deptry", "vulture", "hypothesis", "bandit", "pip-audit"]
[tool.vulture]
exclude = ["tests/", "scripts/", "venv/"]
ignore_decorators = ["@overload", "@dataclass"]
ignore_names = ["Any", "cls", "final_test_accuracy", "final_test_loss", "train_losses", "train_accuracies", "test_accuracies", "total_training_time", "optimizer_type"]
min_confidence = 80
[build-system]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"
[interrogate]
fail-under = 100
ignore-init-method = false
ignore-init-module = false
ignore-semiprivate = false
ignore-private = false
ignore-property-decorators = false
ignore-nested-functions = false
ignore-nested-classes = false
ignore-regex = ["^_"]
exclude = ["venv", ".git", "__pycache__", ".pytest_cache", "tests", "scripts"]
[tool.pytest.ini_options]
addopts = "-v --tb=short"
testpaths = ["tests"]
markers = [
"mps: marks tests that require MPS support",
]
filterwarnings = [
"ignore::DeprecationWarning:torch.*",
"ignore::PendingDeprecationWarning:torch.*",
"ignore::DeprecationWarning:numpy.*",
"ignore::PendingDeprecationWarning:numpy.*",
"ignore:dtype\\(\\). align:Warning",
]
[tool.ruff]
# Exclude a variety of commonly ignored directories.
exclude = [
"*.ipynb", # Jupyter notebooks (Colab demo, not linted)
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
]
# Same as Black.
line-length = 79
indent-width = 4
# Assumption: Python 3.9
target-version = "py39"
[tool.ruff.lint]
# Maximum strictness: select all rules
select = ["ALL"]
ignore = [
"D203", # one-blank-line-before-class (conflicts with D211)
"D213", # multi-line-summary-second-line (conflicts with D212)
"E501", # line too long (handled by ruff format)
"COM812", # missing-trailing-comma (formatter conflict)
"ISC001", # single-line-implicit-string-concatenation (formatter conflict)
"PLW2901", # Loop variable overwrites (common in ML code)
"N812", # Lowercase imported as non-lowercase (allow common aliases)
"UP007", # Use X | Y for type annotations (Python 3.10+)
"UP045", # Use X | None instead of Optional (Python 3.10+)
# We remove manually allowed complexity ignores
]
# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []
[tool.ruff.lint.mccabe]
max-complexity = 4
[tool.ruff.lint.pylint]
max-args = 5
max-branches = 6
max-locals = 15
max-nested-blocks = 3
max-returns = 3
max-statements = 20
[tool.ruff.lint.pydocstyle]
convention = "google"
[tool.ruff.format]
# Like Black, use double quotes for strings.
quote-style = "double"
# Like Black, indent with spaces, rather than tabs.
indent-style = "space"
# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false
# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]
"tests/**/*.py" = [
"PLR2004", # Magic numbers acceptable in tests
"S", # Relax security rules for tests
"ANN", # No type annotations required for tests
"D", # No docstrings required for tests
"PLC", # Relax complexity/import rules for tests
"PLR", # Relax refactoring rules for tests
"ARG", # Relax unused argument rules for tests (mocks)
"FBT001", # Boolean positional arguments okay in tests
"FBT002", # Boolean default positional arguments okay in tests
"SLF001", # Accessing private members okay in tests
"TRY", # No strict try-except-finally in tests
"EM", # String literals in exceptions okay in tests
"PTH", # os.path is okay in tests
"C901", # Complexity checks not required for tests
"G", # Logging format okay in tests
"SIM", # Simplification rules okay in tests
"I001", # Import sorting (handled by ruff fmt)
"NPY002", # Legacy random allowed in tests
]
"scripts/**/*.py" = [
"BLE001", # Blind exception catching is acceptable in scripts
"INP001", # Implicit namespace package okay for scripts
"PTH", # os.path is okay in scripts
"C901", # Complexity checks not required for scripts
"FBT", # Boolean positional arguments okay in scripts
"ERA", # Commented-out code okay in scripts
"EXE", # Shebang usage okay in scripts
"TRY", # No strict try-except-finally in scripts
"G", # Logging format okay in scripts
"ANN", # No type annotations required for scripts
"D", # No docstrings required for scripts
"PL", # Relax refactoring rules for scripts
]
# Type checking configuration
[tool.mypy]
# Set to match the development runtime (Python 3.12 + modern torch).
# Python 3.9 syntax compatibility is enforced by ruff's target-version.
python_version = "3.12"
strict = true
exclude = ["tests/", "scripts/"]
plugins = ["pydantic.mypy"]
warn_return_any = true
warn_unused_configs = true
disallow_untyped_defs = true
disallow_incomplete_defs = true
check_untyped_defs = true
disallow_untyped_decorators = false # Relaxed for torch decorators
no_implicit_optional = true
warn_redundant_casts = true
warn_unused_ignores = true
warn_no_return = true
warn_unreachable = true
strict_equality = true
ignore_missing_imports = true
disallow_any_generics = true
disallow_any_unimported = true
disallow_any_decorated = true
disallow_any_explicit = true
disallow_untyped_calls = true
no_implicit_reexport = true
strict_optional = true
[[tool.mypy.overrides]]
module = "src.constants"
disallow_any_explicit = false
[[tool.mypy.overrides]]
module = "src.data"
disallow_any_unimported = false
[[tool.mypy.overrides]]
module = "src.optimizer"
disallow_any_explicit = false
# ------------------------------------------------------------------------------
# Architecture & Mutation Testing Configuration
# ------------------------------------------------------------------------------
[tool.importlinter]
root_package = "src"
[[tool.importlinter.contracts]]
name = "Layered Architecture"
type = "layers"
layers = [
"src.trainer",
"src.optimizer | src.models | src.data",
"src.constants",
]
[[tool.importlinter.contracts]]
name = "No Circular Dependencies"
type = "independence"
modules = [
"src.models",
"src.optimizer",
"src.data",
]
[tool.bandit]
exclude_dirs = ["tests/", "scripts/", "venv/"]
skips = [] # Don't skip any security checks
[tool.mutmut]
paths_to_mutate = [
"src/optimizer.py",
"src/trainer.py",
"src/models.py",
]
backup = false
runner = "python -m pytest tests/ -p no:cov"
tests_dir = ["tests/"]
[tool.coverage.report]
fail_under = 95
skip_covered = false
skip_empty = false
exclude_lines = [
"if TYPE_CHECKING:",
"@overload",
]
[tool.coverage.run]
branch = true
source = ["src"]
omit = []
[[tool.mypy.overrides]]
module = "src.optimizer"
disallow_any_explicit = false