Skip to content

prepare

Class info

🛈 DocStrings

Resolve a registry agent to a runnable command.

For uvx/npx distributions the command is built directly. For binary distributions the archive is downloaded and extracted if needed.

prepare_binary async

prepare_binary(dist: BinaryDistribution, extra_args: list[str], bin_dir: Path) -> list[str]

Download + extract a binary distribution if not already cached.

Source code in src/aclientp/registry/prepare.py
async def prepare_binary(
    dist: BinaryDistribution,
    extra_args: list[str],
    bin_dir: Path,
) -> list[str]:
    """Download + extract a binary distribution if not already cached."""
    bin_dir.mkdir(parents=True, exist_ok=True)
    bin_path = bin_dir / Path(dist.cmd).name
    cmd = [str(bin_path), *dist.args, *extra_args]

    if bin_path.exists():
        logger.info("Binary already cached at %s", bin_path)
        return cmd

    logger.info("Downloading binary from %s", dist.archive)
    with tempfile.NamedTemporaryFile(delete=True) as tmp:
        async with httpx2.AsyncClient(
            timeout=httpx2.Timeout(connect=30.0, read=120.0, write=120.0, pool=30.0),
            follow_redirects=True,
        ) as client:
            response = await client.get(dist.archive)
            response.raise_for_status()
            tmp.write(response.content)
            tmp.flush()

        await asyncio.to_thread(
            extract_binary,
            archive_path=Path(tmp.name),
            binary_name=Path(dist.cmd).name,
            dest_dir=bin_dir,
        )

    bin_path.chmod(0o755)
    logger.info("Binary installed to %s", bin_path)
    return cmd

prepare_npx

prepare_npx(dist: NpxDistribution, extra_args: list[str]) -> list[str]

Build command list for an npx/bunx distribution.

Source code in src/aclientp/registry/prepare.py
def prepare_npx(dist: NpxDistribution, extra_args: list[str]) -> list[str]:
    """Build command list for an npx/bunx distribution."""
    runner = _find_program("bunx", "npx")
    if runner is None:
        raise RuntimeError("Neither bunx nor npx found on PATH. Install bun or node.")
    base = [runner]
    if runner == "npx":
        base.append("-y")
    return [*base, dist.package, *dist.args, *extra_args]

prepare_uvx

prepare_uvx(dist: UvxDistribution, extra_args: list[str]) -> list[str]

Build command list for a uvx distribution.

Source code in src/aclientp/registry/prepare.py
def prepare_uvx(dist: UvxDistribution, extra_args: list[str]) -> list[str]:
    """Build command list for a uvx distribution."""
    if not shutil.which("uvx"):
        raise RuntimeError("uvx not found on PATH. Install uv.")
    return ["uvx", "--python", "3.13", dist.package, *dist.args, *extra_args]