Repository navigation
Expand file tree
/
Copy pathpyproject.toml
More file actions
406 lines (371 loc) · 13.6 KB
/
Copy pathpyproject.toml
File metadata and controls
406 lines (371 loc) · 13.6 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
[tool.poetry]
name = "TPTBox"
version = "0.0.0"
description = "A Torso Processing Toolbox capable of processing BIDS-compatible datasets, singular niftys, points of interests, segmentations, and much more."
authors = [
"Robert Graf <robert.graf@tum.de>",
"Hendrik Möller <hendrik.moeller@tum.de>",
]
repository = "https://github.com/Hendrik-code/TPTBox"
license = "Apache License Version 2.0, January 2004"
readme = "README.md"
packages = [{ include = "TPTBox" }]
[tool.poetry.dependencies]
python = "^3.9 || ^3.10 || ^3.11 || ^3.12 || ^3.13 || ^3.14"
nibabel = "^5.2.0"
typing-extensions = "^4.9.0"
SimpleITK = "^2.3.1"
matplotlib = "^3.8.2"
dill = "^0.3.7"
fill-voids = "^2.0.6"
connected-components-3d = "^3.12.3"
tqdm = "*"
joblib = "*"
scikit-learn = "*"
pynrrd = "*"
requests = "*"
trimesh = "*"
# trimesh's ray engine does its broad phase through rtree, which trimesh itself only
# declares under its `easy` extra. Without it every mesh ray cast raises
# ModuleNotFoundError, which takes out spine.spinestats.measure_ivd_and_vertebra_geometry
# and spinestats.poi_fun.endplates.
rtree = "*"
numpy-stl = "*"
# --- OLD STACK (Python < 3.11)
numpy = [
{ version = ">=1.26.3,<2.0", python = "<3.11" },
{ version = ">=2.0,<3.0", python = ">=3.11" }
]
scipy = [
{ version = ">=1.11,<1.13", python = "<3.11" },
{ version = ">=1.13", python = ">=3.11" }
]
scikit-image = [
{ version = ">=0.22,<0.23", python = "<3.11" },
{ version = ">=0.24", python = ">=3.11" }
]
# --- OPTIONAL EXTRAS -------------------------------------------------------
# Declared here so `pip install "TPTBox[dicom]"` resolves them, but marked
# optional so a plain install stays light. The matching sub-packages
# (TPTBox.core.dicom, TPTBox.segmentation) import successfully without these
# and only raise - naming the extra - when an entry point is actually called.
pydicom = { version = "*", optional = true }
# dicom2nifti 2.6.0 imports `pydicom.pixels` while still declaring
# `pydicom >= 2.2`, and 2.6.1+ require `pydicom >= 3.0` outright. pydicom 3
# needs python >= 3.10, so 2.5.x is the newest dicom2nifti that works on 3.9.
dicom2nifti = [
{ version = "<2.6.0", python = "<3.10", optional = true },
{ version = "*", python = ">=3.10", optional = true },
]
# dicom2nifti requires `python-gdcm` with no upper bound, and on 3.9 nnunetv2
# 2.4.2 (the `seg` extra) pulls dicom2nifti in as well. python-gdcm stopped
# shipping cp39 wheels after 3.2.2 but still advertises
# `requires-python = ">=3.7"`, so a resolver picks 3.2.6 on 3.9 and then fails
# building its sdist - the tarball has no CMakeLists.txt. Cap it at the last
# release with cp39 wheels; >=3.10 takes whatever dicom2nifti resolves to.
python-gdcm = { version = "<=3.2.2", python = "<3.10", optional = true }
torch = { version = "*", optional = true }
# Mirror SPINEPS' own constraint so `TPTBox[seg]` and `spineps` can co-install.
# nnunetv2 2.8+ requires Python >=3.10, so 3.9 stays on the last release supporting it.
# TPTBox.segmentation.nnUnet_utils is a self-contained fork: it builds its own
# PlansManager from the checkpoint's plans.json and never instantiates nnU-Net's,
# so it is not tied to a particular nnU-Net plans layout.
nnunetv2 = [
{ version = "==2.4.2", python = "<3.10", optional = true },
{ version = ">=2.8,<3.0", python = ">=3.10", optional = true },
]
acvl-utils = { version = "*", optional = true }
batchgenerators = { version = "*", optional = true }
# Distribution is `hf-deepali`; the import name is `deepali`. Do NOT shorten it -
# a bare `deepali` on PyPI is an unrelated project.
hf-deepali = { version = "*", optional = true }
# `spineps` is deliberately absent: it depends on TPTBox itself, so declaring it
# here would be a circular dependency. It stays a documented `pip install spineps`.
[tool.poetry.extras]
dicom = ["pydicom", "dicom2nifti", "python-gdcm"]
seg = ["torch", "nnunetv2", "acvl-utils", "batchgenerators"]
reg = ["torch", "hf-deepali"]
[tool.poetry.group.dev.dependencies]
pytest = ">=8.1.1"
# vtk 9.7.0 dropped cp39 wheels (and publishes no requires-python metadata,
# so Poetry cannot exclude it automatically). Pin the last cp39 release there.
vtk = [
{ version = ">=9.0,<9.7", python = "<3.10" },
{ version = "*", python = ">=3.10" },
]
pre-commit = "*"
pyvista = "^0.43.2"
coverage = ">=7.0.1"
pytest-mock = "^3.6.0"
# The `dicom` extra, in the dev group so unit_tests/test_dicom.py and
# test_dicom_renamer.py run in CI instead of only where the extra is installed.
# Deliberately unmarked: a `python = ">=3.10"` marker here does not keep the pair
# off 3.9. Poetry 2.2 merges this declaration with the optional one above into a
# group marker that still mentions `extra == "dicom"` and then installs the
# package on 3.9 anyway - that is how python-gdcm 3.2.6 reached the 3.9 leg and
# broke it. The cp39 wheel problem is fixed by the caps above instead. On 3.9 the
# resolver lands on pydicom 2.4.4 / dicom2nifti 2.5.1, which both modules pass on.
pydicom = "*"
dicom2nifti = "*"
networkx = "*" # optional: np_split_connected_component(method="mincut")
exceptiongroup = { version = "^1.2", python = "<3.11" }
tomli = {version = "*", python = "<3.11" }
# Extra optional deps used by TPTBox.mesh3D (3D snapshots and HTML previews).
# Kept in the dev group so CPU-only mesh tests can run in CI without pulling
# them into every install.
# fury 2.x is a full pygfx-based rewrite that removed `window.record` and
# changed `ShowManager` / `Scene` signatures used by TPTBox.mesh3D.snapshot3D.
# Pin to the last VTK-backed line until snapshot3D is ported.
fury = ">=0.9,<2.0"
Pillow = "*"
xvfbwrapper = { version = "*", markers = "sys_platform == 'linux'" }
[tool.poetry.group.docs.dependencies]
mkdocs = ">=1.6"
mkdocs-material = ">=9.5"
mkdocstrings = {extras = ["python"], version = ">=0.25"}
mkdocs-gen-files = ">=0.5"
mkdocs-literate-nav = ">=0.6"
[build-system]
requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"]
build-backend = "poetry_dynamic_versioning.backend"
[tool.poetry-dynamic-versioning]
enable = true
[tool.ruff]
namespace-packages = ["datagen"]
exclude = [
"*.ipynb",
".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",
".toml",
]
line-length = 140
indent-width = 4
target-version = "py310"
[tool.ruff.lint]
## Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
## Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
## McCabe complexity (`C901`) by default.
#
select = [
"E",
"F",
"W",
"C901",
"I",
"N",
"UP",
"ASYNC",
"BLE",
"B",
"A",
"C4",
"ICN",
"G",
"INP",
"PIE",
"PYI",
#"RET",
"SIM",
"TID",
"INT",
"ARG",
#"PTH",
"TD005",
"FIX003",
"FIX004",
#"ERA",
"D",
"ANN201",
"PD",
"PGH",
"PL",
"TRY",
"FLY",
"NPY",
"AIR",
"PERF",
"FURB",
"RUF",
]
ignore = [
"C901",
"RUF059",
"RUF100",
"F401",
"BLE001",
"E501",
"N801",
"NPY002",
"PD002",
"PERF203",
"PTH123",
"PGH003",
"PLR0911",
"PLR0912",
"PLR0913",
"PLR0915",
"PLR0917",
"PLR2004",
"TRY301",
"SIM105",
"TRY003",
"N999",
"E741",
"SIM118", # dictionary keys
"N802", # function name lowercase
"F811",
"N803",
"N806",
"FURB171",
"PLW0108",
"B905", # strict= in zip
"UP007", # Union and "|" python 3.9
"PLC0415", # import-outside-top-level
# Docstring rules relaxed for internal / magic / dunder members
"D100", # missing docstring in public module
"D104", # missing docstring in public package
"D105", # missing docstring in magic method
"D107", # missing docstring in __init__ (covered by class docstring)
# Argument descriptions in existing docstrings — addressed progressively
"D417",
# Return-type annotation not required for private helpers
"ANN202",
# En-dashes (–) in docstrings are legitimate range notation (e.g. "C1–C7")
"RUF002",
"PLR0917", # Too many positional arguments
"UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)`
]
# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []
extend-safe-fixes = ["RUF015", "C419", "C408", "B006"]
#unnecessary-iterable-allocation-for-first-element = true
# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
[tool.ruff.lint.pydocstyle]
convention = "google"
[tool.ruff.lint.per-file-ignores]
# Test files: don't require docstrings on test functions / helper utilities
"unit_tests/**" = ["D101", "D102", "D103", "D205", "D415", "ANN201"]
"TPTBox/tests/**" = ["D101", "D102", "D103", "D205", "D415", "ANN201"]
# Dev tooling (standalone scripts): same relaxed docstring rules, not an importable package
"benchmarks/**" = ["D101", "D102", "D103", "D205", "D415", "ANN201", "INP001"]
[tool.ruff.lint.mccabe]
# Flag errors (`C901`) whenever the complexity level exceeds 5.
max-complexity = 20
[tool.pytest.ini_options]
filterwarnings = [
"ignore::DeprecationWarning",
"ignore::FutureWarning",
]
[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"if __name__ == .__main__.:",
"def __repr__",
"except",
"import warnings",
"warnings\\.warn",
"warnings\\.filter",
"print\\(f?\"\\[!\\].*",
"def __str__(self):",
"def __hash__(self) -> int:",
"assert ",
"if TYPE_CHECKING: ",
"raise "
]
# Curated: every entry here is code a unit test cannot legitimately reach. Anything
# that is merely awkward to test is NOT listed - it gets a test instead. The PR that
# introduced this list reports the coverage number both with and without it.
omit = [
# Hand-run micro-benchmarks. The filenames do not match pytest's `test_*.py`, so
# they are measured but never executed.
"TPTBox/tests/speedtests/*",
# --- Vendored nnU-Net inference internals -------------------------------------
# Carried from upstream nnU-Net with no TPTBox-specific logic; reachable only with
# real weights on a GPU. TPTBox's own entry point around them,
# nnUnet_utils/inference_api.py, is deliberately NOT omitted and is tested with a
# mock at the model boundary.
"TPTBox/segmentation/nnUnet_utils/predictor.py",
"TPTBox/segmentation/nnUnet_utils/plans_handler.py",
"TPTBox/segmentation/nnUnet_utils/export_prediction.py",
"TPTBox/segmentation/nnUnet_utils/default_preprocessor.py",
"TPTBox/segmentation/nnUnet_utils/data_iterators.py",
"TPTBox/segmentation/nnUnet_utils/get_network_from_plans.py",
"TPTBox/segmentation/nnUnet_utils/sliding_window_prediction.py",
# GPU memory probing: shells out to nvidia-smi in a measurement loop.
"TPTBox/segmentation/nnUnet_utils/estimate_nnunet_memory.py",
# --- nnU-Net training drivers --------------------------------------------------
# Need a populated nnUNet_raw / nnUNet_preprocessed tree and a GPU.
"TPTBox/core/internal/train_nnUnet/*",
# --- Permanently unimportable --------------------------------------------------
# Both import `nipy`, which is not a declared dependency of this package (or
# installable on current Python). test_docs_examples.py already special-cases
# script_ax2sag for the same reason.
"TPTBox/registration/script_ax2sag.py",
"TPTBox/registration/_ridged_intensity/register.py",
# --- Dead vendored deepali optimisation engine ---------------------------------
# An adapted copy of deepali's own registration engine. It imports `yaml`, which is
# not declared either, and nothing in the public API reaches it: the package is
# referenced only by deformable_reg_old.py and grid_search.py, which are themselves
# unreferenced. Candidate for deletion rather than coverage.
"TPTBox/registration/_deformable/_deepali/*",
"TPTBox/registration/_deformable/deformable_reg_old.py",
"TPTBox/registration/_deformable/grid_search.py",
"TPTBox/registration/_deformable/_grid_search_vert.py",
# --- NAKO dataset pipelines ----------------------------------------------------
# Interactive input() prompts, hard-coded /DATA/NAS dataset roots, process pools
# over a private dataset, and pandas/Excel reporting over a finished run.
"TPTBox/spine/spinestats/_load_nako_wh.py",
"TPTBox/spine/spinestats/_load_nako.py",
"TPTBox/spine/spinestats/_run_all.py",
"TPTBox/spine/spinestats/_qc_report.py",
# --- One-off repair script -----------------------------------------------------
# Walks a real dataset and rewrites pickles in place.
"TPTBox/core/dicom/fix_brocken.py",
]
[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
# Enable reformatting of code snippets in docstrings.
docstring-code-format = true
# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"
# Add this to your setting.json (user)
# Ctrl+shift+P settings json
#"[python]": {
# "editor.formatOnSave": true,
# "editor.defaultFormatter": "charliermarsh.ruff",
# "editor.codeActionsOnSave": {
# "source.fixAll": "explicit",
# "source.organizeImports": "never"
# }
# },
# "notebook.formatOnSave.enabled": true,
# "notebook.codeActionsOnSave": {
# "source.fixAll": false,
# "source.organizeImports": false
# },