-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyproject.toml
More file actions
351 lines (311 loc) · 9.52 KB
/
Copy pathpyproject.toml
File metadata and controls
351 lines (311 loc) · 9.52 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
# ContextSafe - Document Anonymization System
# ============================================
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "contextsafe"
version = "0.1.0"
description = "Sistema 100% local de anonimizacion inteligente de documentos sensibles"
authors = ["ContextSafe Team"]
readme = "README.md"
license = "Apache-2.0"
packages = [{ include = "contextsafe", from = "src" }]
[tool.poetry.dependencies]
python = "^3.11"
# Core - Design by Contract
icontract = "^2.6.0"
# Data Validation
pydantic = "^2.0.0"
pydantic-settings = "^2.0.0"
# Structured Logging
structlog = "^23.0.0"
# HTTP Client
httpx = "^0.24.0"
# Web Framework
fastapi = "^0.100.0"
uvicorn = { version = "^0.23.0", extras = ["standard"] }
# Database - SQLite with encryption
sqlalchemy = { version = "^2.0.0", extras = ["asyncio"] }
aiosqlite = "^0.19.0"
sqlcipher3-binary = "^0.5.0"
# Document Processing
pdfplumber = "^0.10.0"
python-docx = "^0.8.11"
chardet = "^5.0.0"
reportlab = "^4.0.0"
# OCR
pytesseract = "^0.3.10"
Pillow = "^10.0.0"
opencv-python-headless = "^4.8.0"
# NLP / NER
spacy = "^3.7.0"
transformers = "^4.36.0"
torch = "^2.1.0"
# Fuzzy String Matching (for entity normalization)
thefuzz = "^0.22.1"
# LLM Runtime (legacy - puede eliminarse si no se usa)
# llama-cpp-python = "^0.2.50"
# Embeddings (optional, for semantic alias)
sentence-transformers = "^2.2.0"
# Metrics
prometheus-client = "^0.17.0"
# WebSocket
websockets = "^12.0"
# CLI
click = "^8.1.0"
# PII Detection (Presidio)
presidio-analyzer = "^2.2.0"
presidio-anonymizer = "^2.2.0"
python-dotenv = "^1.0.0"
python-multipart = "^0.0.28"
[tool.poetry.group.dev.dependencies]
# Testing
pytest = "^7.4.0"
pytest-asyncio = "^0.21.0"
pytest-cov = "^4.1.0"
hypothesis = "^6.82.0"
# Type Checking
mypy = "^1.5.0"
# Linting & Formatting
ruff = "^0.1.0"
# Security Scanning
bandit = "^1.7.0"
# Mutation Testing
mutmut = "^2.4.0"
# E2E Testing (Web)
pytest-playwright = "^0.4.0"
# Test Utilities
factory-boy = "^3.3.0"
faker = "^19.0.0"
testcontainers = "^3.7.0"
[tool.poetry.group.docs.dependencies]
mkdocs = "^1.5.0"
mkdocs-material = "^9.0.0"
mkdocstrings = { version = "^0.23.0", extras = ["python"] }
[tool.poetry.scripts]
contextsafe = "contextsafe.api.main:run"
# ============================================
# TOOL CONFIGURATIONS
# ============================================
[tool.ruff]
target-version = "py311"
line-length = 100
src = ["src", "tests"]
[tool.ruff.lint]
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # Pyflakes
"I", # isort
"C", # flake8-comprehensions
"B", # flake8-bugbear
"UP", # pyupgrade
"S", # flake8-bandit
"A", # flake8-builtins
"C4", # flake8-comprehensions
"DTZ", # flake8-datetimez
"T10", # flake8-debugger
"EXE", # flake8-executable
"ISC", # flake8-implicit-str-concat
"ICN", # flake8-import-conventions
"G", # flake8-logging-format
"INP", # flake8-no-pep420
"PIE", # flake8-pie
"PYI", # flake8-pyi
"PT", # flake8-pytest-style
"Q", # flake8-quotes
"RSE", # flake8-raise
"RET", # flake8-return
"SLF", # flake8-self
"SLOT", # flake8-slots
"SIM", # flake8-simplify
"TID", # flake8-tidy-imports
"TCH", # flake8-type-checking
"ARG", # flake8-unused-arguments
"PTH", # flake8-use-pathlib
"PL", # Pylint
"TRY", # tryceratops
"FLY", # flynt
"PERF", # Perflint
"RUF", # Ruff-specific rules
]
ignore = [
"S101", # Use of assert (needed for icontract)
"S104", # Possible binding to all interfaces
"B008", # Do not perform function calls in argument defaults (FastAPI Depends)
"PLR0913", # Too many arguments to function call
"PLR2004", # Magic value used in comparison
"UP007", # Use X | Y instead of Optional[X] (not yet adopted)
"G004", # Logging statement uses f-string
"TCH001", # Move application import into type-checking block
"TCH002", # Move third-party import into type-checking block
"TCH003", # Move standard library import into type-checking block
"TCH005", # Empty type-checking block
"S311", # Standard pseudo-random generators not suitable for cryptography
"RUF012", # Mutable class attributes should be annotated with ClassVar
"RUF001", # String contains ambiguous character (Spanish text)
"RUF003", # Comment contains ambiguous character (Spanish comments)
"TRY003", # Avoid specifying long messages outside the exception class
"TRY300", # Consider moving statement to else block
"ARG002", # Unused method argument
"C901", # Function is too complex
"SLF001", # Private member accessed
"DTZ003", # datetime.utcnow() used
"PLR0912", # Too many branches
"SIM102", # Use a single if statement instead of nested if
"RET505", # Unnecessary else after return
"PTH123", # open() should be replaced with Path.open()
"E501", # Line too long (handled by formatter)
"ISC001", # Implicit string concatenation (conflicts with formatter)
"TRY400", # Use logging.exception instead of logging.error
"TRY200", # Use raise from to specify exception cause
"PLW0603", # Using global statement
"PLR0911", # Too many return statements
"PLR0915", # Too many statements
"PLW2901", # Loop variable overwritten by assignment
"S110", # try/except/pass detected
"S603", # subprocess call: check for execution of untrusted input
"S607", # Starting a process with a partial executable path
"ARG001", # Unused function argument
"RET504", # Unnecessary assignment before return
"PERF401", # Use list comprehension (not always clearer)
"DTZ001", # datetime without timezone info
"RUF013", # Implicit Optional
"RUF002", # Docstring contains ambiguous character (Spanish)
"PT011", # pytest.raises too broad
"B904", # Use raise from inside except
"B017", # pytest.raises(Exception) considered evil
"B033", # Set contains duplicate items
"B007", # Loop variable not used in loop body
"PT004", # Fixture does not return anything, use underscore prefix
"A002", # Argument shadowing builtin
"A001", # Variable shadowing builtin
"SIM110", # Use any()/all() instead of for loop
"PYI034", # __new__ should return self
"PIE810", # Pass multiple values to isinstance
"TRY301", # Abstract raise to inner function
"TRY201", # Use raise without args in except
"TID252", # Prefer relative imports
"PTH109", # os.getcwd() -> Path.cwd()
"PTH108", # os.unlink() -> Path.unlink()
"PLR5501", # Use elif instead of else+if
"C401", # Unnecessary generator passed to set()
]
[tool.ruff.lint.per-file-ignores]
"tests/**/*.py" = [
"S101", # asserts allowed in tests
"ARG", # Unused function args (fixtures)
"S105", # Possible hardcoded password
"S106", # Possible hardcoded password
]
[tool.ruff.lint.isort]
known-first-party = ["contextsafe"]
force-single-line = false
lines-after-imports = 2
[tool.mypy]
python_version = "3.11"
warn_return_any = true
warn_unused_ignores = true
disallow_untyped_defs = true
disallow_incomplete_defs = true
check_untyped_defs = true
no_implicit_optional = true
warn_redundant_casts = true
plugins = ["pydantic.mypy"]
explicit_package_bases = true
mypy_path = "src"
disable_error_code = [
"import-untyped",
"misc",
"type-arg",
"list-item",
"no-any-return",
"no-untyped-def",
"no-untyped-call",
"arg-type",
"union-attr",
"assignment",
"override",
"call-arg",
"valid-type",
"return-value",
"index",
"call-overload",
"attr-defined",
"operator",
"unused-ignore",
"import-not-found",
]
[[tool.mypy.overrides]]
module = [
"pdfplumber.*",
"docx.*",
"pytesseract.*",
"cv2.*",
"spacy.*",
"llama_cpp.*",
"sentence_transformers.*",
"sqlcipher3.*",
"prometheus_client.*",
"icontract.*",
"icontract_hypothesis.*",
"hypothesis.*",
"factory.*",
"faker.*",
"testcontainers.*",
]
ignore_missing_imports = true
[tool.pytest.ini_options]
asyncio_mode = "auto"
testpaths = ["tests"]
python_files = ["test_*.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]
addopts = [
"-v",
"--strict-markers",
"--tb=short",
"-ra",
]
markers = [
"unit: Unit tests",
"integration: Integration tests",
"contract: Contract tests",
"pbt: Property-based tests",
"e2e: End-to-end tests",
"slow: Slow tests",
]
filterwarnings = [
"ignore::DeprecationWarning",
]
[tool.coverage.run]
source = ["src/contextsafe"]
branch = true
omit = [
"*/tests/*",
"*/__init__.py",
]
[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"def __repr__",
"raise NotImplementedError",
"if TYPE_CHECKING:",
"if __name__ == .__main__.:",
"@abstractmethod",
"Protocol",
]
fail_under = 0
show_missing = true
[tool.bandit]
exclude_dirs = ["tests", "scripts"]
skips = [
"B101", # assert_used - needed for icontract
"B104", # hardcoded_bind_all_interfaces - accepted, configured via env
"B110", # try_except_pass - accepted pattern for optional features
"B311", # random - not used for cryptography, only for synthetic data
"B404", # subprocess import - legitimate use for NLP tools
"B603", # subprocess_without_shell_equals_true - commands are controlled
"B607", # start_process_with_partial_path - commands are controlled
]