Quickly sandbox your AI agent.
Python
fix(build): Inject image extraction pre-hook into CI build plan
Tyler Paynee6952345f6da
diff --git a/uvr_hooks.py b/uvr_hooks.pyindex 8f905f4..9db0015 100644--- a/uvr_hooks.py+++ b/uvr_hooks.py@@ -122,40 +122,47 @@ class Hooks(ReleaseHook):update={"test_install": {vm: install for vm in ("ubuntu", "alpine")}})+ # Inject a pre-hook on the build job to extract base images from dep+ # wheels into workspace source dirs. When building overlays via+ # --packages (base images not rebuilt), uv resolves build-system deps+ # from workspace sources which lack qcow2 images. Extracting them+ # first and clearing the uv cache ensures the build env gets images.+ _EXTRACT_SCRIPT = (+ "python3 -c \""+ "import zipfile, pathlib, shutil, os\\n"+ "deps = pathlib.Path('deps')\\n"+ "if deps.exists():\\n"+ " for whl in sorted(deps.glob('*.whl')):\\n"+ " with zipfile.ZipFile(whl) as zf:\\n"+ " for name in zf.namelist():\\n"+ " exts=('.qcow2','.kernel','.initrd')\\n"+ " if not any(name.endswith(e) for e in exts): continue\\n"+ " parts = pathlib.Path(name).parts\\n"+ " if len(parts) < 2: continue\\n"+ " pkg = parts[0].replace('_','-')\\n"+ " dest = pathlib.Path('packages') / pkg / name\\n"+ " if dest.exists(): continue\\n"+ " dest.parent.mkdir(parents=True, exist_ok=True)\\n"+ " print(f' Extracting {name} from {whl.name}')\\n"+ " with zf.open(name) as s, open(dest,'wb') as d:\\n"+ " shutil.copyfileobj(s,d)\\n"+ "\""+ " && uv cache clean quicksand-ubuntu quicksand-alpine || true"+ )+ new_jobs = []+ for job in plan.jobs:+ if job.name == "build" and not job.pre_hook:+ job = job.model_copy(update={"pre_hook": _EXTRACT_SCRIPT})+ new_jobs.append(job)+ plan = plan.model_copy(update={"jobs": new_jobs})+return plandef pre_build(self) -> None:- """Extract images from dep wheels and install gh CLI on Windows."""+ """Install gh CLI on Windows runners (not pre-installed on self-hosted)."""import osimport platformimport urllib.request- import zipfile-- # When building overlays from --packages (base images not rebuilt),- # uv resolves build-system.requires from workspace sources which lack- # qcow2 images. Extract images from pre-built dep wheels so the- # workspace source directories have them.- deps_dir = Path("deps")- if deps_dir.exists():- for whl in deps_dir.glob("*.whl"):- with zipfile.ZipFile(whl) as zf:- for name in zf.namelist():- if not any(name.endswith(ext) for ext in (".qcow2", ".kernel", ".initrd")):- continue- # e.g. quicksand_ubuntu/images/ubuntu-24.04-amd64.qcow2- parts = Path(name).parts- if len(parts) < 2:- continue- pkg_dir = Path("packages")- # quicksand_ubuntu -> quicksand-ubuntu- pkg_name = parts[0].replace("_", "-")- dest = pkg_dir / pkg_name / name- if dest.exists():- continue- dest.parent.mkdir(parents=True, exist_ok=True)- print(f" Extracting {name} from {whl.name}")- with zf.open(name) as src, open(dest, "wb") as dst:- shutil.copyfileobj(src, dst)if platform.system() != "Windows":return