-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyproject.toml
More file actions
396 lines (350 loc) · 12 KB
/
pyproject.toml
File metadata and controls
396 lines (350 loc) · 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
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
# OpenProcessor - Python Project Configuration
# Configuration for ruff (linter + formatter) and project metadata
[project]
name = "openprocessor"
version = "0.1.0"
description = "Self-hosted AI-powered visual processing engine with object detection, face recognition, CLIP embeddings, OCR, and vector search"
readme = "README.md"
requires-python = ">=3.12"
authors = [
{name = "OpenProcessor Contributors"}
]
license = {text = "MIT"}
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Scientific/Engineering :: Image Recognition",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3.12",
]
keywords = ["yolo", "triton", "tensorrt", "object-detection", "face-recognition", "clip", "ocr", "visual-search", "fastapi", "inference", "openprocessor"]
dependencies = [
"fastapi",
"uvicorn[standard]",
"python-multipart",
"orjson",
"pydantic-settings",
"ultralytics",
"tritonclient[all]",
"onnx>=1.12.0,<=1.19.1",
"onnxslim>=0.1.71",
"onnxsim>=0.4.33",
"onnxscript",
"onnxruntime-gpu",
"onnx-graphsurgeon",
"tensorrt-cu12==10.13.3.9",
"nvidia-dali-cuda120",
"torch",
"torchvision",
"opencv-python",
"numpy",
"scipy",
"requests",
"aiohttp",
"matplotlib",
"seaborn",
"pandas",
"psutil",
"tqdm",
"tabulate",
"pyyaml",
"opensearch-py>=2.3.0",
"transformers>=4.30.0",
"timm",
"huggingface_hub",
]
[project.optional-dependencies]
dev = [
"pre-commit>=4.0.0",
"ruff>=0.8.4",
"mypy>=1.13.0",
"bandit[toml]>=1.8.0",
"pytest>=8.0.0",
"pytest-cov>=5.0.0",
"pytest-asyncio>=0.24.0",
]
[build-system]
requires = ["setuptools>=68.0", "wheel"]
build-backend = "setuptools.build_meta"
# =============================================================================
# Ruff Configuration (Linter + Formatter)
# =============================================================================
[tool.ruff]
# Target Python 3.12
target-version = "py312"
# Line length (industry standard: 88-100, we use 100)
line-length = 100
# Directories to include/exclude
include = ["src/**/*.py", "export/**/*.py", "dali/**/*.py", "scripts/**/*.py", "tests/**/*.py"]
exclude = [
".git",
".venv",
"__pycache__",
".pytest_cache",
".mypy_cache",
".ruff_cache",
"reference_repos",
"pytorch_models",
"models",
"cache",
"benchmarks/results",
"*.egg-info",
]
# =============================================================================
# Ruff Linter Rules
# =============================================================================
[tool.ruff.lint]
# Enable rule categories (industry standard set)
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"I", # isort (import sorting)
"N", # pep8-naming
"UP", # pyupgrade (modernize Python code)
"B", # flake8-bugbear (detect common bugs)
"A", # flake8-builtins (shadowing builtins)
"C4", # flake8-comprehensions (better list/dict comprehensions)
"DTZ", # flake8-datetimez (timezone-aware datetime)
"T10", # flake8-debugger (no breakpoints in production)
"EM", # flake8-errmsg (better error messages)
"ISC", # flake8-implicit-str-concat
"ICN", # flake8-import-conventions
"PIE", # flake8-pie (misc lints)
"PT", # flake8-pytest-style
"Q", # flake8-quotes (enforce quote style)
"RSE", # flake8-raise (better exception raising)
"RET", # flake8-return (better return statements)
"SIM", # flake8-simplify (simplify code)
"TID", # flake8-tidy-imports
"TCH", # flake8-type-checking (optimize TYPE_CHECKING imports)
"ARG", # flake8-unused-arguments
"PTH", # flake8-use-pathlib (prefer pathlib over os.path)
"ERA", # eradicate (remove commented-out code)
"PL", # pylint
"PERF", # perflint (performance anti-patterns)
"RUF", # ruff-specific rules
]
# Rules to ignore (with justification)
ignore = [
"E501", # Line too long (handled by formatter)
"PLC0415", # Import should be at top-level (lazy imports for heavy deps)
"PLR0913", # Too many arguments (common in ML code)
"PLR0912", # Too many branches (common in validation logic)
"PLR0915", # Too many statements (common in setup functions)
"PLR2004", # Magic value comparison (common with thresholds)
"N803", # Argument name should be lowercase (allow numpy-style names)
"N806", # Variable should be lowercase (allow numpy-style names)
"DTZ005", # datetime.now() without tz (not critical for logs)
"EM101", # Exception must not use string literal (too strict)
"EM102", # Exception must not use f-string (too strict)
"TRY003", # Avoid long messages in exception (too strict)
"SIM108", # Use ternary operator (readability preference)
"PTH123", # pathlib open() vs builtin open() (performance reasons)
"RUF012", # Mutable class attributes (common in Pydantic)
]
# Allow autofix for all enabled rules
fixable = ["ALL"]
unfixable = []
# Allow unused variables when prefixed with underscore
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
[tool.ruff.lint.per-file-ignores]
# Test files can have additional flexibility
"tests/**/*.py" = [
"ARG001", # Unused function argument (fixtures)
"S101", # Use of assert
"PLR2004", # Magic values
"PT028", # Default arguments in test-like functions (standalone test scripts, not pytest)
"RUF001", # Ambiguous Unicode characters (intentional for display)
]
# Scripts can be less strict
"scripts/**/*.py" = [
"T201", # print() allowed in scripts
"PLR2004", # Magic values
"PT028", # Default arguments in test-named functions (these are scripts, not pytest tests)
]
# DALI pipeline scripts are not pytest tests despite test_* naming
"dali/**/*.py" = [
"PT028", # Default arguments in test-like functions (standalone validation scripts)
"ARG001", # Unused function argument (kept for interface consistency)
"ERA001", # Commented-out code (documentation comments describing matrix format)
"RUF022", # Unsorted __all__ (intentionally grouped by category)
]
# FastAPI routers use dependency injection in default arguments (standard pattern)
"src/routers/**/*.py" = [
"B008", # Function call in default argument (FastAPI File(), Depends(), Query())
"PT028", # Default arguments in endpoint functions (FastAPI pattern, not pytest)
]
# Utils package has documentation comments explaining import structure
"src/utils/__init__.py" = [
"ERA001", # Commented-out code (import documentation for circular dependency prevention)
]
# Ultralytics patches are third-party code
"src/ultralytics_patches/**/*.py" = [
"ALL", # Disable all linting for third-party patches
]
# Export scripts for TensorRT plugins (third-party TRT NMS patterns)
"export/**/*.py" = [
"N801", # Class names follow TensorRT plugin conventions (TRT_EfficientNMS)
"ARG001", # Unused arguments kept for interface consistency
"ARG004", # TensorRT plugin forward() requires all args for ONNX export
"PT028", # Default arguments in test-named functions (standalone scripts, not pytest)
"F401", # Import for side effects (pycuda.autoinit, pycuda.driver)
]
[tool.ruff.lint.isort]
# Import sorting configuration (follows black/blue style)
force-single-line = false
lines-after-imports = 2
known-first-party = ["src"]
known-third-party = ["ultralytics", "tritonclient", "fastapi", "pydantic"]
section-order = ["future", "standard-library", "third-party", "first-party", "local-folder"]
# Combine 'from' imports from the same module
combine-as-imports = true
split-on-trailing-comma = false
[tool.ruff.lint.flake8-quotes]
# Use single quotes (blue style, more compact)
inline-quotes = "single"
multiline-quotes = "double"
docstring-quotes = "double"
[tool.ruff.lint.pydocstyle]
# Use Google-style docstrings
convention = "google"
[tool.ruff.lint.pylint]
# Pylint-specific settings
max-args = 10
max-branches = 15
max-returns = 8
max-statements = 60
# =============================================================================
# Ruff Formatter Configuration
# =============================================================================
[tool.ruff.format]
# Use single quotes (blue style)
quote-style = "single"
# Indent with spaces
indent-style = "space"
# Respect existing line endings
line-ending = "auto"
# Enable magic trailing comma (helps with git diffs)
skip-magic-trailing-comma = false
# Docstring formatting
docstring-code-format = true
docstring-code-line-length = 88
# =============================================================================
# Pytest Configuration
# =============================================================================
[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = ["test_*.py", "*_test.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]
addopts = [
"-v",
"--strict-markers",
"--tb=short",
"--cov=src",
"--cov-report=term-missing",
"--cov-report=html",
]
# =============================================================================
# Coverage Configuration
# =============================================================================
[tool.coverage.run]
source = ["src"]
omit = [
"*/tests/*",
"*/test_*.py",
"*/__pycache__/*",
"*/site-packages/*",
"src/ultralytics_patches/*", # Third-party code
]
[tool.coverage.report]
precision = 2
show_missing = true
skip_covered = false
exclude_lines = [
"pragma: no cover",
"def __repr__",
"raise AssertionError",
"raise NotImplementedError",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
"@abstractmethod",
]
# =============================================================================
# MyPy Configuration (Type Checking)
# =============================================================================
[tool.mypy]
python_version = "3.12"
warn_return_any = false # Disabled for ML code with numpy/FAISS operations
warn_unused_configs = true
disallow_untyped_defs = false
disallow_incomplete_defs = false
check_untyped_defs = true
no_implicit_optional = true
warn_redundant_casts = true
warn_unused_ignores = false
warn_no_return = true
strict_equality = true
ignore_missing_imports = true
explicit_package_bases = true
mypy_path = "."
namespace_packages = true
# Ignore third-party packages without type stubs
[[tool.mypy.overrides]]
module = [
"ultralytics.*",
"tritonclient.*",
"onnx.*",
"onnxslim.*",
"onnxsim.*",
"onnxruntime.*",
"tensorrt.*",
"nvidia.dali.*",
"cv2.*",
"opensearchpy.*",
"transformers.*",
"timm.*",
]
ignore_missing_imports = true
# Relax strict checks for ML/scientific code with FAISS and numpy operations
[[tool.mypy.overrides]]
module = [
"src.services.clustering",
"src.services.duplicate_detection",
"src.clients.opensearch",
"src.clients.triton_client",
"src.services.model_export",
"src.services.visual_search",
"src.utils.retry",
"src.utils.face_alignment",
"src.utils.image_processing",
"src.services.image",
"src.services.face_identity",
"src.routers.detect",
]
disable_error_code = ["attr-defined", "operator", "misc", "assignment", "return-value", "call-overload", "union-attr", "arg-type", "dict-item"]
# Skip type checking on third-party patches
[[tool.mypy.overrides]]
module = "src.ultralytics_patches.*"
ignore_errors = true
# =============================================================================
# Bandit Configuration (Security Linting)
# =============================================================================
[tool.bandit]
exclude_dirs = [
"tests",
".venv",
"venv",
"reference_repos",
"pytorch_models",
"cache",
]
skips = [
"B101", # assert_used - common in test files
"B311", # random - only used for non-cryptographic retry jitter
"B601", # paramiko_calls - not used
]
[tool.bandit.assert_used]
skips = ["*_test.py", "test_*.py"]