Skip to content

abc_runner.squashfs

WARNING

This documentation is almost entirely "vibe coded"; while a helpful resource for humans and agents to understand this codebase, it should not be considered a source of ground truth in the way documentation normally is, and the user is responsible for verifying that all instructions given here are safe.

abc_runner.squashfs

SquashFS support for ABC Runner task groups.

A task group may be supplied either as an ordinary directory or as a squashfs (.sqfs) image of that directory. This module mounts such an image read-only with squashfuse and copies its contents out to a temporary directory so the rest of ABC Runner can treat it exactly like a directory-backed task group.

squashfs is a hard requirement on every platform ABC Runner targets, so this module is intentionally small: it mounts, copies, and unmounts, and raises a clear error if squashfuse is unavailable. There is no directory fallback and no partial-extraction cleverness.

SquashfsError

Bases: RuntimeError

Raised for any squashfs mount/copy failure.

is_squashfs_artifact

is_squashfs_artifact(path: Path) -> bool

Return True if path looks like a squashfs task-group image.

Source code in abc_runner/squashfs.py
def is_squashfs_artifact(path: Path) -> bool:
    """Return True if ``path`` looks like a squashfs task-group image."""
    return path.is_file() and path.suffix == SQUASHFS_SUFFIX

mount_squashfs

mount_squashfs(artifact: Path) -> Iterator[Path]

Mount a squashfs image read-only, yielding the mount point.

Uses squashfuse (a userspace FUSE mount): no root required and nothing is expanded to disk. The mount is always torn down on exit.

Source code in abc_runner/squashfs.py
@contextlib.contextmanager
def mount_squashfs(artifact: Path) -> Iterator[Path]:
    """Mount a squashfs image read-only, yielding the mount point.

    Uses ``squashfuse`` (a userspace FUSE mount): no root required and nothing
    is expanded to disk. The mount is always torn down on exit.
    """
    artifact = Path(artifact)
    if not artifact.is_file():
        raise SquashfsError(f"squashfs artifact not found: {artifact}")
    _require_squashfuse()

    mount_point = Path(tempfile.mkdtemp(prefix="abc-runner-sqfs-mount."))
    try:
        print(f"Mounting squashfs image {artifact} ...", flush=True)
        result = subprocess.run(
            ["squashfuse", str(artifact), str(mount_point)],
            check=False,
            text=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        )
        if result.returncode != 0:
            raise SquashfsError(
                f"failed to mount squashfs image {artifact}: {result.stderr.strip()}"
            )
        try:
            yield mount_point
        finally:
            _unmount(mount_point)
    finally:
        with contextlib.suppress(OSError):
            mount_point.rmdir()

materialize_group

materialize_group(artifact: Path) -> Path

Mount a squashfs group image and copy its contents to a temp directory.

Returns the path to the materialized directory. The directory is registered for cleanup at interpreter exit. The image is never fully decompressed to disk during the mount; only the copied contents live on disk afterward.

This is the single-group form: the image must contain exactly one task group (group.yaml at the root, or a single top-level dir containing it). Use :func:materialize_groups for images that may pack several groups.

Source code in abc_runner/squashfs.py
def materialize_group(artifact: Path) -> Path:
    """Mount a squashfs group image and copy its contents to a temp directory.

    Returns the path to the materialized directory. The directory is registered
    for cleanup at interpreter exit. The image is never fully decompressed to
    disk during the mount; only the copied contents live on disk afterward.

    This is the *single-group* form: the image must contain exactly one task
    group (``group.yaml`` at the root, or a single top-level dir containing it).
    Use :func:`materialize_groups` for images that may pack several groups.
    """
    artifact = Path(artifact)
    dest = Path(tempfile.mkdtemp(prefix="abc-runner-group."))
    _MATERIALIZED_DIRS.append(dest)
    try:
        with mount_squashfs(artifact) as mount_point:
            _copy_group_root(mount_point, dest)
    except Exception:
        with contextlib.suppress(OSError):
            shutil.rmtree(dest, ignore_errors=True)
        with contextlib.suppress(ValueError):
            _MATERIALIZED_DIRS.remove(dest)
        raise
    return dest

materialize_groups

materialize_groups(artifact: Path) -> list[Path]

Mount a squashfs image and copy out every task group it contains.

Handles three packings:

  • group.yaml at the image root -> one group,
  • a single top-level dir that contains group.yaml -> one group,
  • a top level of several dirs each containing group.yaml -> many groups.

Returns the list of materialized group directories (one per group), all under a single temp dir registered for cleanup at interpreter exit.

Source code in abc_runner/squashfs.py
def materialize_groups(artifact: Path) -> list[Path]:
    """Mount a squashfs image and copy out *every* task group it contains.

    Handles three packings:

    * ``group.yaml`` at the image root -> one group,
    * a single top-level dir that contains ``group.yaml`` -> one group,
    * a top level of several dirs each containing ``group.yaml`` -> many groups.

    Returns the list of materialized group directories (one per group), all
    under a single temp dir registered for cleanup at interpreter exit.
    """
    artifact = Path(artifact)
    dest = Path(tempfile.mkdtemp(prefix="abc-runner-groups."))
    _MATERIALIZED_DIRS.append(dest)
    try:
        with mount_squashfs(artifact) as mount_point:
            group_roots = _iter_group_roots(mount_point)
            if not group_roots:
                raise SquashfsError(
                    f"squashfs image does not contain any task group "
                    f"(no group.yaml): {mount_point}"
                )
            out: list[Path] = []
            for root in group_roots:
                # For a root-level single group the mount root itself is the
                # group; copy its contents into a named subdir so multiple
                # groups never collide and each returned path is a group dir.
                target = dest / root.name if root != mount_point else dest / "group"
                target.mkdir(parents=True, exist_ok=True)
                _copy_dir_contents(root, target, desc=f"Extracting {target.name}")
                out.append(target)
            return out
    except Exception:
        with contextlib.suppress(OSError):
            shutil.rmtree(dest, ignore_errors=True)
        with contextlib.suppress(ValueError):
            _MATERIALIZED_DIRS.remove(dest)
        raise