Skip to content

Commit 4ab5c26

Browse files
authored
fix: types for run_ssh_commands (#145)
1 parent 3c78c18 commit 4ab5c26

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

.pre-commit-config.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,12 @@ repos:
6060
exclude: ^(tests/)
6161
additional_dependencies: [types-requests]
6262
args: [--ignore-missing-imports, --disallow-untyped-defs]
63+
64+
- repo: https://github.com/espressif/conventional-precommit-linter
65+
rev: v1.10.0 # The version tag you wish to use
66+
hooks:
67+
- id: conventional-precommit-linter
68+
stages: [commit-msg]
69+
args:
70+
- --types=ci,docs,feat,fix,refactor,test,release
71+
- --subject-min-length=15

pyhelper_utils/shell.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
1+
from __future__ import annotations
2+
13
import subprocess
2-
from typing import Any, List, Optional, Tuple
4+
from typing import Any
35

6+
from rrmngmnt import Host
47
from simple_logger.logger import get_logger
58

69
from pyhelper_utils.exceptions import CommandExecFailed
7-
from rrmngmnt import Host
810

911
LOGGER = get_logger(name=__name__)
1012

1113
TIMEOUT_30MIN = 30 * 60
1214

1315

1416
def run_command(
15-
command: List[str],
17+
command: list[str],
1618
verify_stderr: bool = True,
1719
shell: bool = False,
18-
timeout: Optional[int] = None,
20+
timeout: int | None = None,
1921
capture_output: bool = True,
2022
check: bool = True,
2123
hide_log_command: bool = False,
2224
log_errors: bool = True,
2325
**kwargs: Any,
24-
) -> Tuple[bool, str, str]:
26+
) -> tuple[bool, str, str]:
2527
"""
2628
Run command locally.
2729
@@ -83,11 +85,11 @@ def run_command(
8385

8486
def run_ssh_commands(
8587
host: Host,
86-
commands: List[str],
88+
commands: list[Any],
8789
get_pty: bool = False,
8890
check_rc: bool = True,
8991
timeout: int = TIMEOUT_30MIN,
90-
tcp_timeout: Optional[float] = None,
92+
tcp_timeout: float | None = None,
9193
) -> list:
9294
"""
9395
Run commands on remote host via SSH
@@ -110,8 +112,9 @@ def run_ssh_commands(
110112
Raise:
111113
CommandExecFailed: If command failed to execute.
112114
"""
113-
results: List[str] = []
114-
commands_list: List[List[str]] = commands if isinstance(commands[0], list) else [commands]
115+
results: list[str] = []
116+
commands_list: list[list[str]] = commands if isinstance(commands[0], list) else [commands]
117+
115118
with host.executor().session(timeout=tcp_timeout) as ssh_session:
116119
for cmd in commands_list:
117120
rc, out, err = ssh_session.run_cmd(cmd=cmd, get_pty=get_pty, timeout=timeout)

0 commit comments

Comments
 (0)