-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpyproject.toml
More file actions
408 lines (375 loc) ยท 16.8 KB
/
pyproject.toml
File metadata and controls
408 lines (375 loc) ยท 16.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
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
397
398
399
400
401
402
403
404
405
406
407
408
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "pubmed-search-mcp"
version = "0.4.5"
description = "MCP server for PubMed literature search with MeSH, PICO, and intelligent query expansion"
readme = "README.md"
license = "Apache-2.0"
requires-python = ">=3.10"
authors = [
{ name = "u9401066", email = "u9401066@gap.kmu.edu.tw" }
]
keywords = [
"pubmed",
"entrez",
"ncbi",
"literature",
"medical",
"research",
"search",
"mcp",
"model-context-protocol"
]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Scientific/Engineering :: Medical Science Apps.",
"Topic :: Scientific/Engineering :: Bio-Informatics",
]
dependencies = [
"biopython>=1.81",
"requests>=2.28.0",
"pylatexenc>=2.10", # Unicode to LaTeX conversion for BibTeX export
"mcp>=1.23.3", # FastMCP Context injection, progress reporting, and list_tools() are required
"fastapi>=0.128.0",
"httpx>=0.28.1",
"tenacity>=8.0.0",
"cachetools>=5.0.0",
"pywin32>=311; sys_platform == 'win32'",
"defusedxml>=0.7.1",
"dependency-injector>=4.48.3",
"pyyaml>=6.0", # YAML pipeline config support
]
[project.scripts]
pubmed-search-mcp = "pubmed_search.presentation.mcp_server:main"
[project.urls]
Homepage = "https://github.com/u9401066/pubmed-search-mcp"
Repository = "https://github.com/u9401066/pubmed-search-mcp"
Issues = "https://github.com/u9401066/pubmed-search-mcp/issues"
[tool.hatch.build.targets.wheel]
packages = ["src/pubmed_search"]
[tool.hatch.build.targets.sdist]
include = [
"/src",
"/README.md",
"/LICENSE",
]
[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = ["test_*.py"]
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"
# โก MANDATORY: ๆๆๆธฌ่ฉฆไธๅพๅคๆ ธๅท่ก
# -n 8: ้ๅถ worker ๆธ้้ฟๅ
OOM๏ผ32 logical cores ร ~1.5GB/worker > 48GB RAM๏ผ
# pytest-benchmark ๅจ xdist ๆจกๅผไธ่ชๅๅ็จ๏ผ็ก้ๆๅ่็๏ผ
# pytest-cov ๅฎๅ
จๆฏๆด xdist๏ผ่ช pytest-cov 2.0+๏ผ
addopts = "-n 4 --timeout=60"
markers = [
"integration: marks tests as integration tests (may make real API calls)",
"slow: marks tests as slow running",
]
filterwarnings = [
"ignore::DeprecationWarning",
]
[tool.pytest-benchmark]
# Storage settings for baseline comparison
storage = "file://.benchmarks"
save = "0001" # auto-save with run number
compare = "0001" # compare against baseline
min_rounds = 3
warmup = true
warmup_iterations = 1
[dependency-groups]
dev = [
"deptry>=0.24.0",
"mypy>=1.15",
"pytest>=9.0",
"pytest-asyncio>=0.26",
"pytest-cov>=7.0",
"ruff>=0.14,<0.15",
"pytest-benchmark>=5.1.0",
"mutmut>=3.2.0",
"bandit>=1.8.0",
"safety>=3.2.10",
"pytest-timeout>=2.3.1",
"vulture>=2.14",
"types-requests>=2.32.4.20260107",
"types-cachetools>=6.2.0",
"types-PyYAML>=6.0",
"pytest-xdist>=3.8.0",
"pre-commit>=3.8",
"semgrep>=1.151.0",
]
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# Ruff โ linter + formatter
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
[tool.ruff]
target-version = "py310"
line-length = 120
src = ["src", "tests"]
[tool.ruff.lint]
# ๐ PRODUCTION: ๅ็จๆๆ่ฆๅ๏ผๅ
ๆ้คไธ้ฉ็จ็่ฆๅ้
select = ["ALL"]
ignore = [
# โโ formatter ่ฒ ่ฒฌ โโ
"E501", # line too long โ handled by ruff format
"W191", # tab indentation โ handled by formatter
"COM812", # missing trailing comma โ conflicts with formatter
"ISC001", # implicit string concat in single line โ conflicts with formatter
"Q", # quotes โ handled by formatter
# โโ ไธ้ฉ็จ็่ฆๅ้ โโ
"D", # pydocstyle โ ๅ็จๅพๅ้ๆญฅๅ ๅ
ฅ๏ผTODO: Phase 2๏ผ
"ANN", # flake8-annotations โ ็ฑ mypy strict ่ฒ ่ฒฌ
"FBT", # boolean trap โ ๅฐ API ๅฑค้ๆผๅดๆ ผ
"FIX", # fixme/todo โ ้็ผ้ๆฎตๅ
่จฑ TODO
"TD", # todo โ ้็ผ้ๆฎตๅ
่จฑ TODO
"ERA", # eradicate โ ่ชคๅค็้ซ๏ผไธญ่ฑ้่ช่จป่งฃ๏ผ
"CPY", # copyright โ ็ฑ LICENSE ๆชๆก็ฎก็
"DJ", # django โ ้ Django ๅฐๆก
# โโ 3.10 ็ธๅฎน โโ
"UP007", # use X | Y union โ needs 3.10+ runtime
# UP038 removed in ruff 0.14 (integrated into UP007)
# โโ ไธญ่ฑ้่ชๅฐๆก โโ
"RUF001", # ambiguous unicode in string
"RUF002", # ambiguous unicode in docstring
"RUF003", # ambiguous unicode in comment
# โโ ็นๅฎๆจกๅผ่ฑๅ
โโ
"B008", # function call in default arg โ FastAPI/MCP Depends() pattern
"B905", # zip() without strict= โ 3.10 compat
"RUF012", # mutable class var annotation โ dataclass patterns
"RUF022", # __all__ not sorted โ intentionally grouped by category
"TRY003", # long messages in exceptions โ ไธญๆ้ฏ่ชค่จๆฏ้่ฆๅฎๆดๆ่ฟฐ
"EM101", # raw string in exception โ ไธญๆ้ฏ่ชค่จๆฏ็ดๆฅๅฏซๆดๆธ
ๆฅ
"EM102", # f-string in exception โ ๅไธ
# โโ Logging ้ขจๆ ผ (production ๅ็้ธๆ) โโ
"G004", # logging-f-string โ ็พไปฃ Python ๆ
ฃไพ๏ผMCP ๅฎ็จๆถๅ ดๆฏๆ่ฝๅฝฑ้ฟ <1ฮผs
"TRY401", # verbose-log-message โ logging.exception(msg) ๅซ context ๆดๆธ
ๆฅ
"TRY300", # try-consider-else โ ้ขจๆ ผๅๅฅฝ๏ผ้ๅฎๅ
จๅ้ก
# โโ ๆถๆงๆจกๅผ (MCP server ็นๆ) โโ
"PLC0415", # import-outside-top-level โ lazy import ๆฏๅปๆ็ๅๅๆ่ฝๆไฝณๅ
"PLW0603", # global-statement โ ๆจก็ต็ด singleton/cache ๅฟ
่ฆๆจกๅผ
"PLR0913", # too-many-arguments โ MCP tool function ้่ฆๅคๅๆธ API surface
"C901", # complex-structure โ ้จๅ่งฃๆ/่ทฏ็ฑ้่ผฏๆฌ่ณช่ค้๏ผ้่ฆๅคง่ฆๆจก้ๆงๆ่ฝ้ไฝ
"PLR0912", # too-many-branches โ ๅไธ
"PLR0915", # too-many-statements โ ๅไธ
"PLR0911", # too-many-return-statements โ early return ๆฏๅฅฝๅฏฆ่ธ
# โโ API ๅฎขๆถ็ซฏๆจกๅผ โโ
"PERF401", # manual-list-comprehension โ ๅฏ่ฎๆงๅชๅ
๏ผ้ hot path
"PERF203", # try-except-in-loop โ API ๆนๆฌก่็้่ฆ้้
ๅฎน้ฏ
]
fixable = ["ALL"]
unfixable = []
[tool.ruff.lint.isort]
known-first-party = ["pubmed_search"]
[tool.ruff.lint.per-file-ignores]
"tests/**/*.py" = [
"S101", # assert โ pytest uses assert
"S105", # hardcoded password โ test fixtures
"S106", # hardcoded password arg โ test fixtures
"S108", # hardcoded temp file โ test fixtures
"S110", # try-except-pass โ test setup
"S310", # URL open โ test HTTP calls
"S311", # pseudo-random โ test data generation
"B011", # assert False
"B017", # assert blind exception
"BLE001", # blind exception โ test error handling
"PT", # pytest style โ existing tests may not follow
"SIM", # simplify โ test readability
"PLR2004", # magic value comparison โ tests use literals
"PLR0913", # too many arguments โ test fixtures
"ARG", # unused arguments โ pytest fixtures
"RUF059", # unused unpacked variable โ test destructuring
"B007", # unused loop variable โ test loops
"RUF015", # next(iter()) vs slice โ test readability
"SLF001", # private member access โ testing internals
"T201", # print โ debug output in tests
"N802", # function name uppercase โ test naming conventions
"N803", # argument name uppercase โ test naming conventions
"N806", # variable name uppercase โ mock naming conventions
"INP001", # implicit namespace package โ tests dir
"TRY", # exception handling โ test code can be simpler
"EM", # error message โ test code can be simpler
"PERF", # performance โ not critical in tests
"C901", # complexity โ test functions can be complex
"PLR0912", # too many branches โ complex test scenarios
"PLR0915", # too many statements โ complex test setup
"PTH", # pathlib โ test code uses os.path for simplicity
"ASYNC", # async โ test code uses sync patterns (time.sleep, open)
"PGH003", # blanket-type-ignore โ test type annotations
"RET504", # unnecessary-assign โ test readability
"S603", # subprocess โ test scripts
"DTZ005", # datetime-now โ tests don't need tz
]
"scripts/**/*.py" = [
"T20", # print statements โ expected in scripts
"S603", # subprocess call โ scripts need it
"S607", # partial executable path โ scripts intentional
"B007", # unused loop variable
"BLE001", # blind exception โ script error handling
"INP001", # implicit namespace package โ scripts dir
"PLR0913", # too many arguments โ script functions
"PLR2004", # magic values โ scripts use literals
"SLF001", # private member โ FastMCP internal access
"SIM102", # nested-if โ script readability
"DTZ005", # datetime-now โ scripts don't need tz
"ARG001", # unused argument โ script callbacks
"PLW1510", # subprocess-run-without-check โ scripts handle errors
"PERF102", # dict-items โ script readability
]
"run_copilot.py" = [
"PTH", # pathlib โ sys.path manipulation
"SLF001", # private member โ FastMCP internal access
"PLR2004", # magic values โ HTTP status codes
"S104", # bind-all โ server intentional
"INP001", # namespace package
]
"run_server.py" = [
"PTH", # pathlib โ sys.path manipulation
"SLF001", # private member โ FastMCP internal access
"S104", # bind-all โ server intentional
"S108", # hardcoded temp โ export dir
"N806", # variable uppercase โ EXPORT_DIR constant
"SIM108", # ternary โ readability
"ARG001", # unused argument โ Starlette request handlers
"BLE001", # blind exception โ API error handling
"TRY400", # logging-error โ contextual error messages
"INP001", # namespace package
]
"src/pubmed_search/infrastructure/**/*.py" = [
"BLE001", # blind-except โ API ๅฎขๆถ็ซฏๅฟ
้ ๅฎน้ฏไปปๆๅค้จ้ฏ่ชค
"PLR2004", # magic-value โ HTTP ็ๆ
็ขผ (200, 404, 429) ๆฏๆ
ฃไพ
"ARG002", # unused-method-argument โ override/callback ๆจกๅผ
"SLF001", # private-member-access โ ๆกๆถๆดๅ้ๅญๅๅ
ง้จ็ๆ
"A002", # builtin-shadowing โ `type`, `id`, `format` ๆฏ API ๅๆธๅ็จฑ
]
"src/pubmed_search/presentation/**/*.py" = [
"BLE001", # blind-except โ MCP tool ๅฟ
้ ๆ็ฒไปปไฝ้ฏ่ชคๅๅณๆๆ็พฉ็่จๆฏ
"PLR2004", # magic-value โ HTTP ็ๆ
็ขผใ้ๅถๅผ
"ARG001", # unused-function-argument โ MCP ๆกๆถ่ฆๆฑ็ๅๆธ็ฐฝๅ
"ARG002", # unused-method-argument โ ๅไธ
"SLF001", # private-member-access โ FastMCP ๅ
ง้จ API ๆดๅ
"A002", # builtin-shadowing โ `type`, `id`, `format` ๆฏ MCP tool ๅๆธ
]
"src/pubmed_search/application/**/*.py" = [
"BLE001", # blind-except โ session ็ฎก็้ๅฎน้ฏ I/O ้ฏ่ชค
"PLR2004", # magic-value โ ่จญๅฎๅธธๆธ
"ARG002", # unused-method-argument โ ๆฝ่ฑกๆนๆณๅฏฆไฝ
]
".mutmut_config.py" = ["ALL"] # auto-generated config
"vulture_whitelist.py" = ["ALL"] # vulture whitelist uses bare name expressions
"scripts/test-copilot-mcp.py" = [
"BLE001", # blind exception โ test script error handling
"INP001", # namespace package
]
[tool.ruff.format]
quote-style = "double"
indent-style = "space"
line-ending = "auto"
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# mypy โ ๐ PRODUCTION strict mode
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
[tool.mypy]
python_version = "3.10"
strict = true
# strict = true ๅ็จไปฅไธๆๆๅดๆ ผๆชขๆฅ๏ผ
# disallow_any_generics, disallow_untyped_defs, disallow_incomplete_defs,
# check_untyped_defs, no_implicit_optional, warn_redundant_casts,
# warn_unused_ignores, warn_return_any, no_implicit_reexport,
# strict_equality, strict_concatenate
# โโ ้ๅฐ็ฌฌไธๆนๅบซ็ๅๅฏฆ่ฑๅ
โโ
ignore_missing_imports = true # ็ฌฌไธๆนๅบซ็ผบๅฐ py.typed๏ผ้ๆญฅ็งป้ค๏ผ
warn_unused_ignores = false # ่ทจ Python ็ๆฌ็ type: ignore ็ธๅฎนๆง
# ๆผธ้ฒๅผๅดๆ ผๅ๏ผไปฅไธๆซๆๆพๅฏฌ๏ผๅพ
้ๆญฅไฟฎๅพฉๅพ็งป้ค
disallow_any_generics = false # 94 errors โ dict/list ็ผบๅฐ type args๏ผ้ๆญฅๅ ๅ
ฅ๏ผ
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# Bandit โ security linter (medium+ severity)
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
[tool.bandit]
# Only flag medium+ severity (skip low-noise rules)
skips = [
"B404", # import subprocess โ tooling scripts need it
"B603", # subprocess without shell=True โ scripts intentional
"B311", # pseudo-random โ not crypto, used for jitter/test data
]
exclude_dirs = ["tests", "scripts/_tmp"]
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# Deptry โ dependency hygiene
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
[tool.deptry]
extend_exclude = ["scripts", "tests", "docs"]
[tool.deptry.per_rule_ignores]
# DEP001 (missing): lazy optional imports โ installed separately when needed
DEP001 = ["fitz", "pdfplumber"]
# DEP002 (unused): indirect usage (biopythonโrequests, platform-specific pywin32)
DEP002 = ["requests", "pywin32"]
# DEP003 (transitive): re-exports or direct usage of transitive deps
DEP003 = ["typing_extensions", "pydantic", "uvicorn"]
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# Vulture โ dead code detection (config reference; run via pre-commit)
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# Whitelist: vulture_whitelist.py
# Command: uv run vulture src/ scripts/ vulture_whitelist.py --min-confidence 80
[[tool.mypy.overrides]]
module = "tests.*"
ignore_errors = true
[[tool.mypy.overrides]]
module = [
"pubmed_search.infrastructure.sources",
"pubmed_search.infrastructure.sources.*",
]
# ๅค้จ API ๅๆๆฌ่ณชไธๆฏๅๆ
็ (dict[str, Any])
disallow_untyped_defs = false
disallow_untyped_calls = false
warn_return_any = false
disable_error_code = ["no-untyped-def", "no-untyped-call", "no-any-return"]
[[tool.mypy.overrides]]
module = [
"pubmed_search.infrastructure.ncbi",
"pubmed_search.infrastructure.ncbi.*",
]
# NCBI API ๅๆ็ตๆง่ค้ไธๅค่ฎ
disallow_untyped_defs = false
disallow_untyped_calls = false
warn_return_any = false
disable_error_code = ["no-untyped-def", "no-untyped-call", "no-any-return"]
[[tool.mypy.overrides]]
module = [
"pubmed_search.infrastructure.pubtator",
"pubmed_search.infrastructure.pubtator.*",
]
# PubTator API ๅๆ
ๅๆ
disallow_untyped_defs = false
disallow_untyped_calls = false
warn_return_any = false
disable_error_code = ["no-untyped-def", "no-untyped-call", "no-any-return"]
[[tool.mypy.overrides]]
module = [
"pubmed_search.presentation",
"pubmed_search.presentation.*",
"pubmed_search.presentation.api.*",
"pubmed_search.presentation.mcp_server",
"pubmed_search.presentation.mcp_server.*",
"pubmed_search.presentation.mcp_server.tools.*",
]
# MCP tool/server ๅฝๆธ่็ๅๆ
ๆธๆ
disallow_untyped_defs = false
disallow_untyped_calls = false
warn_return_any = false
disable_error_code = ["no-untyped-def", "no-untyped-call", "no-any-return"]
[[tool.mypy.overrides]]
module = [
"pubmed_search.application.session",
"pubmed_search.application.session.*",
]
# Session ็ฎก็ๆถๅๅคง้ๅๆ
JSON ๆธๆ
disallow_untyped_defs = false
disallow_untyped_calls = false
warn_return_any = false
disable_error_code = ["no-untyped-def", "no-untyped-call", "no-any-return"]