Task-group installation for ABC Runner.
abc-runner install materializes task groups into the installed root
(~/.abc-runner/tasks/<group>/) so they can be referenced by name without a
filesystem path. Sources may be:
- a task-group directory (contains
group.yaml),
- a directory that contains task groups,
- a squashfs (
.sqfs) image of a task group, or
- a
.tar.gz / .tgz archive of a task group.
The tiny bundled smoke_test group ships inside the package and is
auto-installed on first use so ABC Runner works out of the box.
InstallError
Bases: RuntimeError
Raised for any task-group install failure.
install_source
install_source(source: Path, dest_root: Path | None = None, force: bool = False) -> list[str]
Install task group(s) from source into the installed root.
Returns the list of installed group ids.
Source code in abc_runner/install.py
| def install_source(source: Path, dest_root: Path | None = None, force: bool = False) -> list[str]:
"""Install task group(s) from ``source`` into the installed root.
Returns the list of installed group ids.
"""
source = Path(source).expanduser()
if dest_root is None:
dest_root = installed_tasks_root()
if not source.exists():
raise InstallError(f"source not found: {source}")
if squashfs.is_squashfs_artifact(source):
materialized = squashfs.materialize_groups(source)
return [_install_group_dir(gd, dest_root, force) for gd in materialized]
if source.is_file() and (source.name.endswith(".tar.gz") or source.name.endswith(".tgz")):
with tempfile.TemporaryDirectory(prefix="abc-runner-install.") as tmp:
tmp_path = Path(tmp)
with tarfile.open(source, "r:gz") as tar:
_safe_extract(tar, tmp_path)
group_dirs = _iter_group_dirs(tmp_path)
if not group_dirs:
raise InstallError(f"archive contains no task group: {source}")
return [_install_group_dir(gd, dest_root, force) for gd in group_dirs]
if source.is_dir():
group_dirs = _iter_group_dirs(source)
if not group_dirs:
raise InstallError(f"directory contains no task group: {source}")
return [_install_group_dir(gd, dest_root, force) for gd in group_dirs]
raise InstallError(f"unsupported install source (expected dir, .sqfs, or .tar.gz): {source}")
|
bundled_smoke_test_dir
bundled_smoke_test_dir() -> Path | None
Return the bundled smoke_test group dir, if shipped with the package.
Source code in abc_runner/install.py
| def bundled_smoke_test_dir() -> Path | None:
"""Return the bundled ``smoke_test`` group dir, if shipped with the package."""
import importlib.resources as resources
try:
candidate = resources.files("abc_runner") / "data" / "tasks" / BUNDLED_SMOKE_TEST
except (ModuleNotFoundError, FileNotFoundError, AttributeError):
candidate = None
if candidate is not None and candidate.is_dir():
with resources.as_file(candidate) as path:
if (path / "group.yaml").is_file():
return Path(path)
# Editable/checkout fallback: tasks/smoke_test relative to the repo root.
repo_candidate = Path(__file__).resolve().parent.parent / "tasks" / BUNDLED_SMOKE_TEST
if (repo_candidate / "group.yaml").is_file():
return repo_candidate
return None
|
ensure_smoke_test_installed
ensure_smoke_test_installed(dest_root: Path | None = None) -> str | None
Auto-install the bundled smoke_test group if nothing is installed yet.
Returns the installed group id, or None if there was nothing to seed
(either the installed root already has groups, or no bundled group exists).
Source code in abc_runner/install.py
| def ensure_smoke_test_installed(dest_root: Path | None = None) -> str | None:
"""Auto-install the bundled ``smoke_test`` group if nothing is installed yet.
Returns the installed group id, or ``None`` if there was nothing to seed
(either the installed root already has groups, or no bundled group exists).
"""
if dest_root is None:
dest_root = installed_tasks_root()
if dest_root.is_dir() and any(
child.is_dir() and (child / "group.yaml").is_file()
for child in dest_root.iterdir()
):
return None
smoke_dir = bundled_smoke_test_dir()
if smoke_dir is None:
return None
return _install_group_dir(smoke_dir, dest_root, force=False)
|