Skip to content

Commit 2956993

Browse files
authored
fix: do not pass target environment to the host virtualenv call (#3023)
1 parent 5d621c9 commit 2956993

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

‎cibuildwheel/venv.py‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,6 @@ def virtualenv(
172172

173173
assert python.exists()
174174

175-
env = os.environ.copy() if env is None else env.copy()
176-
if needs_pip_cert(version, (marker_env or {}).get("implementation_name", "")):
177-
env.setdefault("PIP_CERT", ca_bundle_path())
178-
179175
if use_uv:
180176
uv_path = find_uv()
181177
assert uv_path is not None
@@ -207,9 +203,10 @@ def virtualenv(
207203
"--python",
208204
python,
209205
venv_path,
210-
env=env,
211206
)
212207
venv_env = activate_virtualenv(venv_path, env=env, base_python_bin_dir=base_python_bin_dir)
208+
if needs_pip_cert(version, (marker_env or {}).get("implementation_name", "")):
209+
venv_env.setdefault("PIP_CERT", ca_bundle_path())
213210
if not use_uv and pip_version == "embed":
214211
call(
215212
"python",

‎unit_test/venv_test.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import certifi
77
import pytest
8+
from packaging.version import Version
89

910
import cibuildwheel.venv
1011
from cibuildwheel.venv import (
@@ -128,3 +129,28 @@ def fake_run(args: list[str], **_kwargs: object) -> subprocess.CompletedProcess[
128129
assert output.split()[1] in warning
129130
else:
130131
assert warning is None
132+
133+
134+
def test_virtualenv_host_call_ignores_target_env(
135+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
136+
) -> None:
137+
# virtualenv runs on the host Python, so target settings like PYTHON_GIL=0 must not leak in
138+
calls: list[dict[str, str] | None] = []
139+
monkeypatch.setattr(
140+
cibuildwheel.venv, "_ensure_virtualenv", lambda _: (tmp_path / "v.pyz", Version("21.0"))
141+
)
142+
monkeypatch.setattr(cibuildwheel.venv, "call", lambda *_, env=None: calls.append(env))
143+
144+
venv_env = virtualenv(
145+
"3.9",
146+
Path(sys.executable),
147+
tmp_path / "venv",
148+
None,
149+
use_uv=False,
150+
env={"PATH": "", "PYTHON_GIL": "0"},
151+
pip_version="26.0.1",
152+
)
153+
154+
assert venv_env["PYTHON_GIL"] == "0"
155+
assert venv_env["PIP_CERT"] == certifi.where()
156+
assert calls == [None]

0 commit comments

Comments
 (0)