-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add a system dependency for numpy #12891
base: master
Are you sure you want to change the base?
Conversation
This adds an `interpreter` keyword to `dependency()`, which is needed because there doesn't seem to be another way to get at the result of `import('python').find_installation(...)`. We need to access the installed `numpy` module into that Python installation. It's also possible that a user has multiple Python installations detection in their meson.build files; we can't know for which one they're looking for `numpy` (this would apply to any other Python package dependency). In order to use the system dependency, it is necessary to use it like: ```meson py = import('python').find_installation(pure: false) dependency('numpy', interpreter: py) ``` Alternatives to achieve this I considered are: - `dependency('numpy', interpreter: py.path())` # not as nice, but keeps keyword value as a string - `dependency('numpy', dependencies: py_dep)` [skip ci]
Would it be possible (and feasible) to make just this work instead:
and have it do all the needed lookups behind the scenes? Or possibly something lik
If the boilerplate is always the same, then this would save users from having to type it out every time. |
It'd be very desirable, however I couldn't find a way. To illustrate the problem in another way: imagine a Linux distro with a default Python version of 3.10 (executables meson setup build --native-file native-file.ini with [binaries]
python = '/path/to/python3.11' In such a case, |
How is this supposed to work with the |
That is a very good question @dnicolodi. I had only looked at it cursory, since I copied the logic exactly from
For Python tools the generic answer of the "multiple binaries with the same name" problem is to invoke them like I just created a dummy project like this: project('try-configtool', 'c')
dependency('pybind11') and verified that
Relying on an activated env seems okay, so There's another potential failure mode, which seems much more likely: |
Note that pybind11 is a C++ project. Not a python one. It doesn't matter which python version is used for the pybind11-config script, or indeed if there is one in the first place -- distros probably want to install pybind11 in global mode to /usr/include and /usr/share/pkgconfig. Numpy does depend on which version of python it is associated with due to codegen, right? |
It doesn't; the couple of headers that are created by codegen can have differences for the exact same numpy version due to compiler toolchain and other environment features (things like The main problem equally applies to |
Sure, and that's fine. Please add the constraint to There are several reasons it is relevant, including the fact that distros building with:
Sometimes that is pinned dependencies, sometimes that is additional dependencies (stuff like, but not limited to, accidentally adding a dependency on https://pypi.org/project/ninja/). |
That is fair, yes it's always a good idea. That said, it'll still be potentially confusing to ignore a |
This is fundamentally a matter of layering build environments. My understanding was that you'd suggested automatically adding to the beginning of import glob, os
paths = glob.glob(os.path.join(env_site_packages, '*/share/pkgconfig/')) |
agreed
Either that or trying |
As a follow-up to gh-12799, and addresses gh-9598.
Opening as draft for now, because the key issue (how to get at the target Python installation) required a new keyword for
dependency
, which I suspect is going to lead to a bit of discussion. To get at the rightnumpy
package, the install found byimport('python').find_installation(...)
must be used. There may even be several such installation objects floating around in a user'smeson.build
files. It doesn't seem possible to get at those without the user passing in the target interpreter. I went with this API:Alternatives to achieve this I considered are:
dependency('numpy', interpreter: py.path()) # not as nice, but does keep keyword value as a string
dependency('numpy', dependencies: py_dep)
modules
orcomponents
(but nothing really seems to fit here)Of course the last alternative is deciding that any of these solutions are not acceptable, and letting users wait until they no longer need NumPy 1.x (1.5 to 3 years from now for widely used packages). Until that time they'd have to use this very ugly code block to support 1.x:
https://github.com/PyWavelets/pywt/blob/e69b126c096868b0ea7650d38ed11cd95a9dc182/pywt/_extensions/meson.build#L15-L39
This new keyword is in principle not only applicable to numpy, but to system dependencies for other Python packages with C APIs as well. There aren't too many of those though, so I'm not sure how compelling an argument that is.