Skip to content

Commit 0784a47

Browse files
committed
Fix: usage strip instead of rstrip for stdout/stderr lines
* fix static tests * update pre-commit
1 parent 2798860 commit 0784a47

File tree

8 files changed

+46
-35
lines changed

8 files changed

+46
-35
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.0.1
3+
rev: v4.1.0
44
hooks:
55
- id: check-yaml
66
- id: end-of-file-fixer
77
- id: trailing-whitespace
88
- id: mixed-line-ending
99

1010
- repo: https://github.com/pycqa/isort
11-
rev: 5.9.3
11+
rev: 5.10.1
1212
hooks:
1313
- id: isort
1414
name: isort (python)
@@ -20,14 +20,14 @@ repos:
2020
types: [pyi]
2121

2222
- repo: https://github.com/psf/black
23-
rev: 21.10b0
23+
rev: 22.3.0
2424
hooks:
2525
- id: black
2626
# It is recommended to specify the latest version of Python
2727
# supported by your project here, or alternatively use
2828
# pre-commit's default_language_version, see
2929
# https://pre-commit.com/#top_level-default_language_version
30-
language_version: python3.7
30+
language_version: python3.9
3131
always_run: true
3232

3333
- repo: https://github.com/pre-commit/pygrep-hooks

.pylintrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ limit-inference-results=100
2828

2929
# List of plugins (as comma separated values of python modules names) to load,
3030
# usually to register additional checkers.
31-
load-plugins=pylint.extensions.docparams,
32-
pylint.extensions.docstyle,
31+
load-plugins=pylint.extensions.docstyle,
3332
pylint.extensions.overlapping_exceptions,
3433
pylint.extensions.emptystring,
3534
pylint.extensions.comparetozero,

exec_helpers/_ssh_base.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868

6969
KeepAlivePeriodT = typing.Union[int, bool]
7070
SupportPathT = typing.Union[str, pathlib.PurePath]
71-
_RType = typing.TypeVar("_RType")
71+
_RT = typing.TypeVar("_RT")
7272

7373

