The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(lazy-deps): pass --compile-bytecode on the uv tier and skip metadata dirs in the warm
Tekniumf2989114670b
diff --git a/tests/tools/test_lazy_deps.py b/tests/tools/test_lazy_deps.pyindex 8c4b0c40ae0..c62324be6bb 100644--- a/tests/tools/test_lazy_deps.py+++ b/tests/tools/test_lazy_deps.py@@ -542,6 +542,13 @@ class TestWarmInstalledBytecode:def test_unknown_distribution_resolves_to_nothing(self):assert ld._installed_dist_roots("zzz-not-installed==9.9", None) == set()+ def test_dist_roots_exclude_metadata_dirs(self):+ # ``*.dist-info`` owns RECORD/METADATA/licenses, never importable+ # code — compiling it is wasted work on every install.+ roots = ld._installed_dist_roots("pytest>=8", None)+ assert roots+ assert not any(r.name.endswith((".dist-info", ".egg-info")) for r in roots)+class TestInstallWarmsBytecode:"""The warm runs on install success, and only on success."""@@ -549,6 +556,7 @@ class TestInstallWarmsBytecode:@staticmethoddef _install(monkeypatch, returncode):calls = []+ cmds = []monkeypatch.setattr(ld, "_lazy_install_target", lambda: None)monkeypatch.setattr(ld.shutil, "which", lambda name: "uv" if name == "uv" else None)monkeypatch.setattr(@@ -561,20 +569,34 @@ class TestInstallWarmsBytecode:self.stdout = "out"self.stderr = "err"- monkeypatch.setattr(ld.subprocess, "run", lambda *a, **kw: _Completed())+ def fake_run(cmd, *a, **kw):+ cmds.append(list(cmd))+ return _Completed()++ monkeypatch.setattr(ld.subprocess, "run", fake_run)monkeypatch.setattr(ld, "_warm_installed_bytecode",lambda specs, target: calls.append((specs, target)),)result = ld._venv_pip_install(("zzzfake==1.0",))- return result, calls+ return result, calls, cmdsdef test_success_warms_once_with_the_installed_specs(self, monkeypatch):- result, calls = self._install(monkeypatch, 0)+ result, calls, _ = self._install(monkeypatch, 0)assert result.success is Trueassert calls == [(("zzzfake==1.0",), None)]def test_failed_install_does_not_warm(self, monkeypatch):- result, calls = self._install(monkeypatch, 1)+ result, calls, _ = self._install(monkeypatch, 1)assert result.success is Falseassert calls == []++ def test_uv_tier_compiles_bytecode_for_the_whole_install(self, monkeypatch):+ # uv does not write __pycache__ unless asked (pip does). The flag+ # covers transitive deps too, which the per-spec warm never sees.+ _, _, cmds = self._install(monkeypatch, 0)+ uv_cmds = [c for c in cmds if c[:3] == ["uv", "pip", "install"]]+ assert len(uv_cmds) == 1+ cmd = uv_cmds[0]+ assert "--compile-bytecode" in cmd+ assert cmd.index("--compile-bytecode") < cmd.index("zzzfake==1.0")diff --git a/tools/lazy_deps.py b/tools/lazy_deps.pyindex 50e35dde9a8..f990f340ebd 100644--- a/tools/lazy_deps.py+++ b/tools/lazy_deps.py@@ -727,6 +727,10 @@ def _installed_dist_roots(spec: str, target: Optional[Path]) -> set[Path]:parts = entry.partsif not parts or parts[0].startswith(".") or parts[0] == "__pycache__":continue+ # Metadata dirs (``foo-1.0.dist-info``, legacy ``.egg-info``) own+ # no importable code; compiling them is wasted work.+ if parts[0].endswith((".dist-info", ".egg-info")):+ continueroot = Path(dist.locate_file(parts[0]))if root.is_dir():roots.add(root)@@ -830,8 +834,15 @@ def _venv_pip_install(specs: tuple[str, ...], *, timeout: int = 300) -> _Installuv_bin = shutil.which("uv")if uv_bin:try:+ # --compile-bytecode: uv does NOT write __pycache__ by default+ # (pip does), so without it the first `import <backend>` in+ # the foreground of a user request recompiles every module of+ # the backend *and* its transitive deps (#100461). This covers+ # the whole install; _warm_installed_bytecode below is the+ # belt-and-braces pass for the spec's own roots on any tier.r = subprocess.run(- [uv_bin, "pip", "install", *target_args, *constraint_args, *specs],+ [uv_bin, "pip", "install", "--compile-bytecode",+ *target_args, *constraint_args, *specs],capture_output=True, text=True, encoding='utf-8', errors='replace', timeout=timeout, env=uv_env,stdin=subprocess.DEVNULL,creationflags=windows_hide_flags(),