Skip to content

Commit 83cf21d

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 83cf21d

22 files changed

+61
-52
lines changed

.github/actions/build_pandas/action.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ runs:
2525
- name: Build Pandas
2626
run: |
2727
if [[ ${{ inputs.editable }} == "true" ]]; then
28-
pip install -e . --no-build-isolation -v --no-deps \
29-
-Csetup-args="--werror"
28+
pip install -e . --no-build-isolation -v --no-deps
3029
else
31-
pip install . --no-build-isolation -v --no-deps \
32-
-Csetup-args="--werror"
30+
pip install . --no-build-isolation -v --no-deps
3331
fi
3432
shell: bash -el {0}

.github/workflows/code-checks.yml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ on:
1313
env:
1414
ENV_FILE: environment.yml
1515
PANDAS_CI: 1
16+
PKG_CONFIG_PATH: "${{env.PYTHONHOME}}/numpy/_core/lib/pkgconfig"
1617

1718
permissions:
1819
contents: read

.github/workflows/docbuild-and-upload.yml

+7
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,18 @@ jobs:
4040
with:
4141
fetch-depth: 0
4242

43+
- name: Determine NumPy pkg-config location
44+
run: |
45+
echo pkg_conf: "$(python -c 'import site; print(site.getsitepackages()[0])')/numpy/_core/lib/pkgconfig"
46+
echo "PKG_CONFIG_PATH=$(python -c 'import site; print(site.getsitepackages()[0])')/numpy/_core/lib/pkgconfig" >> $GITHUB_ENV
47+
4348
- name: Set up Conda
4449
uses: ./.github/actions/setup-conda
4550

4651
- name: Build Pandas
4752
uses: ./.github/actions/build_pandas
53+
env:
54+
PKG_CONFIG_PATH=${{env.PKG_CONFIG_PATH}}
4855

4956
- name: Extra installs
5057
# https://pytest-qt.readthedocs.io/en/latest/troubleshooting.html#github-actions-azure-pipelines-travis-ci-and-gitlab-ci-cd

.github/workflows/unit-tests.yml

+11-8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ defaults:
2020
run:
2121
shell: bash -el {0}
2222

23+
env:
24+
PKG_CONFIG_PATH: "${{env.PYTHONHOME}}/numpy/_core/lib/pkgconfig"
25+
2326
jobs:
2427
ubuntu:
2528
runs-on: ${{ matrix.platform }}
@@ -244,10 +247,10 @@ jobs:
244247
run: |
245248
/opt/python/cp313-cp313/bin/python -m venv ~/virtualenvs/pandas-dev
246249
. ~/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
250+
python -m pip install --no-cache-dir -U pip wheel setuptools meson[ninja]==1.4.0 meson-python==0.13.1
248251
python -m pip install numpy -Csetup-args="-Dallow-noblas=true"
249252
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
250-
python -m pip install --no-cache-dir --no-build-isolation -e . -Csetup-args="--werror"
253+
python -m pip install --no-cache-dir --no-build-isolation -e .
251254
python -m pip list --no-cache-dir
252255
PANDAS_CI=1 python -m pytest -m 'not slow and not network and not clipboard and not single_cpu' pandas --junitxml=test-data.xml
253256
concurrency:
@@ -282,9 +285,9 @@ jobs:
282285
run: |
283286
/opt/python/cp313-cp313/bin/python -m venv ~/virtualenvs/pandas-dev
284287
. ~/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
288+
python -m pip install --no-cache-dir -U pip wheel setuptools meson-python==0.13.1 meson[ninja]==1.4.0
286289
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
287-
python -m pip install --no-cache-dir --no-build-isolation -e . -Csetup-args="--werror"
290+
python -m pip install --no-cache-dir --no-build-isolation -e .
288291
python -m pip list --no-cache-dir
289292
290293
- name: Run Tests
@@ -353,10 +356,10 @@ jobs:
353356
- name: Build Environment
354357
run: |
355358
python --version
356-
python -m pip install --upgrade pip setuptools wheel meson[ninja]==1.2.1 meson-python==0.13.1
359+
python -m pip install --upgrade pip setuptools wheel meson[ninja]==1.4.0 meson-python==0.13.1
357360
python -m pip install --pre --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy
358361
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
359-
python -m pip install -ve . --no-build-isolation --no-index --no-deps -Csetup-args="--werror"
362+
python -m pip install -ve . --no-build-isolation --no-index --no-deps
360363
python -m pip list
361364
362365
- name: Run Tests
@@ -395,10 +398,10 @@ jobs:
395398
- name: Build Environment
396399
run: |
397400
python --version
398-
python -m pip install --upgrade pip setuptools wheel numpy meson[ninja]==1.2.1 meson-python==0.13.1
401+
python -m pip install --upgrade pip setuptools wheel numpy meson[ninja]==1.4.0 meson-python==0.13.1
399402
python -m pip install --pre --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple cython
400403
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
401-
python -m pip install -ve . --no-build-isolation --no-index --no-deps -Csetup-args="--werror"
404+
python -m pip install -ve . --no-build-isolation --no-index --no-deps
402405
python -m pip list
403406
404407
- name: Run Tests

.github/workflows/wheels.yml

+8
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ jobs:
5757
with:
5858
python-version: '3.11'
5959

60+
- name: Determine NumPy pkg-config location
61+
run: |
62+
echo "PKG_CONFIG_PATH=$(python -c 'import site; print(site.getsitepackages()[0])')/numpy/_core/lib/pkgconfig" >> $GITHUB_ENV
63+
6064
- name: Build sdist
6165
run: |
6266
python -m pip install build
@@ -140,6 +144,10 @@ jobs:
140144
shell: bash -el {0}
141145
run: echo "sdist_name=$(ls ./dist)" >> "$GITHUB_ENV"
142146

147+
- name: Determine NumPy pkg-config location
148+
run: |
149+
echo "PKG_CONFIG_PATH=$(python -c 'import site; print(site.getsitepackages()[0])')/numpy/_core/lib/pkgconfig" >> $GITHUB_ENV
150+
143151
# Python version used to build sdist doesn't matter
144152
# wheel will be built from sdist with the correct version
145153
- name: Unzip sdist (macOS)

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

requirements-dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
pip
55
versioneer[toml]
66
cython~=3.0.5
7-
meson[ninja]==1.2.1
7+
meson[ninja]==1.4.0
88
meson-python==0.13.1
99
pytest>=7.3.2
1010
pytest-cov

0 commit comments

Comments
 (0)