Skip to content
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

pep517: only use base python when MATURIN_PEP517_USE_BASE_PYTHON env var is set #2134

Merged
merged 2 commits into from
Jul 2, 2024
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
1 change: 1 addition & 0 deletions guide/src/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See [environment variables Cargo reads](https://doc.rust-lang.org/cargo/referenc
* `_PYTHON_SYSCONFIGDATA_NAME`: Name of a `sysconfigdata*.py` file
* `MATURIN_PYPI_TOKEN`: PyPI token for uploading wheels
* `MATURIN_PASSWORD`: PyPI password for uploading wheels
* `MATURIN_PEP517_USE_BASE_PYTHON`: Use base Python executable instead of venv Python executable in PEP 517 build to avoid unnecessary rebuilds, should not be set when the sdist build requires packages installed in venv.

## `pyo3` environment variables

Expand Down
14 changes: 7 additions & 7 deletions maturin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ def get_maturin_pep517_args(config_settings: Optional[Mapping[str, Any]] = None)


def _get_sys_executable() -> str:
# Use the base interpreter path when running inside a venv to avoid recompilation
# when switching between venvs
base_executable = getattr(sys, "_base_executable")
if base_executable and os.path.exists(base_executable):
executable = os.path.realpath(base_executable)
else:
executable = sys.executable
executable = sys.executable
if os.getenv("MATURIN_PEP517_USE_BASE_PYTHON") in {"1", "true"}:
# Use the base interpreter path when running inside a venv to avoid recompilation
# when switching between venvs
base_executable = getattr(sys, "_base_executable")
if base_executable and os.path.exists(base_executable):
executable = os.path.realpath(base_executable)
return executable


Expand Down
Loading