Fail fast for system SWIG 4.4+ with Python limited API#6544
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. |
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