Skip to content

Use base executable when it exists, to avoid recompiling when switching venv #429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading