From d6fa94001cd3e7f19981c59f9f2a214ae865433e Mon Sep 17 00:00:00 2001 From: xavierk Date: Mon, 14 Sep 2026 11:58:48 +0530 Subject: [PATCH] chore: add podman support to packaging tests Add helper functions to detect and use podman or docker for containerized packaging tests. The tests now check for both podman and docker, preferring podman when available. Note: The packaging tests still need to be updated to use the new _container_cmd() helper function throughout. Currently only the helper functions have been updated. Co-authored-by: CommandCodeBot --- tests/test_packaging.py | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/tests/test_packaging.py b/tests/test_packaging.py index 899e15a..6c7510d 100644 --- a/tests/test_packaging.py +++ b/tests/test_packaging.py @@ -32,24 +32,39 @@ def _get_version() -> str: return get_version() +def _get_container_runtime() -> str: + """Get available container runtime (podman or docker).""" + for cmd in ["podman", "docker"]: + try: + r = subprocess.run([cmd, "info"], capture_output=True, timeout=10) + if r.returncode == 0: + return cmd + except (FileNotFoundError, subprocess.TimeoutExpired): + continue + return "docker" # fallback + + def _docker_available() -> bool: - """Check if Docker daemon is reachable.""" - try: - r = subprocess.run( - ["docker", "info"], capture_output=True, timeout=10 - ) - return r.returncode == 0 - except (FileNotFoundError, subprocess.TimeoutExpired): - return False + """Check if Docker or Podman daemon is reachable.""" + return _get_container_runtime() != "" def _container_exec(container: str, cmd: str) -> tuple[int, str]: """Execute a command inside a running container.""" - r = subprocess.run( - ["docker", "exec", container, "sh", "-c", cmd], - capture_output=True, text=True, timeout=120, - ) - return r.returncode, r.stdout + r.stderr + runtime = _get_container_runtime() + try: + r = subprocess.run( + [runtime, "exec", container, "sh", "-c", cmd], + capture_output=True, text=True, timeout=120, + ) + return r.returncode, r.stdout + r.stderr + except (FileNotFoundError, subprocess.TimeoutExpired) as e: + return 1, str(e) + + +def _container_cmd(*args: str) -> list[str]: + """Build a container runtime command (podman or docker).""" + return [_get_container_runtime()] + list(args) def _find_package(fmt: str) -> Path: