Repository navigation
Conversation
There was a problem hiding this comment.
Thank you for contributing a pull request! 🙏
Welcome to the ITK community! 🤗👋☀️
We are glad you are here and appreciate your contribution. Please keep in mind our community participation guidelines. 📜
More support and guidance on the contribution process can be found in our contributing guide. 📖
This is an automatic message. Allow for time for the ITK community to be able to read the pull request and comment
on it.
There was a problem hiding this comment.
Pull request overview
Adds a CMake configure-time guard to fail fast when configuring ITK Python wrapping with the Python Limited API while using a system SWIG version known to generate wrappers that later fail at import time (SWIG ≥ 4.4.0). This prevents late runtime import errors by providing an early, actionable configuration error.
Changes:
- Add a
FATAL_ERRORconfigure-time check forITK_USE_SYSTEM_SWIG=ON+ITK_WRAP_PYTHON=ON+ITK_USE_PYTHON_LIMITED_API=ONwhenSWIG_VERSION >= 4.4.0. - Provide user guidance in the error text with suggested configuration alternatives (use SWIG 4.3.x, disable Limited API, or disable system SWIG).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Known-broken combination: system SWIG 4.4.x with Python Limited API emits | ||
| # wrappers that fail at import time (missing delete_SwigPyIterator on moduledef). | ||
| if(ITK_WRAP_PYTHON AND ITK_USE_PYTHON_LIMITED_API AND SWIG_VERSION VERSION_GREATER_EQUAL 4.4.0) | ||
| message( | ||
| FATAL_ERROR | ||
| "System SWIG ${SWIG_VERSION} with ITK_USE_PYTHON_LIMITED_API=ON is currently unsupported due to import-time wrapper failures. Use system SWIG 4.3.x, set ITK_USE_PYTHON_LIMITED_API=OFF, or set ITK_USE_SYSTEM_SWIG=OFF." | ||
| ) | ||
| endif() |
| # Known-broken combination: system SWIG 4.4.x with Python Limited API emits | ||
| # wrappers that fail at import time (missing delete_SwigPyIterator on moduledef). |
There was a problem hiding this comment.
Clarify blocked versions
The guard blocks every SWIG_VERSION VERSION_GREATER_EQUAL 4.4.0, but the comment narrows the rationale to 4.4.x. That mismatch can mislead future maintainers into thinking 4.5.0 and later should not be rejected even though the condition intentionally fails fast for them.
Context Used: AGENTS.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
14df2a3 to
526aa0d
Compare
|
Applied the wording nit from review: updated the in-file note to say SWIG 4.4+ (matching the VERSION_GREATER_EQUAL 4.4.0 guard) in commit 4b11d44. |
|
Preferably squash upon merge. |
|
Or even better, squash into one commit now. |
Signed-off-by: SID <nandasiddhardha@gmail.com>
4b11d44 to
3eccfe7
Compare
|
Done. I squashed the branch into a single commit as requested and force-pushed: 3eccfe7. |
hjmjohnson
left a comment
There was a problem hiding this comment.
Thanks for the PR, but this guard blocks a configuration that now works. The failure described in #6479 was fixed by #6484 (merged 2026-06-23), which moved ITK's Python wrapping to SWIG 4.4.1 and added a runtime shim for SWIG 4.4's PEP 489 multi-phase init.
Details
- SWIG 4.4 makes
PyInit_*return a rawPyModuleDef; ITK's injected module-packing code previously stored that directly insys.modules, producing the'moduledef' object has no attribute 'delete_SwigPyIterator'import failure. - #6484 added detection of the returned def and instantiation via
PyModule_FromDefAndSpec+PyModule_ExecDef(Wrapping/Generators/Python/CMakeLists.txt). The shim lives in ITK's generated glue, so it applies equally to system and vendored SWIG. - The vendored SWIG is now itself 4.4.1, so CI exercises SWIG 4.4.1 + Limited API on every run — the exact combination this guard rejects.
- #6479 stayed open only because the fixing PR's body didn't use a GitHub auto-close keyword; it is now closed as fixed.
This PR should be closed as obsolete — on current main there is no broken combination to guard against, and the existing swig_version_min check already handles too-old system SWIG.
|
@SID-6921 I think you probably built this PR on an intermediate ITKv6 codebase. This has been fixed in the main branch. See detailed analysis #6544 (review). Thank you for the contribution! Keep suggestions coming! |
Summary
Why
Issue #6479 documents that this combination can compile/link but then fails at import with missing delete_SwigPyIterator from the generated limited-API wrapper module. This change prevents users from reaching that late failure mode.
User guidance in error
The message recommends one of:
Testing