Files
ports/math/py-numpy1/files/patch-numpy_tests_test__configtool.py
T
Charlie Li 28081ef832 math/py-numpy1: backport configtool/pkg-config file from numpy 2
Traditionally the way to query for the numpy C API has been through
distutils/setuptools, but the use of setuptools beyond a PEP-517
build backend is increasingly discouraged. numpy 2 introduced
numpy-config and a pkg-config file to allow consumer build systems
to better support the use of numpy as a dependency.

Based on: https://github.com/numpy/numpy/commit/2634f803313f349170c09606d3cc619accd72247

Reported by: fluffy
PR: 281470
2026-04-03 21:47:26 -04:00

45 lines
1.4 KiB
Python

--- numpy/tests/test_configtool.py.orig 2026-04-04 00:20:07 UTC
+++ numpy/tests/test_configtool.py
@@ -0,0 +1,41 @@
+import os
+import subprocess
+import sysconfig
+
+import pytest
+import numpy as np
+
+
+is_editable = not bool(np.__path__)
+numpy_in_sitepackages = sysconfig.get_path('platlib') in np.__file__
+# We only expect to have a `numpy-config` available if NumPy was installed via
+# a build frontend (and not `spin` for example)
+if not (numpy_in_sitepackages or is_editable):
+ pytest.skip("`numpy-config` not expected to be installed",
+ allow_module_level=True)
+
+
+def check_numpyconfig(arg):
+ p = subprocess.run(['numpy-config', arg], capture_output=True, text=True)
+ p.check_returncode()
+ return p.stdout.strip()
+
+
+def test_configtool_version():
+ stdout = check_numpyconfig('--version')
+ assert stdout == np.__version__
+
+
+def test_configtool_cflags():
+ stdout = check_numpyconfig('--cflags')
+ assert stdout.endswith(os.path.join('numpy', 'core', 'include'))
+
+
+def test_configtool_pkgconfigdir():
+ stdout = check_numpyconfig('--pkgconfigdir')
+ assert stdout.endswith(os.path.join('numpy', 'core', 'lib', 'pkgconfig'))
+
+ if not is_editable:
+ # Also check that the .pc file actually exists (unless we're using an
+ # editable install, then it'll be hiding in the build dir)
+ assert os.path.exists(os.path.join(stdout, 'numpy.pc'))