From da92aec06e6e91d98276cf1ea624c88e77dc3404 Mon Sep 17 00:00:00 2001 From: matsjoyce Date: Thu, 23 May 2024 10:58:40 +0100 Subject: [PATCH 1/2] Use base executable when it exists, to avoid recompiling when switching venv --- setuptools_rust/build.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/setuptools_rust/build.py b/setuptools_rust/build.py index e693ccba..a19b5593 100644 --- a/setuptools_rust/build.py +++ b/setuptools_rust/build.py @@ -610,9 +610,13 @@ def _replace_vendor_with_unknown(target: str) -> Optional[str]: def _prepare_build_environment() -> Dict[str, str]: """Prepares environment variables to use when executing cargo build.""" + executable = getattr(sys, "_base_executable", sys.executable) + if not os.path.exists(executable): + executable = sys.executable + # Make sure that if pythonXX-sys is used, it builds against the current # executing python interpreter. - bindir = os.path.dirname(sys.executable) + bindir = os.path.dirname(executable) env = os.environ.copy() env.update( @@ -622,9 +626,9 @@ def _prepare_build_environment() -> Dict[str, str]: # interpreter from the path. "PATH": os.path.join(bindir, os.environ.get("PATH", "")), "PYTHON_SYS_EXECUTABLE": os.environ.get( - "PYTHON_SYS_EXECUTABLE", sys.executable + "PYTHON_SYS_EXECUTABLE", executable ), - "PYO3_PYTHON": os.environ.get("PYO3_PYTHON", sys.executable), + "PYO3_PYTHON": os.environ.get("PYO3_PYTHON", executable), } ) return env From 95b527fb1e19578d05b91a14c9b1aa1432aef106 Mon Sep 17 00:00:00 2001 From: matsjoyce Date: Fri, 24 May 2024 17:20:53 +0100 Subject: [PATCH 2/2] Add CHANGELOG item for #429 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ace982bf..b2a82df7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased +### Changed + - Use the base interpreter path when running inside a virtual environment to avoid recompilation when switching between virtual environments. [#429](https://github.com/PyO3/setuptools-rust/pull/429) + ## 1.9.0 (2024-02-24) ### Changed - Deprecate `py_limited_api` option to `RustExtension` in favour of always using `"auto"` to configure this from `bdist_wheel`. [#410](https://github.com/PyO3/setuptools-rust/pull/410)