"""Download pure/binary wheels from PyPI and extract them into a target dir. Bypasses pip entirely: pip's temp-file handling is blocked by the sandbox. """ import json import os import sys import urllib.request import zipfile TARGET = sys.argv[1] if len(sys.argv) > 1 else "libs-ssh" os.makedirs(TARGET, exist_ok=True) os.makedirs("wheels", exist_ok=True) def fetch_json(pkg): url = f"https://pypi.org/pypi/{pkg}/json" req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"}) with urllib.request.urlopen(req, timeout=60) as r: return json.load(r) def pick_wheel(pkg): data = fetch_json(pkg) ver = data["info"]["version"] files = [f for f in data["urls"] if f["filename"].endswith(".whl")] pure = [f for f in files if f["filename"].endswith("-py3-none-any.whl")] if pure: return ver, pure[0]["filename"], pure[0]["url"] win = [f for f in files if f["filename"].endswith("-win_amd64.whl")] abi3 = [f for f in win if "-abi3-" in f["filename"]] cp314 = [f for f in win if "-cp314-cp314-" in f["filename"]] for group in (abi3, cp314, win): if group: return ver, group[0]["filename"], group[0]["url"] raise SystemExit(f"no wheel for {pkg} on this platform") def download(url, path): req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"}) with urllib.request.urlopen(req, timeout=120) as r, open(path, "wb") as f: f.write(r.read()) for pkg in ("paramiko", "bcrypt", "pynacl"): try: ver, fname, url = pick_wheel(pkg) except SystemExit as exc: print(f"SKIP {pkg}: {exc}") continue path = os.path.join("wheels", fname) if not os.path.exists(path) or os.path.getsize(path) == 0: download(url, path) size = os.path.getsize(path) with zipfile.ZipFile(path) as z: z.extractall(TARGET) print(f"OK {pkg} {ver} -> {fname} ({size} bytes)") print("done ->", os.path.abspath(TARGET))