ENH: Update to minimum Python support to py310#6012
ENH: Update to minimum Python support to py310#6012hjmjohnson merged 8 commits intoInsightSoftwareConsortium:mainfrom
Conversation
|
| Filename | Overview |
|---|---|
| .pre-commit-config.yaml | Updated black target from py39 to py310 and pyupgrade from --py39-plus to --py310-plus; both active and commented-out args updated consistently |
| Documentation/docs/contributing/python_packaging.md | Updated Python >= 3.9 to >= 3.10 and refreshed example wheel build script invocations and output filenames |
| Testing/ContinuousIntegration/AzurePipelinesLinux.yml | Updated Azure Pipelines pre-commit job Python version spec from 3.9 to 3.10 |
| Wrapping/Generators/Python/CMakeLists.txt | Updated configure_file reference from itkConfig.py.in to itkConfig.template.in.py following the file rename |
| Wrapping/Generators/Python/itkConfig.template.in.py | Renamed from itkConfig.py.in; removed typing imports and replaced with built-in generics and X |
| Wrapping/Generators/Python/itk/pyi_generator.py | Removed top-level Union import; updated two function return annotations to use str |
| Wrapping/Generators/Python/itk/support/types.py | Removed Optional import; updated GetCType and GetCTypeForDType return types to X |
| Wrapping/Generators/Python/itk/support/template_class.py | Moved Callable import from typing to collections.abc; replaced Union[str, Callable] with str |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Python runtime imports itk] --> B{pyBase.i version check\nif _version_info < 3,9,0}
B -->|Python < 3.9| C[RuntimeError: Python 3.9 or later required\n⚠️ Message still says 3.9]
B -->|Python >= 3.9| D[Continue module loading]
D --> E{Python version?}
E -->|Python 3.9| F[TypeError: unsupported operand type\nfor | in union annotations\ne.g. str | None]
E -->|Python >= 3.10| G[Imports succeed ✅]
H[CMakeLists.txt / PYTHON_VERSION_MIN=3.10] -.->|Build-time enforcement| A
style C fill:#ffcccc
style F fill:#ffcccc
style G fill:#ccffcc
Greploops — Automatically fix all review issues by running /greploops in Claude Code. It iterates: fix, push, re-review, repeat until 5/5 confidence.
Use the Greptile plugin for Claude Code to query reviews, search comments, and manage custom context directly from your terminal.
Reviews (2): Last reviewed commit: "ENH: Rename itkConfig.py.in to itkConfig..." | Re-trigger Greptile
29d9b1b to
eccb91f
Compare
ITK v6.0 requires Python >= 3.10 for wrapping. Update the LinuxCxx20 CI job to use Python 3.10 instead of 3.9. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Update the minimum Python version requirement from 3.9 to 3.10 and modernize the wheel build examples from cp38/ITK 5.3 to cp310/ITK 6.0. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Python 3.9 reached end-of-life in October 2025. Update black and pyupgrade to target Python 3.10+, which is the oldest supported release. - black: --target-version py39 -> py310 - pyupgrade: --py39-plus -> --py310-plus This aligns ITK's pre-commit config with BRAINSTools (which already uses py310) and drops support for a Python version that is no longer maintained. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
511815e to
9f9b850
Compare
Modernize type annotations in ITK Python wrapping code: - Union[X, Y] -> X | Y (PEP 604) - Optional[X] -> X | None (PEP 604) - typing.Callable -> collections.abc.Callable (PEP 585) These syntax forms are supported in Python >= 3.10. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Manually apply PEP 604/585 modernizations to itkConfig.py.in since pre-commit hooks (black, pyupgrade) skip .py.in files: - Union[Warning, str] -> Warning | str - Type[Warning] -> type[Warning] - Optional[str] -> str | None - Dict[str, List[str]] -> dict[str, list[str]] - Remove 'from typing import Dict, List, Optional, Type, Union' Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fea2085 to
af68b5c
Compare
Rename the CMake configure_file template so that it has a .py extension and is recognized as Python by pre-commit hooks (black, pyupgrade, check-ast). The .py.in extension was classified as plain text by the identify library, causing all Python linting hooks to skip the file. The output filename remains itkConfig.py — only the source template name changes. Apply black formatting now that the file is covered by pre-commit. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The pyupgrade --py310-plus conversion changed: Union["itkt.TransformBase", list["itkt.TransformBase"]] to: "itkt.TransformBase" | list["itkt.TransformBase"] This fails at runtime because Python evaluates annotations eagerly by default, and str.__or__(GenericAlias) is not defined. Adding `from __future__ import annotations` defers all annotation evaluation to string form, making PEP 604 union syntax safe even with forward references. pyupgrade then also removes the now-unnecessary string quotes from other forward reference annotations. Fixes 169 Python test failures in ITK.Linux.Python and ITK.macOS.Python CI. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The runtime version guard in pyBase.i checked for Python 3.9 but CMake/ITKSetPython3Vars.cmake already sets PYTHON_VERSION_MIN=3.10, and the codebase now uses Python 3.10-only syntax (PEP 604 unions). A Python 3.9 user would pass the old guard but immediately hit a TypeError at import time from the X|Y type annotations. Update the check and error message to match the CMake minimum, as the comment in pyBase.i instructs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
dzenanz
left a comment
There was a problem hiding this comment.
Looks good, but preferably someone else should also review.
|
Updating pre-commit and updating python in wrapping seem like two rather different things. |
@blowekamp updated the PR comment to reflect the full scope of these changes. Let me know if you want something else done. |
Summary
blackandpyupgradeto target Python 3.10+, the oldest actively supported release.black--target-version py39--target-version py310pyupgrade--py39-plus--py310-plusThis aligns ITK's pre-commit config with BRAINSTools (which already uses
py310targets) and drops enforcement of syntax compatibility with an unsupported Python version.Test plan
pre-commit run --all-filespasses on this branch with no regressions.🤖 Generated with Claude Code