From 20acedfc25cc327c8d5053c3134164383755ea96 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Wed, 6 Dec 2023 08:41:44 -0400 Subject: [PATCH] Run f2py's meson backend with the same python that ran f2py On Debian, we sometimes have multiple Python 3 versions in the archive. When using f2py3.X, I'd expect meson to run with the same python, not the default python. Not sure how far up the stack this should come from, I kept it simple for this PR, if someone has better ideas, they can direct me. --- numpy/f2py/_backends/_meson.py | 4 ++++ numpy/f2py/_backends/meson.build.template | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/numpy/f2py/_backends/_meson.py b/numpy/f2py/_backends/_meson.py index 7956fc64b671..7cf08446e863 100644 --- a/numpy/f2py/_backends/_meson.py +++ b/numpy/f2py/_backends/_meson.py @@ -4,6 +4,7 @@ import errno import shutil import subprocess +import sys from pathlib import Path from ._backend import Backend @@ -27,6 +28,7 @@ def __init__( linker_args: list[str], c_args: list[str], build_type: str, + python_exe: str, ): self.modulename = modulename self.build_template_path = ( @@ -59,6 +61,7 @@ def meson_build_template(self) -> str: def initialize_template(self) -> None: self.substitutions["modulename"] = self.modulename self.substitutions["buildtype"] = self.build_type + self.substitutions["python"] = self.python_exe def sources_substitution(self) -> None: indent = " " * 21 @@ -138,6 +141,7 @@ def write_meson_build(self, build_dir: Path) -> None: self.flib_flags, self.fc_flags, self.build_type, + sys.executable, ) src = meson_template.generate_meson_build() Path(build_dir).mkdir(parents=True, exist_ok=True) diff --git a/numpy/f2py/_backends/meson.build.template b/numpy/f2py/_backends/meson.build.template index 65e3ecb19c30..52e34634493a 100644 --- a/numpy/f2py/_backends/meson.build.template +++ b/numpy/f2py/_backends/meson.build.template @@ -8,7 +8,7 @@ project('${modulename}', ]) fc = meson.get_compiler('fortran') -py = import('python').find_installation(pure: false) +py = import('python').find_installation('${python}', pure: false) py_dep = py.dependency() incdir_numpy = run_command(py,