Skip to content

RFC: restrict wcs extension modules to CPython's limited API - #18231

Merged
mcara merged 1 commit into
astropy:mainfrom
neutrinoceros:bld/wcs/limited_api_compat
Jul 11, 2025
Merged

mcara merged 1 commit into
astropy:mainfrom
neutrinoceros:bld/wcs/limited_api_compat

Conversation

@neutrinoceros

@neutrinoceros neutrinoceros commented Jun 7, 2025 •

Copy link
Copy Markdown
Contributor

Description

Following @da-woods' advice, I think I got most of this right, but I'm still struggling to resolve the last compilation-error I'm getting, namely:

astropy/wcs/src/astropy_wcs.c:774:28: error: initializer element is not a compile-time constant
  774 | static PyObject* WcsType = PyType_FromSpec(&WCSBaseClass_spec);
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

At this point, I'd like to ask @astrofrog and @da-woods for a hand solving this last bit.
Partially address #18163

update: notes to reviewers

  • in a couple places I added FIXME comments indicating what I believe are bug-for-bug refactors, where I found some methods defined but not included in their natural parent structs
  • a couple of functions were simply replaced with a slower equivalent (e.g. Py_List_GET_ITEM -> Py_List_GetItem). It should be possible to instead select the version we want at compile time using #ifdef ... pre-proc directives (if we keep LIMITED_API as a opt-in build option). Let me know if this (small) additional complexity is desired.
  • because my primary source of information when working on this were compilation errors and warnings, I ended up fixing many unrelated but noisy warning about mismatched pointer types (i.e. PY_XDECREF expects a PyObject* pointer)
  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

@github-actions

github-actions Bot commented Jun 7, 2025

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@github-actions

github-actions Bot commented Jun 7, 2025

Copy link
Copy Markdown
Contributor

👋 Thank you for your draft pull request! Do you know that you can use [ci skip] or [skip ci] in your commit messages to skip running continuous integration tests until you are ready?

@neutrinoceros neutrinoceros changed the title BLD: refactor astropy_wcs Cython module for compatibility with CPython's limited API BLD: refactor astropy_wcs Cython module for compatibility with CPython's limited API Jun 7, 2025
@astrofrog

Copy link
Copy Markdown
Member

@neutrinoceros just to check, did you forget to paste the error?

Comment thread astropy/wcs/src/astropy_wcs.c Outdated
Comment thread astropy/wcs/src/astropy_wcs.c
@neutrinoceros

Copy link
Copy Markdown
Contributor Author

Whoops, yes ! thanks for your quick response !

Comment thread astropy/wcs/src/astropy_wcs.c Outdated
@neutrinoceros
neutrinoceros force-pushed the bld/wcs/limited_api_compat branch from 4b64975 to fac10b9 Compare June 7, 2025 18:07
Comment thread astropy/wcs/src/astropy_wcs.c Outdated
@neutrinoceros
neutrinoceros force-pushed the bld/wcs/limited_api_compat branch 2 times, most recently from 0713776 to 4e74776 Compare June 7, 2025 18:24
@neutrinoceros
neutrinoceros force-pushed the bld/wcs/limited_api_compat branch from 4e74776 to 26acbf4 Compare June 7, 2025 18:26
@neutrinoceros
neutrinoceros marked this pull request as ready for review June 7, 2025 18:38
@neutrinoceros
neutrinoceros requested a review from mcara as a code owner June 7, 2025 18:38
@neutrinoceros neutrinoceros changed the title BLD: refactor astropy_wcs Cython module for compatibility with CPython's limited API BLD: refactor astropy_wcs extension module for compatibility with CPython's limited API Jun 8, 2025
@neutrinoceros
neutrinoceros force-pushed the bld/wcs/limited_api_compat branch from 26acbf4 to a5249ed Compare June 8, 2025 08:12
@neutrinoceros neutrinoceros changed the title BLD: refactor astropy_wcs extension module for compatibility with CPython's limited API BLD: restrict C-API usage in wcs extensions to Limited API Jun 8, 2025
@neutrinoceros
neutrinoceros marked this pull request as draft June 8, 2025 08:13
@neutrinoceros
neutrinoceros force-pushed the bld/wcs/limited_api_compat branch from a5249ed to 8edb949 Compare June 8, 2025 08:19
Comment thread astropy/wcs/src/str_list_proxy.c
@neutrinoceros
neutrinoceros force-pushed the bld/wcs/limited_api_compat branch 3 times, most recently from d6b457b to 161d76b Compare June 8, 2025 12:13
@neutrinoceros
neutrinoceros marked this pull request as ready for review June 9, 2025 16:40
@astrofrog

Copy link
Copy Markdown
Member

What an epic effort - nice work! 👏

Comment thread astropy/wcs/src/pyutil.c Outdated
@neutrinoceros
neutrinoceros requested a review from taldcroft as a code owner June 10, 2025 07:13
@neutrinoceros
neutrinoceros force-pushed the bld/wcs/limited_api_compat branch 2 times, most recently from 9ac87c6 to fd79957 Compare June 10, 2025 07:29
Comment thread astropy/wcs/src/pyutil.c Outdated
@neutrinoceros
neutrinoceros force-pushed the bld/wcs/limited_api_compat branch 2 times, most recently from 0ab79bb to 65b7559 Compare June 10, 2025 08:21
@astrofrog

Copy link
Copy Markdown
Member

@neutrinoceros - could you rebase this so that it picks up the multiple limited API CI jobs?

@astrofrog

Copy link
Copy Markdown
Member

@mcara @nden - just to check, would either of you have time in the near future to review this? Or would you be happy for others to review/approve if ready?

@neutrinoceros
neutrinoceros force-pushed the bld/wcs/limited_api_compat branch from 65b7559 to 46f5179 Compare June 19, 2025 09:18
@neutrinoceros

Copy link
Copy Markdown
Contributor Author

rebased !

@mcara

mcara commented Jun 23, 2025

Copy link
Copy Markdown
Contributor

I would prefer to review myself in order to understand (for my own education) the proposed changes but I will not be able to look at this PR in detail for the next 2 weeks. At first glance (without me following all the links to CPython and initial issues), changes look non-controversial. So I am fine with someone else reviewing this PR, especially if time is critical.

@neutrinoceros

Copy link
Copy Markdown
Contributor Author

rebased with no modifications to refresh CI

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to have a look, and made some comments, in particular about decref'ing what I think are borrowed references (from Py_TYPE). Not sure I'm correct, or that I caught all. Am a bit worried that, if my reasoning is correct, this is not caught by testing. In numpy, there is a test run that somehow checks things more carefully -- cannot easily find out right now what that is (am travelling), but can try next week.

Comment thread astropy/wcs/src/pyutil.c
Comment thread astropy/wcs/src/wcslib_celprm_wrap.c
Comment thread astropy/wcs/src/wcslib_prjprm_wrap.c
Comment thread astropy/wcs/src/wcslib_tabprm_wrap.c
Comment thread astropy/wcs/src/wcslib_wrap.c
Comment thread astropy/wcs/src/wcslib_wtbarr_wrap.c
@neutrinoceros
neutrinoceros force-pushed the bld/wcs/limited_api_compat branch from 5ee3035 to 93c37b1 Compare July 7, 2025 12:30
@neutrinoceros

Copy link
Copy Markdown
Contributor Author

Time is still not critical, but I'd like to emphasize that this the last remaining PR for making astropy (as a whole) limited-api compliant.

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With my earlier worries proven wrong, I think this is all OK, so approving. I'll leave merging to the wcs team, though.

Really nice work!

@astrofrog

Copy link
Copy Markdown
Member

@mcara @nden - this should be merged before my preserve_units PR, happy to rebase mine

@mcara mcara left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you!

I run regression tests on drizzlepac and they all pass. All stwcs and tweakwcs unit tests pass as well.

@mcara
mcara merged commit 91fc8bc into astropy:main Jul 11, 2025
@neutrinoceros
neutrinoceros deleted the bld/wcs/limited_api_compat branch July 11, 2025 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants