Skip to content

refactor: move the demo blocks and script helpers out of the package - #65

Open
Hendrik-code wants to merge 1 commit into
hm/dedup-trainer-tailfrom
hm/demo-script
Open

refactor: move the demo blocks and script helpers out of the package#65
Hendrik-code wants to merge 1 commit into
hm/dedup-trainer-tailfrom
hm/demo-script

Conversation

@Hendrik-code

Copy link
Copy Markdown
Collaborator

Stacked on #64. Last of the deduplication PRs.

Three __main__ blocks leave the shipped package

486 lines across transforms/gpu/transforms.py, transforms/gpu/transforms_list.py and transforms/cpu/transforms.py become one parameterised scripts/demo_augmentations.py.

None of them could run for anyone but their author. All three hardcoded absolute paths into one person's machine, and the two GPU blocks differed only in that path and in cuda(device=7) vs cuda() — otherwise a 205-line copy of each other. They also imported cv2, which is not a SmaugLab dependency, so they'd have failed at import for anyone who did try. The script writes PNGs through torchvision, which is a dependency.

The real cost was that they shipped in the wheel: 486 lines of dead demonstration code in the installed package. The wheel is now 26 modules.

Dropping them removes the only reason for the F811 ruff carve-out, so that goes too.

smauglab/utils/utils.pyscripts/_common.py

Nothing under smauglab/ imported it once the demo blocks were gone. It's MONAI training-loop helpers, argparse tuple parsers and a Dice function, used only by scripts/train_monai.py and scripts/generate_augmentations.py. config2parser and sig_fn had no callers at all.

Its normalize becomes normalize_percentile — three functions in this repo shared that name and two computed different things. The min-max one now lives in the demo script as normalize_minmax.

smauglab/utils/image.py deliberately stays. Five modules in the sibling segtransferaug repository import smauglab.utils.image.Image, so it is public API in practice despite having no in-package consumer.

Verification

  • The 24-config seeded digests are unchanged.
  • The wheel builds and carries 26 modules / 30 configs, with no utils/utils.py.
  • Both scripts still import and parse their arguments (--help runs clean).
  • Full suite: 105 passed, 199 subtests. ruff and mypy clean.

One subtest fewer than the parent, as expected: test_imports.py walks the package's modules, and there is one less module.

Usage

# GPU pipeline, two subjects batched together (what the old GPU demos did)
python scripts/demo_augmentations.py \
    --image sub-01_T1w.nii.gz --seg sub-01_dseg.nii.gz \
    --image sub-02_T2w.nii.gz --seg sub-02_dseg.nii.gz \
    --config smauglab/configs/transform_params_gpu.json --device cuda:0

# CPU pipeline, a grid of repeated draws (what the old CPU demo did)
python scripts/demo_augmentations.py --backend cpu --repeats 24 \
    --image sub-01_T1w.nii.gz --seg sub-01_dseg.nii.gz

The shape/NaN assertions the old demos made inline are kept — they're the reason the script is worth having, since a pipeline that changes shape or emits NaN is broken in a way the unit tests' 24-voxel volumes don't always surface.

Three `if __name__ == "__main__":` blocks -- 486 lines across
transforms/gpu/transforms.py, transforms/gpu/transforms_list.py and
transforms/cpu/transforms.py -- become one parameterised
scripts/demo_augmentations.py.

None of them could run for anyone but their author. All three hardcoded absolute
paths into one person's machine, and the two GPU blocks differed only in that
path and in cuda(device=7) vs cuda(); they were otherwise a 205-line copy of each
other. They also imported cv2, which is not a SmaugLab dependency, so they would
have failed at import for anyone who did try. The script writes PNGs through
torchvision, which is a dependency.

They shipped in the wheel, which is the real cost: 486 lines of dead
demonstration code in the installed package. The wheel is now 26 modules.

Dropping them removes the only reason for the F811 ruff carve-out, so that goes
too.

smauglab/utils/utils.py moves to scripts/_common.py. Nothing under smauglab/
imported it once the demo blocks were gone -- it is MONAI training-loop helpers,
argparse tuple parsers and a Dice function, used only by scripts/train_monai.py
and scripts/generate_augmentations.py. config2parser and sig_fn had no callers at
all. Its `normalize` becomes normalize_percentile, because three functions in
this repository shared that name and two of them computed different things; the
min-max one now lives in the demo script as normalize_minmax.

smauglab/utils/image.py deliberately stays. Five modules in the sibling
segtransferaug repository import smauglab.utils.image.Image, so it is public API
in practice despite having no in-package consumer.

Verified: the 24-config seeded digests are unchanged, the wheel still builds and
carries 26 modules and 30 configs with no utils/utils.py, and both scripts still
import and parse their arguments.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 20, 2026 12:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants