8000 MNT: use pythoncapi_compat.h in npy_compat.h by ngoldbaum · Pull Request #26189 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MNT: use pythoncapi_compat.h in npy_compat.h #26189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 3, 2024

Conversation

ngoldbaum
Copy link
Member
@ngoldbaum ngoldbaum commented Apr 1, 2024

Following on from #26158 and #26159, this adds a new submodule for pythoncapi_compat.h and includes it in npy_pycompat.h. I also removed all the spots where npy_pycompat.h was getting included unnecessarily, probably leftovers from the python 2->3 migrations.

This doesn't actually use the new header yet, that will come in followups.

@seberg
Copy link
Member
seberg commented Apr 2, 2024

In the past we used very few macro definitions and that also felt much to use a submodule (and the full file which has a lot of things we don't need).

I suspect we still only use a small, but significantly larger, fraction of them all and we have a lot of submodules now anyway.
So I lean towards this making sense even if we end up using very few functions, there are probably some other small nice things which we get this way without having to think about it (i.e. NewRef).

Copy link
Contributor
@mhvk mhvk left a comment

Choose a reason for hiding this comment

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

Yes, seems a sensible way to go. I guess eventually the submodule will disappear again, once borrowed references are a thing of the past? And that any actual changes in the code to use new routines that give new references will be done in follow-up?

p.s. I had to do a bit of a double-take since you seemed to remove the usage of the headers that you were introducing, but that just meant I should have read your comments better...

@ngoldbaum
Copy link
Member Author

I guess eventually the submodule will disappear again, once borrowed references are a thing of the past?

Maybe but I don’t see the CPython C API remaining static after the nogil effort over the next few years, and this way we don’t need to maintain our own compatibility shims. I also like these shims because their names match the upstream names so they don’t need another migration in the future to get rid of them besides removing the compat header include.

Copy link
Member
@rgommers rgommers left a comment

Choose a reason for hiding this comment

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

This LGTM overall, thanks @ngoldbaum. _core/src/common seems like the right place to put this. I have one suggestion to avoid contributors being puzzled after a git pull and missing the submodule - add this near the top of numpy/_core/meson.build:

  if not fs.exists('src/common/pythoncapi-compat')
    error('Missing the `pythoncapi-compat` git submodule! Run `git submodule update --init` to fix this.')
  endif

There are a couple of other checks like that already, like for svml and highway.

@rgommers rgommers added this to the 2.1.0 release milestone Apr 3, 2024
Copy link
Member
@rgommers rgommers left a comment

Choose a reason for hiding this comment

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

Reviewers seem happy and CI seems happy, so let's give it a go:) Thanks Nathan, all!

@rgommers rgommers merged commit e59c074 into numpy:main Apr 3, 2024
@rgommers rgommers added the 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703) label Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
03 - Maintenance 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0