Skip to content

BUG: Replace distutils.version with a standard-library comparison - #479

Open
hjmjohnson wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:comp-replace-distutils
Open

BUG: Replace distutils.version with a standard-library comparison#479
hjmjohnson wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:comp-replace-distutils

Conversation

@hjmjohnson

@hjmjohnson hjmjohnson commented Sep 12, 2026

Copy link
Copy Markdown
Member

Python 3.12 removed distutils, which ten examples imported to check ITK's
version. Compare the dotted components as a tuple instead, dropping the
import entirely.

The failure

Every affected example guards its minimum ITK version like this:

from distutils.version import StrictVersion as VS

if VS(itk.Version.GetITKVersion()) < VS("4.9.0"):
    print("ITK 4.9.0 is required.")
    sys.exit(1)

On Python 3.12 and newer the import raises before the example runs:

Traceback (most recent call last):
ModuleNotFoundError: No module named 'distutils'

The replacement keeps each example's own minimum and drops the import:

if tuple(int(v) for v in itk.Version.GetITKVersion().split(".")) < (4, 9, 0):
Also fixed: a latent NameError in the same guard

SegmentBloodVessels and SegmentBloodVesselsWithMultiScaleHessianBasedMeasure call sys.exit() in that block without importing sys, so on an older ITK they would raise NameError instead of printing the message. Both now import it.

Verification

Built against ITK main with Python 3.14.6 and run through the project's own ctest Python suite:

before after
Python tests failing 10 2

All eight distutils casualties pass. The two remaining failures are unrelated to this change and were failing beforehand: ConvolveImageWithKernelTestPython needs matplotlib, which is absent from that environment, and ComputeFFTInOneDimensionPhaseBaselineComparisonPython fails a baseline image comparison (ImageError 25.13, 4 pixels).

pre-commit run --all-files passes, and no distutils reference remains in the repository.

@github-actions github-actions Bot added type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances area:Core Issues affecting the Core module area:Filtering Issues affecting the Filtering module area:Registration Issues affecting the Registration module area:Bridge Issues affecting the Bridge module area:Nonunit Issues affecting the Nonunit module language:Python Changes to Python examples labels Sep 12, 2026
@hjmjohnson
hjmjohnson marked this pull request as ready for review September 12, 2026 13:59
@hjmjohnson
hjmjohnson force-pushed the comp-replace-distutils branch from f49d826 to fea7e67 Compare September 12, 2026 14:04
@hjmjohnson
hjmjohnson requested a review from dzenanz September 12, 2026 14:44
@hjmjohnson
hjmjohnson force-pushed the comp-replace-distutils branch from fea7e67 to 78ffaa7 Compare September 12, 2026 18:36
Python 3.12 removed distutils, so every example guarding its minimum ITK
version with distutils.version.StrictVersion fails at import:

    ModuleNotFoundError: No module named 'distutils'

Compare the dotted version components as a tuple instead, which needs no
import at all and keeps each example's existing minimum.

SegmentBloodVessels and
SegmentBloodVesselsWithMultiScaleHessianBasedMeasure called sys.exit()
in that guard without importing sys; add the import.
@hjmjohnson
hjmjohnson force-pushed the comp-replace-distutils branch from 78ffaa7 to bae30bd Compare September 12, 2026 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Bridge Issues affecting the Bridge module area:Core Issues affecting the Core module area:Filtering Issues affecting the Filtering module area:Nonunit Issues affecting the Nonunit module area:Registration Issues affecting the Registration module language:Python Changes to Python examples type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant