Skip to content

Commit 2ce3c19

Browse files
authored
Merge pull request numpy#27425 from roehling/meson-native-file-python
MAINT: Use correct Python interpreter in tests
2 parents 290e3a0 + f927197 commit 2ce3c19

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

numpy/_core/tests/test_cython.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ def install_temp(tmpdir_factory):
4646
native_file = str(build_dir / 'interpreter-native-file.ini')
4747
with open(native_file, 'w') as f:
4848
f.write("[binaries]\n")
49-
f.write(f"python = '{sys.executable}'")
49+
f.write(f"python = '{sys.executable}'\n")
50+
f.write(f"python3 = '{sys.executable}'")
5051

5152
try:
5253
subprocess.check_call(["meson", "--version"])

numpy/_core/tests/test_limited_api.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ def install_temp(tmpdir_factory):
4040
srcdir = os.path.join(os.path.dirname(__file__), 'examples', 'limited_api')
4141
build_dir = tmpdir_factory.mktemp("limited_api") / "build"
4242
os.makedirs(build_dir, exist_ok=True)
43+
# Ensure we use the correct Python interpreter even when `meson` is
44+
# installed in a different Python environment (see gh-24956)
45+
native_file = str(build_dir / 'interpreter-native-file.ini')
46+
with open(native_file, 'w') as f:
47+
f.write("[binaries]\n")
48+
f.write(f"python = '{sys.executable}'\n")
49+
f.write(f"python3 = '{sys.executable}'")
50+
4351
try:
4452
subprocess.check_call(["meson", "--version"])
4553
except FileNotFoundError:
@@ -48,11 +56,13 @@ def install_temp(tmpdir_factory):
4856
subprocess.check_call(["meson", "setup",
4957
"--werror",
5058
"--buildtype=release",
51-
"--vsenv", str(srcdir)],
59+
"--vsenv", "--native-file", native_file,
60+
str(srcdir)],
5261
cwd=build_dir,
5362
)
5463
else:
55-
subprocess.check_call(["meson", "setup", "--werror", str(srcdir)],
64+
subprocess.check_call(["meson", "setup", "--werror",
65+
"--native-file", native_file, str(srcdir)],
5666
cwd=build_dir
5767
)
5868
try:

numpy/random/tests/test_extending.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,23 @@ def test_cython(tmp_path):
6363
build_dir = tmp_path / 'random' / '_examples' / 'cython'
6464
target_dir = build_dir / "build"
6565
os.makedirs(target_dir, exist_ok=True)
66+
# Ensure we use the correct Python interpreter even when `meson` is
67+
# installed in a different Python environment (see gh-24956)
68+
native_file = str(build_dir / 'interpreter-native-file.ini')
69+
with open(native_file, 'w') as f:
70+
f.write("[binaries]\n")
71+
f.write(f"python = '{sys.executable}'\n")
72+
f.write(f"python3 = '{sys.executable}'")
6673
if sys.platform == "win32":
6774
subprocess.check_call(["meson", "setup",
6875
"--buildtype=release",
69-
"--vsenv", str(build_dir)],
76+
"--vsenv", "--native-file", native_file,
77+
str(build_dir)],
7078
cwd=target_dir,
7179
)
7280
else:
73-
subprocess.check_call(["meson", "setup", str(build_dir)],
81+
subprocess.check_call(["meson", "setup",
82+
"--native-file", native_file, str(build_dir)],
7483
cwd=target_dir
7584
)
7685
subprocess.check_call(["meson", "compile", "-vv"], cwd=target_dir)

0 commit comments

Comments
 (0)