Skip to content

Commit 563ea31

Browse files
BLD: use meson's NumPy resolution mechanism for building
Instead of querying the include folder's location from NumPy during building, use Meson's built-in dependency resolution for NumPy. With this change during build-time Meson first tries to query the dependency details using numpy-config (which, in turn essentially uses the same method as the original code this commit replaces), and in case that fails for some reason, it tries to discover NumPy resources using pkg-config - which, beside being a good fail-over mechanism, has the added benefit of somewhat simpler cross-compiling, as querying the include folder location from NumPy module is only usable for cross-compiling only in some corner cases, while pkg-config is a bit more universal. Signed-off-by: Gyorgy Sarvari <[email protected]>
1 parent f1b00b8 commit 563ea31

File tree

6 files changed

+20
-28
lines changed

6 files changed

+20
-28
lines changed

doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Other enhancements
8181
- Support passing a :class:`Iterable[Hashable]` input to :meth:`DataFrame.drop_duplicates` (:issue:`59237`)
8282
- Support reading Stata 102-format (Stata 1) dta files (:issue:`58978`)
8383
- Support reading Stata 110-format (Stata 7) dta files (:issue:`47176`)
84+
- Use Meson's native NumPy dependency resolution method for building (:issue:`61095`)
8485

8586
.. ---------------------------------------------------------------------------
8687
.. _whatsnew_300.notable_bug_fixes:

meson.build

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fs = import('fs')
1414
py = import('python').find_installation(pure: false)
1515
tempita = files('generate_pxi.py')
1616
versioneer = files('generate_version.py')
17-
17+
numpy_dep = dependency('numpy', method: 'auto')
1818

1919
add_project_arguments('-DNPY_NO_DEPRECATED_API=0', language: 'c')
2020
add_project_arguments('-DNPY_NO_DEPRECATED_API=0', language: 'cpp')

pandas/_libs/meson.build

+7-2
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,17 @@ if get_option('buildtype') == 'debug'
149149
endif
150150

151151
foreach ext_name, ext_dict : libs_sources
152+
dependencies = [numpy_dep]
153+
if ext_dict.has_key('deps')
154+
dependencies += ext_dict.get('deps')
155+
endif
156+
152157
py.extension_module(
153158
ext_name,
154159
ext_dict.get('sources'),
155160
cython_args: cython_args,
156-
include_directories: [inc_np, inc_pd],
157-
dependencies: ext_dict.get('deps', ''),
161+
include_directories: [inc_pd],
162+
dependencies: dependencies,
158163
subdir: 'pandas/_libs',
159164
install: true,
160165
)

pandas/_libs/tslibs/meson.build

+7-2
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,17 @@ if get_option('buildtype') == 'debug'
2929
endif
3030

3131
foreach ext_name, ext_dict : tslibs_sources
32+
dependencies = [numpy_dep]
33+
if ext_dict.has_key('deps')
34+
dependencies += ext_dict.get('deps')
35+
endif
36+
3237
py.extension_module(
3338
ext_name,
3439
ext_dict.get('sources'),
3540
cython_args: cython_args,
36-
include_directories: [inc_np, inc_pd],
37-
dependencies: ext_dict.get('deps', ''),
41+
include_directories: [inc_pd],
42+
dependencies: dependencies,
3843
subdir: 'pandas/_libs/tslibs',
3944
install: true,
4045
)

pandas/_libs/window/meson.build

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ py.extension_module(
22
'aggregations',
33
['aggregations.pyx'],
44
cython_args: ['-X always_allow_keywords=true'],
5-
include_directories: [inc_np, inc_pd],
5+
include_directories: [inc_pd],
6+
dependencies: [numpy_dep],
67
subdir: 'pandas/_libs/window',
78
override_options: ['cython_language=cpp'],
89
install: true,
@@ -12,7 +13,8 @@ py.extension_module(
1213
'indexers',
1314
['indexers.pyx'],
1415
cython_args: ['-X always_allow_keywords=true'],
15-
include_directories: [inc_np, inc_pd],
16+
include_directories: [inc_pd],
17+
dependencies: [numpy_dep],
1618
subdir: 'pandas/_libs/window',
1719
install: true,
1820
)

pandas/meson.build

-21
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,3 @@
1-
incdir_numpy = run_command(
2-
py,
3-
[
4-
'-c',
5-
'''
6-
import os
7-
import numpy as np
8-
try:
9-
# Check if include directory is inside the pandas dir
10-
# e.g. a venv created inside the pandas dir
11-
# If so, convert it to a relative path
12-
incdir = os.path.relpath(np.get_include())
13-
except Exception:
14-
incdir = np.get_include()
15-
print(incdir)
16-
''',
17-
],
18-
check: true,
19-
).stdout().strip()
20-
21-
inc_np = include_directories(incdir_numpy)
221
inc_pd = include_directories('_libs/include')
232

243
fs.copyfile('__init__.py')

0 commit comments

Comments
 (0)