From 6fa2a977df8a4dc0a7b5de1ad384e033a4a480c3 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Wed, 13 Aug 2025 19:21:18 +0200 Subject: [PATCH] askpass: use protocol as interface Avoids a cyclic dependency on the Remote class Strips down the dependency closure by explizitly declaring what functions it needs --- .../clan-cli/clan_lib/ssh/sudo_askpass_proxy.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/pkgs/clan-cli/clan_lib/ssh/sudo_askpass_proxy.py b/pkgs/clan-cli/clan_lib/ssh/sudo_askpass_proxy.py index e5ffbb349..a3459a6d7 100644 --- a/pkgs/clan-cli/clan_lib/ssh/sudo_askpass_proxy.py +++ b/pkgs/clan-cli/clan_lib/ssh/sudo_askpass_proxy.py @@ -8,21 +8,28 @@ import sys import termios import threading from pathlib import Path -from typing import TYPE_CHECKING +from typing import Protocol from clan_lib.cmd import terminate_process from clan_lib.errors import ClanError -if TYPE_CHECKING: - from clan_lib.ssh.remote import Remote - logger = logging.getLogger(__name__) remote_script = (Path(__file__).parent / "sudo_askpass_proxy.sh").read_text() +class RemoteP(Protocol): + @property + def address(self) -> str: ... + + @property + def target(self) -> str: ... + + def ssh_cmd(self) -> list[str]: ... + + class SudoAskpassProxy: - def __init__(self, host: "Remote", prompt_command: list[str]) -> None: + def __init__(self, host: "RemoteP", prompt_command: list[str]) -> None: self.host = host self.password_prompt_command = prompt_command self.ssh_process: subprocess.Popen | None = None