-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
ENH: Add entry point for Array API implementation #19800
Conversation
Could you add a test to |
Hope something like this is okay. Note my test uses |
NumPy has dropped support for 3.7 in CI testing, we are now 3.8+ only (on main for 1.22, we may release another 1.21 bugfix that will still support 3.7 at some point) |
|
So the issue is that <3.10 |
It seems the |
Not on my machine (the release notes say |
In Hypothesis we just try to use the new interface, and fall back to the old: try:
eps = importlib_metadata.entry_points(group="array_api")
except TypeError:
# Load-time selection requires Python >= 3.10 or importlib_metadata >= 3.6,
# so we'll retain this fallback logic for some time to come. See also
# https://importlib-metadata.readthedocs.io/en/latest/using.html
eps = importlib_metadata.entry_points().get("array_api", []) |
I followed Zac's example of fall-backing to the dict interface, so now (locally) the test runs nicely on both Python 3.10 and 3.8 🥳 |
6f54c21
to
79ff375
Compare
3.10 now works in CI, just not the debug server. The failing assertion:
i.e. no Array API entry points could be found... so it's likely the debug server doesn't build NumPy in such a way it looks at the specified entry point? It's 3.8, but the tests work locally on my 3.8.10 env. I can't figure out what |
I would wait until we actually decide if we are going to do data-apis/array-api#244 and finalize it in the spec before merging this. |
With that being said, it's useful to have an implementation. If anyone has any comments on this approach, and whether you like it or not, that would useful to hear as well. |
This seems very straightforward and simple to implement. Entry points have proven useful for command-line tools. It does suffer from the "one more standard" problem, but I think it is indeed useful. |
cbcc677
to
506ae06
Compare
@asmeurer has the Array API group reached a conclusion about entry points? |
People at the consortium meeting were generally amenable to the idea, but nothing has been added to the spec about it yet. |
Not sure what's up with Travis, but in regards to failing on debug job I have no idea. I burnt an hour trying to figure out what exactly in the build script (with the debug flag) doesn't expose the entrypoints... it's something I bet someone with experience with developing NumPy or packaging in general could solve quite easily heh. |
That entrypoints don't work in a debug build seems quite odd, but possibly is a known issue: microsoft/debugpy#165 is quite similar. The code in A pragmatic approach would be to skip this test on a debug build, which can be checked like so: import sysconfig
sysconfig.get_config_var('Py_DEBUG') Then open an issue to follow up. |
I could not reproduce this locally, this passes (on Ubuntu 20.04 focal, like the CI run):
Skipping the test on debug sound like a good solution. I didn't realize how new the |
5cd1a87
to
3b0f5ce
Compare
Co-authored-by: Zac Hatfield-Dodds <zac.hatfield.dodds@gmail.com>
Co-authored-by: Zac Hatfield-Dodds <zac.hatfield.dodds@gmail.com>
I now xfail the test when Optional entry points are now in the spec 🙂 |
Just a wild guess that this may have to do with using the system python3-dbg on that particular image. But I am happy to xfail the test. |
Thanks @honno |
On @mattip's suggestion, this PR simple adds an entry point for NumPy's Array API implementation in
setup.py
:entry_points={ 'console_scripts': f2py_cmds, + 'array_api': ['numpy = numpy.array_api'], },
The Data APIs consortium is currently discussing whether Array API adaptors should have an entry point to point to their actual implementation in data-apis/array-api#244. In summary: for array consuming libraries you can currently get the Array API namespace via
xp = x.__array_namespace__()
, but for array generating libraries (e.g. Hypothesis in HypothesisWorks/hypothesis#3065) the entry point would allow programmatic discovery of the available Array API implementations in the Python environment.I thought I'd make this PR more-so to demonstrate how the proposal would work in practice, and it's something that can be returned to if the proposal goes through.