Skip to content

The agent that grows with you

fix(lazy_deps): bridge PIP_INDEX_URL into the uv tier alongside pip.conf

liuhao1024d42fff651417
diff --git a/tests/tools/test_lazy_deps.py b/tests/tools/test_lazy_deps.py
index 2141e7b40db..54b7fa54a5a 100644
--- a/tests/tools/test_lazy_deps.py
+++ b/tests/tools/test_lazy_deps.py
@@ -633,6 +633,7 @@ class TestPipConfIndexBridge:
encoding="utf-8",
)
monkeypatch.setenv("PIP_CONFIG_FILE", str(conf))
+ monkeypatch.delenv("PIP_INDEX_URL", raising=False)
monkeypatch.delenv("UV_INDEX_URL", raising=False)
captured = self._record_uv_env(monkeypatch)
result = ld._venv_pip_install(("somepkg==1.0",))
@@ -651,8 +652,38 @@ class TestPipConfIndexBridge:
ld._venv_pip_install(("somepkg==1.0",))
assert captured["env"]["UV_INDEX_URL"] == "https://custom.example/simple"
+ def test_pip_index_url_env_bridged_without_conf(self, monkeypatch, tmp_path):
+ # A large share of mirror users configure via PIP_INDEX_URL instead
+ # of a config file — the bridge must cover that spelling too.
+ monkeypatch.setenv("PIP_CONFIG_FILE", str(tmp_path / "missing.conf"))
+ monkeypatch.setenv("PIP_INDEX_URL", "https://env-mirror.example/simple")
+ monkeypatch.delenv("UV_INDEX_URL", raising=False)
+ captured = self._record_uv_env(monkeypatch)
+ result = ld._venv_pip_install(("somepkg==1.0",))
+ assert result.success
+ assert (
+ captured["env"]["UV_INDEX_URL"] == "https://env-mirror.example/simple"
+ )
+
+ def test_pip_index_url_env_beats_pip_conf(self, monkeypatch, tmp_path):
+ # pip's own precedence: the env var wins over pip.conf.
+ conf = tmp_path / "pip.conf"
+ conf.write_text(
+ "[global]\nindex-url = https://mirror.example/simple\n",
+ encoding="utf-8",
+ )
+ monkeypatch.setenv("PIP_CONFIG_FILE", str(conf))
+ monkeypatch.setenv("PIP_INDEX_URL", "https://env-mirror.example/simple")
+ monkeypatch.delenv("UV_INDEX_URL", raising=False)
+ captured = self._record_uv_env(monkeypatch)
+ ld._venv_pip_install(("somepkg==1.0",))
+ assert (
+ captured["env"]["UV_INDEX_URL"] == "https://env-mirror.example/simple"
+ )
+
def test_no_pip_conf_leaves_uv_env_unchanged(self, monkeypatch, tmp_path):
monkeypatch.setenv("PIP_CONFIG_FILE", str(tmp_path / "missing.conf"))
+ monkeypatch.delenv("PIP_INDEX_URL", raising=False)
monkeypatch.delenv("UV_INDEX_URL", raising=False)
captured = self._record_uv_env(monkeypatch)
ld._venv_pip_install(("somepkg==1.0",))
@@ -660,6 +691,7 @@ class TestPipConfIndexBridge:
def test_uv_timeout_error_carries_actionable_hint(self, monkeypatch, tmp_path):
monkeypatch.setenv("PIP_CONFIG_FILE", str(tmp_path / "missing.conf"))
+ monkeypatch.delenv("PIP_INDEX_URL", raising=False)
monkeypatch.delenv("UV_INDEX_URL", raising=False)
def fake_run(cmd, *args, **kwargs):
diff --git a/tools/lazy_deps.py b/tools/lazy_deps.py
index f7431fc0eef..b6554f5efc3 100644
--- a/tools/lazy_deps.py
+++ b/tools/lazy_deps.py
@@ -579,9 +579,12 @@ def _venv_pip_install(specs: tuple[str, ...], *, timeout: int = 300, constraint_
# uv never reads pip.conf, so a mirrored-pip user would see every
# lazy install stall against the default pypi.org for the full
# timeout (#95608). Bridge pip's index-url unless uv is configured
- # explicitly — same policy as the update path (#17761).
+ # explicitly — same policy as the update path (#17761). PIP_INDEX_URL
+ # follows pip's own precedence (env var beats pip.conf).
if not uv_env.get("UV_INDEX_URL"):
- pip_index_url = _pip_conf_index_url(uv_env)
+ pip_index_url = (uv_env.get("PIP_INDEX_URL") or "").strip() or (
+ _pip_conf_index_url(uv_env)
+ )
if pip_index_url:
uv_env["UV_INDEX_URL"] = pip_index_url
# Tier 1: uv. --compile-bytecode because uv writes no __pycache__ by default, so the first