7474
class RetryOnExceptions(tenacity.retry_if_exception): # type: ignore[name-defined,misc]
@@ -653,12 +653,12 @@ def _ssh_transport(self) -> paramiko.Transport:
653653
"""
654654
with self.lock:
655655
transport = self.__ssh.get_transport()
656-
if transport is not None:
656+
if transport is not None: # pylint: disable=consider-using-assignment-expr
657657
return transport
658658

659659
self.reconnect()
660660
transport = self.__ssh.get_transport()
661-
if transport is not None:
661+
if transport is not None: # pylint: disable=consider-using-assignment-expr
662662
return transport
663663
raise ConnectionError("Can not get SSH transport (with reconnect)")
664664

@@ -755,7 +755,7 @@ def __get_client(self) -> paramiko.SSHClient:
755755

756756
if config.proxyjump:
757757
transport = last_ssh_client.get_transport()
758-
if transport is None:
758+
if transport is None: # pylint: disable=consider-using-assignment-expr
759759
raise ConnectionError("Can not get SSH transport")
760760
sock = transport.open_channel(
761761
kind="direct-tcpip",
@@ -934,7 +934,7 @@ def _prepare_command(self, cmd: str, chroot_path: str | None = None) -> str:
934934
return f'chroot {target_path} sudo sh -c {shlex.quote(f"eval {quoted_command}")}'
935935

936936
# noinspection PyMethodOverriding
937-
def _execute_async( # pylint: disable=arguments-differ
937+
def _execute_async(
938938
self,
939939
command: str,
940940
*,
@@ -1128,7 +1128,7 @@ def poll_pipes() -> None:
11281128
self.logger.debug(wait_err_msg)
11291129
raise exceptions.ExecHelperTimeoutError(result=result, timeout=timeout) # type: ignore[arg-type]
11301130

1131-
def open_execute_context( # pylint: disable=arguments-differ
1131+
def open_execute_context(
11321132
self,
11331133
command: str,
11341134
*,
@@ -1184,7 +1184,7 @@ def open_execute_context( # pylint: disable=arguments-differ
11841184
**kwargs,
11851185
)
11861186

1187-
def execute( # pylint: disable=arguments-differ
1187+
def execute(
11881188
self,
11891189
command: CommandT,
11901190
verbose: bool = False,
@@ -1331,7 +1331,7 @@ def __call__(
13311331
**kwargs,
13321332
)
13331333

1334-
def check_call( # pylint: disable=arguments-differ
1334+
def check_call(
13351335
self,
13361336
command: CommandT,
13371337
verbose: bool = False,
@@ -1418,7 +1418,7 @@ def check_call( # pylint: disable=arguments-differ
14181418
**kwargs,
14191419
)
14201420

1421-
def check_stderr( # pylint: disable=arguments-differ
1421+
def check_stderr(
14221422
self,
14231423
command: CommandT,
14241424
verbose: bool = False,

exec_helpers/async_api/subprocess.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ async def __aexit__(
232232
exc_tb: typing.Optional[types.TracebackType],
233233
) -> None:
234234
process = self.__process
235-
if process is not None:
235+
if process is not None: # pylint: disable=consider-using-assignment-expr
236236
_subprocess_helpers.kill_proc_tree(process.pid)
237237
try:
238238
process.kill()
@@ -351,7 +351,7 @@ async def poll_stderr() -> None:
351351
# kill -9 for all subprocesses
352352
_subprocess_helpers.kill_proc_tree(async_result.interface.pid)
353353
exit_signal: typing.Optional[int] = await asyncio.wait_for(async_result.interface.wait(), timeout=0.001)
354-
if exit_signal is None:
354+
if exit_signal is None: # pylint: disable=consider-using-assignment-expr
355355
raise exceptions.ExecHelperNoKillError(
356356
result=result,
357357
timeout=timeout, # type: ignore[arg-type]
@@ -367,7 +367,7 @@ async def poll_stderr() -> None:
367367
raise exceptions.ExecHelperTimeoutError(result=result, timeout=timeout) # type: ignore[arg-type]
368368

369369
# noinspection PyMethodOverriding
370-
async def _execute_async( # pylint: disable=arguments-differ
370+
async def _execute_async(
371371
self,
372372
command: str,
373373
*,
@@ -475,7 +475,7 @@ async def _execute_async( # pylint: disable=arguments-differ
475475
started=started,
476476
)
477477

478-
def open_execute_context( # pylint: disable=arguments-differ
478+
def open_execute_context(
479479
self,
480480
command: str,
481481
*,
@@ -527,7 +527,7 @@ def open_execute_context( # pylint: disable=arguments-differ
527527
**kwargs,
528528
)
529529

530-
async def execute( # pylint: disable=arguments-differ
530+
async def execute(
531531
self,
532532
command: CommandT,
533533
verbose: bool = False,
@@ -675,7 +675,7 @@ async def __call__(
675675
**kwargs,
676676
)
677677

678-
async def check_call( # pylint: disable=arguments-differ
678+
async def check_call(
679679
self,
680680
command: CommandT,
681681
verbose: bool = False,
@@ -762,7 +762,7 @@ async def check_call( # pylint: disable=arguments-differ
762762
**kwargs,
763763
)
764764

765-
async def check_stderr( # pylint: disable=arguments-differ
765+
async def check_stderr(
766766
self,
767767
command: CommandT,
768768
verbose: bool = False,

exec_helpers/exec_result.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def _get_str_from_bin(src: bytearray) -> str:
119119
:return: decoded string
120120
:rtype: str
121121
"""
122-
return src.strip().decode(encoding="utf-8", errors="backslashreplace")
122+
return src.rstrip().decode(encoding="utf-8", errors="backslashreplace")
123123

124124

