Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

ENH: add pkg_config entrypoint #28214

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 9 commits into from
Feb 5, 2025
Merged

Conversation

FFY00
Copy link
Contributor

@FFY00 FFY00 commented Jan 22, 2025

This makes pkgconf-pypi be able to pickup NumPy's pkg-config file.

@ngoldbaum
Copy link
Member

Any chance you can add a test showing that the entry point works? Not sure if that's doable without adding pkgconfig-pypi as a test dependency.

@rgommers
Copy link
Member

I think we'll be using this new entrypoint in a CI job in gh-26574, so a dedicated test here may not be the best way of spending time. @FFY00 please correct me if I am wrong there.

@rgommers
Copy link
Member

That gh-26574 PR is pretty small - in case the issue we ran into there is fully fixed, please feel free to fold those changes into this PR.

@ngoldbaum
Copy link
Member

ngoldbaum commented Jan 24, 2025

EDIT: oops, wrong branch checked out

@ngoldbaum
Copy link
Member

It looks like this is working, but I did notice something a little weird when I tried testing. It looks like if you use pkgconf.get_pkg_config_path() before importing NumPy, then import NumPy, the module is broken:

goldbaum at Mac in ~/Documents
○  python
Python 3.13.1 experimental free-threading build (main, Dec 10 2024, 14:07:41) [Clang 16.0.0 (clang-1600.0.26.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pkgconf
>>> list(pkgconf.get_pkg_config_path())
['/Users/goldbaum/.pyenv/versions/3.13.1t/lib/python3.13t/site-packages/numpy/_core/lib/pkgconfig']
>>> import numpy
>>> numpy.__version__
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    numpy.__version__
AttributeError: module 'numpy' has no attribute '__version__'
>>> quit

goldbaum at Mac in ~/Documents
○  python
Python 3.13.1 experimental free-threading build (main, Dec 10 2024, 14:07:41) [Clang 16.0.0 (clang-1600.0.26.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import pkgconf
>>> list(pkgconf.get_pkg_config_path())
['/Users/goldbaum/.pyenv/versions/3.13.1t/lib/python3.13t/site-packages/numpy/_core/lib/pkgconfig']
>>> numpy.__version__
'2.3.0.dev0+git20250122.deb4bf3'

That seems like a bug in the pkgconf-pypi project though and probably unrelated to merging this.

@FFY00
Copy link
Contributor Author

FFY00 commented Jan 24, 2025

Yeah, I don't think we really need a test, defining an entrypoint is very low-risk. If anything, what could make sense is making sure its value is correct, for the .pc file path.

@FFY00
Copy link
Contributor Author

FFY00 commented Jan 24, 2025

I added a test to check the entrypoint. While I was at it, I also refactored a bit the test_configtool helpers to make them a bit more reliable, and moved them to numpy.testing.

@FFY00 FFY00 force-pushed the pkgconfig-entrypoint branch 2 times, most recently from 97292b8 to 7fef045 Compare January 24, 2025 21:18
@FFY00
Copy link
Contributor Author

FFY00 commented Jan 24, 2025

It looks like this is working, but I did notice something a little weird when I tried testing. It looks like if you use pkgconf.get_pkg_config_path() before importing NumPy, then import NumPy, the module is broken:

That must have to do with our lazy loading, which we need to do to resolve the path of the module specified in the entrypoint without actually executing the module, in case that raises an exception. I'll look into it.

@FFY00 FFY00 force-pushed the pkgconfig-entrypoint branch 5 times, most recently from a814d04 to d298264 Compare January 26, 2025 03:52
@FFY00
Copy link
Contributor Author

FFY00 commented Jan 26, 2025

I believe the CI failure is unrelated, could someone trigger a re-run of the job? Thanks!

@rgommers
Copy link
Member

I believe the CI failure is unrelated, could someone trigger a re-run of the job? Thanks!

I re-ran it now. It is very likely related though - that's the one job that uses an editable install and builds extension modules with f2py, so I think your tweaks to determining IS_EDITABLE for the test suite are responsible.

FFY00 added 6 commits January 30, 2025 03:40
Signed-off-by: Filipe Laíns <lains@riseup.net>
Signed-off-by: Filipe Laíns <lains@riseup.net>
Signed-off-by: Filipe Laíns <lains@riseup.net>
…ported

Signed-off-by: Filipe Laíns <lains@riseup.net>
Signed-off-by: Filipe Laíns <lains@riseup.net>
Signed-off-by: Filipe Laíns <lains@riseup.net>
@FFY00 FFY00 force-pushed the pkgconfig-entrypoint branch from 3a4a3c0 to 68a501c Compare January 30, 2025 03:40
Signed-off-by: Filipe Laíns <lains@riseup.net>
@FFY00 FFY00 force-pushed the pkgconfig-entrypoint branch from e8b70bf to 12f69e0 Compare January 30, 2025 04:43
@FFY00
Copy link
Contributor Author

FFY00 commented Jan 30, 2025

Alright, everything's good now 😅

Copy link
Member

@ngoldbaum ngoldbaum left a comment

Choose a reason for hiding this comment

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

Thanks this looks like a nice cleanup! Sorry my comment led to you discovering a bunch of issues but I'm glad you found and fixed things. I didn't look it over carefully but I will soon if someone else doesn't in the meantime.

@FFY00
Copy link
Contributor Author

FFY00 commented Jan 31, 2025

No worries, this did highlight some un-engornomic aspects of the importlib.metadata API (python/importlib_metadata#510, python/importlib_metadata#511), which was helpful.

The test_core_shims_coherence failure was due to the entrypoint lookup importing namespace packages, like numpy._core.lib.pkgconfig, which do not contain any code, so we don't care about them in the test.

The IS_INSTALLED workaround is very specific to this project, as environment.yml includes scipy for the docs, which pulls numpy, and then spin installs the project directly using Meson, which doesn't install metadata, so we do find the metadata for a numpy distribution, but it's the one from the base environment 🙃

@rgommers
Copy link
Member

@FFY00 you're adding an unconditional test dependency here, which is undesirable. Was the old method to determine IS_EDITABLE silently broken without us noticing? If not, what's the problem with continuing to use it?

The test_core_shims_coherence failure was due to the entrypoint lookup importing namespace packages, like numpy._core.lib.pkgconfig, which do not contain any code, so we don't care about them in the test.

If it's helpful to make it not a namespace package by adding an extra __init__.py, that'd be fine.

@FFY00
Copy link
Contributor Author

FFY00 commented Jan 31, 2025

@FFY00 you're adding an unconditional test dependency here, which is undesirable. Was the old method to determine IS_EDITABLE silently broken without us noticing? If not, what's the problem with continuing to use it?

It depends on meson-python implementation details, and is incorrectly true if the environment prefix contains "editable" anywhere.

The unconditional test dependency is only on older Python versions, so it's temporary. It could be worked around by reading direct_url.json manually, but I generally prefer against that kind of fix as it introduces complexity and creates nontrivial future work. The importlib_metadata backport dependency will go away in a couple versions, and all we have to do is remove the version check. That said, if you prefer to work around the missing importlib.metadata API on older versions, I can do that, it's not a problem.

If it's helpful to make it not a namespace package by adding an extra __init__.py, that'd be fine.

No, we explicitly don't want those modules to show in test_core_shims_coherence, which tests if we re-export everything from numpy._core.

@rgommers
Copy link
Member

It depends on meson-python implementation details, and is incorrectly true if the environment prefix contains "editable" anywhere.

Yes I know, that's fine. Those are pretty minor downsides that don't matter in practice (and in case meson-python changes, is easy to fix up), so I'd much prefer not to add a dependency - that is very costly, since it affects not only CI but pretty much all distro packagers as well as contributors.

@rgommers
Copy link
Member

I'd be okay with an optional test dependency, but keeping the fallback to the current method is necessary instead of failing outright.

@FFY00
Copy link
Contributor Author

FFY00 commented Jan 31, 2025

I backported importlib.metadata.Distribution.origin, which I think is less confusing to read than keeping the old check. Let's see if the CI is happy.

@FFY00 FFY00 force-pushed the pkgconfig-entrypoint branch 5 times, most recently from 5f3f9a7 to 89bf31b Compare January 31, 2025 13:20
Signed-off-by: Filipe Laíns <lains@riseup.net>
@FFY00 FFY00 force-pushed the pkgconfig-entrypoint branch from 89bf31b to f6d44cc Compare January 31, 2025 13:58
@FFY00
Copy link
Contributor Author

FFY00 commented Jan 31, 2025

The CI seems to be happy now.

Copy link
Member

@ngoldbaum ngoldbaum left a comment

Choose a reason for hiding this comment

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

I trust you to know the packaging details here better than I do.

It's technically a new feature so I think it needs a release note.

Also this is not your fault and it's not incumbent on you to fix in this PR, but it looks the only place numpy-config is documented is in the release notes. Maybe we could add a note to the docstring for np.show_config? Or give it its own page somewhere?

@FFY00
Copy link
Contributor Author

FFY00 commented Feb 5, 2025

I trust you to know the packaging details here better than I do.

Packaging-wise, this only adds metadata, so it's a very low-risk change when it comes to the NumPy project itself 1. They only affect the usage of the pkgconf package, which hasn't seen much adaption yet, so very low risk for any breakage of any kind. Adoption is we are attempting to bootstrap here, starting with NumPy providing the necessary metadata, and going on from there. Even within the pkgconf package context, the metadata we are exposing here is pretty low-risk — we are just pointing to the Python package containing the .pc file.

It's technically a new feature so I think it needs a release note.

Ah, yes, it definitely makes sense mentioning this in the release notes.

Also this is not your fault and it's not incumbent on you to fix in this PR, but it looks the only place numpy-config is documented is in the release notes. Maybe we could add a note to the docstring for np.show_config? Or give it its own page somewhere?

I am happy to do this, but maybe it'd be better to do it in a separate PR? So that we can discuss its documentation details without impacting the pkgconf entrypoints implementation.

Footnotes

  1. The main change, I mean. The test changes are riskier, as most changes are, but they only affect development, so that shouldn't matter much here.

Signed-off-by: Filipe Laíns <lains@riseup.net>
@ngoldbaum
Copy link
Member

I am happy to do this, but maybe it'd be better to do it in a separate PR?

Sounds great! I'm going to merge this now.

@ngoldbaum ngoldbaum merged commit 2308775 into numpy:main Feb 5, 2025
67 checks passed
@rgommers rgommers added this to the 2.3.0 release milestone Feb 6, 2025
DimitriPapadopoulos added a commit to DimitriPapadopoulos/numpy that referenced this pull request Apr 17, 2025
Asserting on a non-empty string literal will always pass

This line of code had been modified by numpy#28214 / b45b614 without any
explanation. I believe that's an error as the current asertion is a
no-op. So revert to actually test something in this test.
DimitriPapadopoulos added a commit to DimitriPapadopoulos/numpy that referenced this pull request Apr 17, 2025
Asserting on a non-empty string literal will always pass

This line had been modified by numpy#28214 / b45b614 without any explanation.
I believe that's an error as the current asertion is a no-op. So revert
to actually test something!
DimitriPapadopoulos added a commit to DimitriPapadopoulos/numpy that referenced this pull request Apr 17, 2025
Asserting on a non-empty string literal will always pass

This line had been modified by numpy#28214 / b45b614 without any explanation.
I believe it's an error as the current assertion is a no-op. Change to
have the test actually test something.
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.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.