refactor: move the demo blocks and script helpers out of the package - #65
Open
Hendrik-code wants to merge 1 commit into
Open
refactor: move the demo blocks and script helpers out of the package#65Hendrik-code wants to merge 1 commit into
Hendrik-code wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #64. Last of the deduplication PRs.
Three
__main__blocks leave the shipped package486 lines across
transforms/gpu/transforms.py,transforms/gpu/transforms_list.pyandtransforms/cpu/transforms.pybecome one parameterisedscripts/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)vscuda()— otherwise a 205-line copy of each other. They also importedcv2, 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
F811ruff carve-out, so that goes too.smauglab/utils/utils.py→scripts/_common.pyNothing 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 byscripts/train_monai.pyandscripts/generate_augmentations.py.config2parserandsig_fnhad no callers at all.Its
normalizebecomesnormalize_percentile— three functions in this repo shared that name and two computed different things. The min-max one now lives in the demo script asnormalize_minmax.smauglab/utils/image.pydeliberately stays. Five modules in the siblingsegtransferaugrepository importsmauglab.utils.image.Image, so it is public API in practice despite having no in-package consumer.Verification
utils/utils.py.--helpruns clean).ruffandmypyclean.One subtest fewer than the parent, as expected:
test_imports.pywalks the package's modules, and there is one less module.Usage
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.