Skip to content

Commit 45b095b

Browse files
authored
Merge pull request #429 from matsjoyce-refeyn/use-base-executable-path-in-venv
Use base executable when it exists, to avoid recompiling when switching venv
2 parents 70fc951 + 95b527f commit 45b095b

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Unreleased
4+
### Changed
5+
- 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)
6+
37
## 1.9.0 (2024-02-24)
48
### Changed
59
- 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)

setuptools_rust/build.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,13 @@ def _replace_vendor_with_unknown(target: str) -> Optional[str]:
610610
def _prepare_build_environment() -> Dict[str, str]:
611611
"""Prepares environment variables to use when executing cargo build."""
612612

613+
executable = getattr(sys, "_base_executable", sys.executable)
614+
if not os.path.exists(executable):
615+
executable = sys.executable
616+
613617
# Make sure that if pythonXX-sys is used, it builds against the current
614618
# executing python interpreter.
615-
bindir = os.path.dirname(sys.executable)
619+
bindir = os.path.dirname(executable)
616620

617621
env = os.environ.copy()
618622
env.update(
@@ -622,9 +626,9 @@ def _prepare_build_environment() -> Dict[str, str]:
622626
# interpreter from the path.
623627
"PATH": os.path.join(bindir, os.environ.get("PATH", "")),
624628
"PYTHON_SYS_EXECUTABLE": os.environ.get(
625-
"PYTHON_SYS_EXECUTABLE", sys.executable
629+
"PYTHON_SYS_EXECUTABLE", executable
626630
),
627-
"PYO3_PYTHON": os.environ.get("PYO3_PYTHON", sys.executable),
631+
"PYO3_PYTHON": os.environ.get("PYO3_PYTHON", executable),
628632
}
629633
)
630634
return env

0 commit comments

Comments
 (0)