Skip to content

Commit

Permalink
Merge pull request #429 from matsjoyce-refeyn/use-base-executable-pat…
Browse files Browse the repository at this point in the history
…h-in-venv

Use base executable when it exists, to avoid recompiling when switching venv
  • Loading branch information
davidhewitt authored May 25, 2024
2 parents 70fc951 + 95b527f commit 45b095b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
10 changes: 7 additions & 3 deletions setuptools_rust/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down

0 comments on commit 45b095b

Please sign in to comment.