From 9a3b1b4be1a5bf842ebad9ca39c1e85bed836f43 Mon Sep 17 00:00:00 2001 From: Leo Dewaele Date: Fri, 22 May 2026 11:01:32 +0900 Subject: [PATCH 1/2] Arch support for dependencies checking --- src/piper_control/piper_connect.py | 36 ++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/piper_control/piper_connect.py b/src/piper_control/piper_connect.py index 61f11c2..9498dd2 100644 --- a/src/piper_control/piper_connect.py +++ b/src/piper_control/piper_connect.py @@ -8,6 +8,7 @@ import subprocess import time +import shutil # ------------------------ # Public API @@ -97,16 +98,33 @@ def get_can_adapter_serial(can_port: str) -> str | None: # Internal Utility Methods # ------------------------ - def _check_dependencies() -> None: - for pkg in ["ethtool", "can-utils"]: - try: - subprocess.run(["dpkg", "-s", pkg], check=True, stdout=subprocess.DEVNULL) - except subprocess.CalledProcessError as exc: - raise RuntimeError( - f"Missing dependency: {pkg}. Please install with `sudo apt install " - f"{pkg}`." - ) from exc + # Detect package manager + if shutil.which("pacman"): + query_cmd = lambda pkg: ["pacman", "-Q", pkg] + install_cmd = "sudo pacman -S" + elif shutil.which("dpkg"): + query_cmd = lambda pkg: ["dpkg", "-s", pkg] + install_cmd = "sudo apt install" + else: + raise RuntimeError("Unsupported package manager. \ + Please ensure ethtool and can-utils \ + are installed manually.") + + + for pkg in ["ethtool", "can-utils"]: + try: + subprocess.run( + query_cmd(pkg), + check=True, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + ) + except subprocess.CalledProcessError as exc: + raise RuntimeError( + f"Missing dependency: {pkg}. \ + Please install with `{install_cmd} {pkg}`." + ) from exc def _get_can_interfaces() -> list[tuple[str, str]]: From ed72ba9168d76cb6193500de89971f9ba29666cd Mon Sep 17 00:00:00 2001 From: Leo Dewaele Date: Fri, 22 May 2026 14:23:03 +0900 Subject: [PATCH 2/2] Linting --- src/piper_control/piper_connect.py | 59 +++++++++++++++++------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/src/piper_control/piper_connect.py b/src/piper_control/piper_connect.py index 9498dd2..74372d0 100644 --- a/src/piper_control/piper_connect.py +++ b/src/piper_control/piper_connect.py @@ -6,9 +6,9 @@ from higher-level Python code. """ +import shutil import subprocess import time -import shutil # ------------------------ # Public API @@ -98,33 +98,40 @@ def get_can_adapter_serial(can_port: str) -> str | None: # Internal Utility Methods # ------------------------ + def _check_dependencies() -> None: - # Detect package manager - if shutil.which("pacman"): - query_cmd = lambda pkg: ["pacman", "-Q", pkg] - install_cmd = "sudo pacman -S" - elif shutil.which("dpkg"): - query_cmd = lambda pkg: ["dpkg", "-s", pkg] - install_cmd = "sudo apt install" - else: - raise RuntimeError("Unsupported package manager. \ - Please ensure ethtool and can-utils \ - are installed manually.") - - - for pkg in ["ethtool", "can-utils"]: - try: - subprocess.run( - query_cmd(pkg), - check=True, - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, - ) - except subprocess.CalledProcessError as exc: - raise RuntimeError( - f"Missing dependency: {pkg}. \ + # Detect package manager + def _pacman_query(pkg: str) -> list[str]: + return ["pacman", "-Q", pkg] + + def _dpkg_query(pkg: str) -> list[str]: + return ["dpkg", "-s", pkg] + + if shutil.which("pacman"): + query_cmd = _pacman_query + install_cmd = "sudo pacman -S" + elif shutil.which("dpkg"): + query_cmd = _dpkg_query + install_cmd = "sudo apt install" + else: + raise RuntimeError( + "Unsupported package manager. " + "Please ensure ethtool and can-utils are installed manually." + ) + + for pkg in ["ethtool", "can-utils"]: + try: + subprocess.run( + query_cmd(pkg), + check=True, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + ) + except subprocess.CalledProcessError as exc: + raise RuntimeError( + f"Missing dependency: {pkg}. \ Please install with `{install_cmd} {pkg}`." - ) from exc + ) from exc def _get_can_interfaces() -> list[tuple[str, str]]: