The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(pm): compile bytecode when uv syncs the environment
ethernet525c09142fac
diff --git a/gateway/status.py b/gateway/status.pyindex 19ff96e6d41..521f9c62c55 100644--- a/gateway/status.py+++ b/gateway/status.py@@ -900,13 +900,6 @@ def _posix_is_zombie(pid: int) -> bool:return len(stat_fields) > 2 and stat_fields[2] == "Z"except FileNotFoundError:with contextlib.suppress(Exception):- # --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.- # CREATE_NO_WINDOW on Windows — under the desktop GUI's windowless parent, this spawn otherwise- # flashes a console (#56747).r = subprocess.run(["ps", "-o", "state=", "-p", str(pid)],capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=5,diff --git a/pm/environment.py b/pm/environment.pyindex 674976bb157..ac89ab38762 100644--- a/pm/environment.py+++ b/pm/environment.py@@ -301,8 +301,10 @@ class PythonEnvironment:if not frozen:self.lock(source, timeout=timeout)# Locking members alone is insufficient: plain sync only installs root deps.+ # uv writes no __pycache__ (pip does): without --compile-bytecode the first import+ # of every module in the foreground of a user request compiles it (#100461).command = ["sync", "--locked" if locked else "--frozen", "--all-packages",- "--python", str(self.python)]+ "--python", str(self.python), "--compile-bytecode"]if no_default_groups:command.append("--no-default-groups")if all_extras:diff --git a/tests/pm/test_environment_build.py b/tests/pm/test_environment_build.pyindex f1e08d63450..57580f2031e 100644--- a/tests/pm/test_environment_build.py+++ b/tests/pm/test_environment_build.py@@ -140,15 +140,19 @@ def test_public_build_installs_all_extras_at_explicit_destination(installable_prcache=tmp_path / "cache", env=env, all_extras=True, offline=True,sealed=sealed,)+ from pm.environments import site_packages++ site = site_packages(executable.parent.parent)+ # Bytecode is written at build time, not by the first user request's import (#100461);+ # checked before anything imports from the environment.+ assert list(site.glob("*/__pycache__/*.pyc")) or list(site.glob("__pycache__/*.pyc")), \+ "dependencies were installed without bytecode"assert _run([str(executable), "-I", "-c","import root_app, member_dep, chosen_dep, other_dep; print(root_app.VALUE)"],cwd=tmp_path, env=env) == "installed from the explicit source"assert executable.parent.parent == tmp_path / "native environment"assert not (tmp_path / "wrong-environment").exists()assert "root_app" not in sys.modules- from pm.environments import site_packages-- site = site_packages(executable.parent.parent)assert (site / "_virtualenv.pth").exists() is not sealedassert (site / "construction_root.pth").is_file(), "load-bearing .pth must survive sealing"assert (source / "uv.lock").read_bytes() == locked