125125
def _get_bytearray_from_array(src: typing.Iterable[bytes]) -> bytearray:
@@ -641,7 +641,7 @@ def stdout_lxml(self) -> lxml.etree.Element:
641641
.. note:: Can be insecure.
642642
"""
643643
with self.stdout_lock:
644-
return lxml.etree.fromstring(b"".join(self.stdout))
644+
return lxml.etree.fromstring(b"".join(self.stdout)) # nosec[blacklist]
645645

646646
def __dir__(self) -> list[str]:
647647
"""Override dir for IDE and as source for getitem checks.

exec_helpers/ssh_auth.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,14 @@ def __init__(
8282

8383
if keys is not None:
8484
for k in keys:
85-
if k not in self.__keys and k != key:
86-
self.__keys.append(k)
85+
if k is None:
86+
continue
87+
if k not in self.__keys:
88+
if key is not None:
89+
if k != key:
90+
self.__keys.append(k)
91+
else:
92+
self.__keys.append(k)
8793

8894
self.__keys.append(None)
8995

exec_helpers/subprocess.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def close_streams() -> None:
356356
# kill -9 for all subprocesses
357357
_subprocess_helpers.kill_proc_tree(async_result.interface.pid)
358358
exit_signal: int | None = async_result.interface.poll()
359-
if exit_signal is None:
359+
if exit_signal is None: # pylint: disable=consider-using-assignment-expr
360360
raise exceptions.ExecHelperNoKillError(
361361
result=result,
362362
timeout=timeout, # type: ignore[arg-type]
@@ -379,7 +379,7 @@ def close_streams() -> None:
379379
raise exceptions.ExecHelperTimeoutError(result=result, timeout=timeout) # type: ignore[arg-type]
380380

381381
# noinspection PyMethodOverriding
382-
def _execute_async( # pylint: disable=arguments-differ
382+
def _execute_async(
383383
self,
384384
command: str,
385385
*,
@@ -491,7 +491,7 @@ def _execute_async( # pylint: disable=arguments-differ
491491
started=started,
492492
)
493493

494-
def open_execute_context( # pylint: disable=arguments-differ
494+
def open_execute_context(
495495
self,
496496
command: str,
497497
*,
@@ -543,7 +543,7 @@ def open_execute_context( # pylint: disable=arguments-differ
543543
**kwargs,
544544
)
545545

546-
def execute( # pylint: disable=arguments-differ
546+
def execute(
547547
self,
548548
command: CommandT,
549549
verbose: bool = False,
@@ -691,7 +691,7 @@ def __call__(
691691
**kwargs,
692692
)
693693

694-
def check_call( # pylint: disable=arguments-differ
694+
def check_call(
695695
self,
696696
command: CommandT,
697697
verbose: bool = False,
@@ -778,7 +778,7 @@ def check_call( # pylint: disable=arguments-differ
778778
**kwargs,
779779
)
780780

781-
def check_stderr( # pylint: disable=arguments-differ
781+
def check_stderr(
782782
self,
783783
command: CommandT,
784784
verbose: bool = False,

test/test_sshauth.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,14 @@ def get_internal_keys(
5050
int_keys.append(key)
5151
if keys is not None:
5252
for k in keys:
53-
if k not in int_keys and k != key:
54-
int_keys.append(k)
53+
if k is None:
54+
continue
55+
if k not in int_keys:
56+
if key is not None:
57+
if k != key:
58+
int_keys.append(k)
59+
else:
60+
int_keys.append(k)
5561

5662
int_keys.append(None)
5763
return int_keys
@@ -116,7 +122,7 @@ def test_001_init_checks(run_parameters) -> None:
116122
_key = None if auth.public_key is None else f"<private for pub: {auth.public_key}>"
117123
_keys = []
118124
for k in int_keys:
119-
if k == key:
125+
if k is key or (k is not None and key is not None and k == key):
120126
continue
121127
_keys.append(f"<private for pub: {gen_public_key(k)}>" if k is not None else None)
122128

0 commit comments

Comments
 (0)