Skip to content

Commit d62c160

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 d62c160

17 files changed

+35
-43
lines changed

.github/workflows/unit-tests.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ jobs:
244244
run: |
245245
/opt/python/cp313-cp313/bin/python -m venv ~/virtualenvs/pandas-dev
246246
. ~/virtualenvs/pandas-dev/bin/activate
247-
python -m pip install --no-cache-dir -U pip wheel setuptools meson[ninja]==1.2.1 meson-python==0.13.1
247+
python -m pip install --no-cache-dir -U pip wheel setuptools meson[ninja]==1.4.0 meson-python==0.13.1
248248
python -m pip install numpy -Csetup-args="-Dallow-noblas=true"
249249
python -m pip install --no-cache-dir versioneer[toml] cython python-dateutil pytest>=7.3.2 pytest-xdist>=3.4.0 hypothesis>=6.84.0
250250
python -m pip install --no-cache-dir --no-build-isolation -e . -Csetup-args="--werror"
@@ -282,7 +282,7 @@ jobs:
282282
run: |
283283
/opt/python/cp313-cp313/bin/python -m venv ~/virtualenvs/pandas-dev
284284
. ~/virtualenvs/pandas-dev/bin/activate
285-
python -m pip install --no-cache-dir -U pip wheel setuptools meson-python==0.13.1 meson[ninja]==1.2.1
285+
python -m pip install --no-cache-dir -U pip wheel setuptools meson-python==0.13.1 meson[ninja]==1.4.0
286286
python -m pip install --no-cache-dir versioneer[toml] cython numpy python-dateutil pytest>=7.3.2 pytest-xdist>=3.4.0 hypothesis>=6.84.0
287287
python -m pip install --no-cache-dir --no-build-isolation -e . -Csetup-args="--werror"
288288
python -m pip list --no-cache-dir
@@ -353,7 +353,7 @@ jobs:
353353
- name: Build Environment
354354
run: |
355355
python --version
356-
python -m pip install --upgrade pip setuptools wheel meson[ninja]==1.2.1 meson-python==0.13.1
356+
python -m pip install --upgrade pip setuptools wheel meson[ninja]==1.4.0 meson-python==0.13.1
357357
python -m pip install --pre --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy
358358
python -m pip install versioneer[toml] python-dateutil tzdata cython hypothesis>=6.84.0 pytest>=7.3.2 pytest-xdist>=3.4.0 pytest-cov
359359
python -m pip install -ve . --no-build-isolation --no-index --no-deps -Csetup-args="--werror"
@@ -395,7 +395,7 @@ jobs:
395395
- name: Build Environment
396396
run: |
397397
python --version
398-
python -m pip install --upgrade pip setuptools wheel numpy meson[ninja]==1.2.1 meson-python==0.13.1
398+
python -m pip install --upgrade pip setuptools wheel numpy meson[ninja]==1.4.0 meson-python==0.13.1
399399
python -m pip install --pre --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple cython
400400
python -m pip install versioneer[toml] python-dateutil pytz tzdata hypothesis>=6.84.0 pytest>=7.3.2 pytest-xdist>=3.4.0 pytest-cov
401401
python -m pip install -ve . --no-build-isolation --no-index --no-deps -Csetup-args="--werror"

ci/deps/actions-310-minimum_versions.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dependencies:
99
# build dependencies
1010
- versioneer
1111
- cython>=0.29.33
12-
- meson=1.2.1
12+
- meson=1.4.0
1313
- meson-python=0.13.1
1414

1515
# test dependencies

ci/deps/actions-310.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dependencies:
77
# build dependencies
88
- versioneer
99
- cython>=0.29.33
10-
- meson=1.2.1
10+
- meson=1.4.0
1111
- meson-python=0.13.1
1212

1313
# test dependencies

ci/deps/actions-311-downstream_compat.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ dependencies:
88
# build dependencies
99
- versioneer
1010
- cython>=0.29.33
11-
- meson=1.2.1
11+
- meson=1.4.0
1212
- meson-python=0.13.1
1313

1414
# test dependencies

ci/deps/actions-311-numpydev.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ dependencies:
66

77
# build dependencies
88
- versioneer
9-
- meson=1.2.1
9+
- meson=1.4.0
1010
- meson-python=0.13.1
1111
- cython>=0.29.33
1212

ci/deps/actions-311-pyarrownightly.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ dependencies:
66

77
# build dependencies
88
- versioneer
9-
- meson=1.2.1
9+
- meson=1.4.0
1010
- cython>=0.29.33
1111
- meson-python=0.13.1
1212

ci/deps/actions-311.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dependencies:
77
# build dependencies
88
- versioneer
99
- cython>=0.29.33
10-
- meson=1.2.1
10+
- meson=1.4.0
1111
- meson-python=0.13.1
1212

1313
# test dependencies

ci/deps/actions-312.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dependencies:
77
# build dependencies
88
- versioneer
99
- cython>=0.29.33
10-
- meson=1.2.1
10+
- meson=1.4.0
1111
- meson-python=0.13.1
1212

1313
# test dependencies

ci/deps/actions-pypy-39.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dependencies:
1010
# build dependencies
1111
- versioneer
1212
- cython>=0.29.33
13-
- meson=1.2.1
13+
- meson=1.4.0
1414
- meson-python=0.13.1
1515

1616
# test dependencies

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:

environment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dependencies:
99
# build dependencies
1010
- versioneer
1111
- cython~=3.0.5
12-
- meson=1.2.1
12+
- meson=1.4.0
1313
- meson-python=0.13.1
1414

1515
# test dependencies

meson.build

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ project(
66
'cython',
77
version: run_command(['generate_version.py', '--print'], check: true).stdout().strip(),
88
license: 'BSD-3',
9-
meson_version: '>=1.2.1',
9+
meson_version: '>=1.4.0',
1010
default_options: ['buildtype=release', 'c_std=c11', 'warning_level=2'],
1111
)
1212

1313
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')

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# See https://github.com/scipy/scipy/pull/12940 for the AIX issue.
44
requires = [
55
"meson-python>=0.13.1",
6-
"meson>=1.2.1,<2",
6+
"meson>=1.4.0,<2",
77
"wheel",
88
"Cython~=3.0.5", # Note: sync with setup.py, environment.yml and asv.conf.json
99
# Force numpy higher than 2.0rc1, so that built wheels are compatible

0 commit comments

Comments
 (0)