Skip to content

Commit

Permalink
pep517: only use base python when MATURIN_PEP517_USE_BASE_PYTHON en…
Browse files Browse the repository at this point in the history
…v var is set (#2134)

* pep517: only use base python when `MATURIN_PEP517_USE_BASE_PYTHON` env var is set

* Update environment-variables.md
  • Loading branch information
messense committed Jul 2, 2024
1 parent 8b7001d commit e35097e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
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

0 comments on commit e35097e

Please sign in to comment.