Skip to content

Commit

Permalink
TST: ensure test_extending compile tests work with any meson
Browse files Browse the repository at this point in the history
The `meson` executable isn't guaranteed to be installed for the same
Python interpreter as we're running the tests for (this may for example
happen in distro setups when we're testing a non-default Python).
Explicitly passing the Python interpreter we're testing for to Meson
via a native file should be a robust solution.
  • Loading branch information
rgommers committed Apr 29, 2024
1 parent 193a0e1 commit 3a33dab
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion scipy/_lib/_testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,20 +280,35 @@ def _test_cython_extension(tmp_path, srcdir):
Helper function to test building and importing Cython modules that
make use of the Cython APIs for BLAS, LAPACK, optimize, and special.
"""
try:
subprocess.check_call(["meson", "--version"])
except FileNotFoundError:
pytest.skip("No usable 'meson' found")

# build the examples in a temporary directory
mod_name = os.path.split(srcdir)[1]
shutil.copytree(srcdir, tmp_path / mod_name)
build_dir = tmp_path / mod_name / 'tests' / '_cython_examples'
target_dir = build_dir / 'build'
os.makedirs(target_dir, exist_ok=True)

# Ensure we use the correct Python interpreter even when `meson` is
# installed in a different Python environment (see numpy#24956)
native_file = str(build_dir / 'interpreter-native-file.ini')
with open(native_file, 'w') as f:
f.write("[binaries]\n")
f.write(f"python = '{sys.executable}'")

if sys.platform == "win32":
subprocess.check_call(["meson", "setup",
"--buildtype=release",
"--native-file", native_file,
"--vsenv", str(build_dir)],
cwd=target_dir,
)
else:
subprocess.check_call(["meson", "setup", str(build_dir)],
subprocess.check_call(["meson", "setup",
"--native-file", native_file, str(build_dir)],
cwd=target_dir
)
subprocess.check_call(["meson", "compile", "-vv"], cwd=target_dir)
Expand Down

0 comments on commit 3a33dab

Please sign in to comment.