Skip to content
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 numpy dependency with pkg-config and configtool methods #12799

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/markdown/Dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,14 @@ The `language` keyword may used.

`method` may be `auto`, `pkg-config`, `system` or `cmake`.

## NumPy

*(added 1.4.0)*

`method` may be `auto`, `pkg-config`, or `config-tool`.
`dependency('numpy')` supports regular use of the NumPy C API.
Use of `numpy.f2py` for binding Fortran code isn't yet supported.

## pcap

*(added 0.42.0)*
Expand Down
9 changes: 9 additions & 0 deletions docs/markdown/snippets/numpy-custom-dependency.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## New numpy custom dependency

Support for `dependency('numpy')` was added, via supporting the `numpy-config` tool and
pkg-config support, both of which are available since NumPy 2.0.0.

Config-tool support is useful because it will work out of the box when
``numpy`` is installed, while the pkg-config file is located inside python's
site-packages, which makes it impossible to use in an out of the box manner
without setting `PKG_CONFIG_PATH`.
1 change: 1 addition & 0 deletions mesonbuild/dependencies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ def __init__(self, name: str, environment: 'Environment', kwargs: T.Dict[str, T.
'appleframeworks': 'platform',

# from python:
'numpy': 'python',
'python3': 'python',
'pybind11': 'python',

Expand Down
17 changes: 17 additions & 0 deletions mesonbuild/dependencies/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ def __init__(self, name: str, environment: Environment, kwargs: T.Dict[str, T.An
self.compile_args = self.get_config_value(['--includes'], 'compile_args')


class NumPyConfigToolDependency(ConfigToolDependency):

tools = ['numpy-config']

def __init__(self, name: str, environment: Environment, kwargs: T.Dict[str, T.Any]):
super().__init__(name, environment, kwargs)
if not self.is_found:
return
self.compile_args = self.get_config_value(['--cflags'], 'compile_args')


class BasicPythonExternalProgram(ExternalProgram):
def __init__(self, name: str, command: T.Optional[T.List[str]] = None,
ext_prog: T.Optional[ExternalProgram] = None):
Expand Down Expand Up @@ -412,3 +423,9 @@ def set_env(name: str, value: str) -> None:
[DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL, DependencyMethods.CMAKE],
configtool_class=Pybind11ConfigToolDependency,
)

packages['numpy'] = numpy_factory = DependencyFactory(
'numpy',
[DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL],
configtool_class=NumPyConfigToolDependency,
)
Loading