Skip to content

Commit 3129fc4

Browse files
committedJun 4, 2024·
Normalize docstrings for better documentation generation
1 parent aa99ff4 commit 3129fc4

16 files changed

+1031
-1030
lines changed
 

‎exec_helpers/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@
8787
def __getattr__(name: str) -> typing.Any:
8888
"""Get attributes lazy.
8989
90-
:return: attribute by name
91-
:raises AttributeError: attribute is not defined for lazy load
90+
:return: Attribute by name.
91+
:raises AttributeError: Attribute is not defined for the lazy load.
9292
"""
9393
if name in _deprecated:
9494
warnings.warn(

‎exec_helpers/_helpers.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313

1414
def string_bytes_bytearray_as_bytes(src: str | bytes | bytearray) -> bytes:
15-
"""Get bytes string from string/bytes/bytearray union.
15+
"""Get byte string from string/bytes/bytearray union.
1616
17-
:param src: source string or bytes-like object
18-
:return: Byte string
17+
:param src: Source string or bytes-like object.
18+
:return: Byte string.
1919
:rtype: bytes
2020
:raises TypeError: unexpected source type.
2121
"""
@@ -31,11 +31,11 @@ def string_bytes_bytearray_as_bytes(src: str | bytes | bytearray) -> bytes:
3131
def _mask_command(text: str, rules: str | re.Pattern[str]) -> str:
3232
"""Mask part of text using rules.
3333
34-
:param text: source text
34+
:param text: Source text.
3535
:type text: str
36-
:param rules: regex rules to mask.
36+
:param rules: Regex rules to mask.
3737
:type rules: str | re.Pattern
38-
:return: source with all MATCHED groups replaced by '<*masked*>'
38+
:return: Source with all MATCHED groups replaced by '<*masked*>'.
3939
:rtype: str
4040
"""
4141
masked: list[str] = []
@@ -55,11 +55,11 @@ def _mask_command(text: str, rules: str | re.Pattern[str]) -> str:
5555
def mask_command(text: str, *rules: str | re.Pattern[str] | None) -> str:
5656
"""Apply all rules to command.
5757
58-
:param text: source text
58+
:param text: Source text.
5959
:type text: str
60-
:param rules: regex rules to mask.
60+
:param rules: Regex rules to mask.
6161
:type rules: str | re.Pattern[str] | None
62-
:return: source with all MATCHED groups replaced by '<*masked*>'
62+
:return: Source with all MATCHED groups replaced by '<*masked*>'.
6363
:rtype: str
6464
"""
6565
return functools.reduce(_mask_command, (rule for rule in rules if rule is not None), text)
@@ -68,9 +68,9 @@ def mask_command(text: str, *rules: str | re.Pattern[str] | None) -> str:
6868
def cmd_to_string(command: str | Iterable[str]) -> str:
6969
"""Convert command to string for usage with shell.
7070
71-
:param command: original command.
71+
:param command: Original command.
7272
:type command: str | Iterable[str]
73-
:return: command as single string
73+
:return: Command as single string.
7474
:rtype: str
7575
"""
7676
if isinstance(command, str):
@@ -81,13 +81,13 @@ def cmd_to_string(command: str | Iterable[str]) -> str:
8181
def chroot_command(command: str, chroot_path: str | None = None, chroot_exe: str = "chroot") -> str:
8282
"""Prepare command for chroot execution.
8383
84-
:param command: original command.
84+
:param command: Original command.
8585
:type command: str
86-
:param chroot_path: chroot path
86+
:param chroot_path: chroot path.
8787
:type chroot_path: str | None
88-
:param chroot_exe: chroot executable
88+
:param chroot_exe: chroot executable.
8989
:type chroot_exe: str
90-
:return: command to be executed with chroot rules if applicable
90+
:return: Command to be executed with chroot rules if applicable.
9191
:rtype: str
9292
"""
9393
if chroot_path and chroot_path != "/":

‎exec_helpers/_ssh_base.py

+285-284
Large diffs are not rendered by default.

‎exec_helpers/_ssh_helpers.py

+46-46
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
def _parse_ssh_config_file(file_path: pathlib.Path) -> paramiko.SSHConfig | None:
2828
"""Parse ssh config file.
2929
30-
:param file_path: file path for parsing
30+
:param file_path: File path for parsing.
3131
:type file_path: pathlib.Path
32-
:return: SSH config if file found and parsed else None
32+
:return: SSH config if file found and parsed else None.
3333
:rtype: paramiko.SSHConfig | None
3434
"""
3535
if not file_path.exists():
@@ -73,21 +73,21 @@ def __init__(
7373
):
7474
"""SSH Config for creation connection.
7575
76-
:param hostname: hostname, which config relates
76+
:param hostname: Hostname, which config relates.
7777
:type hostname: str
78-
:param port: remote port
78+
:param port: Remote port.
7979
:type port: str | int | None
80-
:param user: remote user
80+
:param user: Remote user.
8181
:type user: str | None
82-
:param identityfile: connection ssh keys file names
82+
:param identityfile: Connection ssh keys file names.
8383
:type identityfile: Collection[str] | None
84-
:param proxycommand: proxy command for ssh connection
84+
:param proxycommand: Proxy command for ssh connection.
8585
:type proxycommand: str | None
86+
:param proxyjump: Proxy host name.
8687
:type proxyjump: str | None
87-
:param proxyjump: proxy host name
88-
:param controlpath: shared socket file path for re-using connection by multiple instances
88+
:param controlpath: Shared socket file path for re-using connection by multiple instances.
8989
:type controlpath: str | None
90-
:param controlmaster: re-use connection
90+
:param controlmaster: Re-use connection.
9191
:type controlmaster: str | bool | None
9292
:raises ValueError: Invalid argument provided.
9393
@@ -114,7 +114,7 @@ def __init__(
114114
def __hash__(self) -> int: # pragma: no cover
115115
"""Hash for caching possibility.
116116
117-
:return: hash for instance
117+
:return: hash for instance.
118118
:rtype: int
119119
"""
120120
return hash(
@@ -134,7 +134,7 @@ def __hash__(self) -> int: # pragma: no cover
134134
def __repr__(self) -> str:
135135
"""Debug support.
136136
137-
:return: string representation allowing to re-construct object
137+
:return: String representation allowing to re-construct an object.
138138
:rtype: str
139139
"""
140140
return (
@@ -158,13 +158,13 @@ def __pretty_repr__(
158158
) -> str:
159159
"""Make human-readable representation of object.
160160
161-
:param log_wrap: logwrap instance
161+
:param log_wrap: Logwrap instance.
162162
:type log_wrap: logwrap.PrettyRepr
163-
:param indent: start indentation
163+
:param indent: Start indentation.
164164
:type indent: int
165-
:param no_indent_start: do not indent open bracket and simple parameters
165+
:param no_indent_start: Do not indent open bracket and simple parameters.
166166
:type no_indent_start: bool
167-
:return: formatted string
167+
:return: Formatted string.
168168
:rtype: str
169169
"""
170170
next_indent = log_wrap.next_indent(indent)
@@ -186,9 +186,9 @@ def __pretty_repr__(
186186
def _parse_optional_int(value: str | int | None) -> int | None:
187187
"""Parse optional integer field in source data.
188188
189-
:param value: value to process
189+
:param value: Value to process.
190190
:type value: str | int | None
191-
:return: integer value if applicable
191+
:return: Integer value if applicable.
192192
:rtype: int | None
193193
"""
194194
if value is None or isinstance(value, int):
@@ -199,9 +199,9 @@ def _parse_optional_int(value: str | int | None) -> int | None:
199199
def _parse_optional_bool(value: str | bool | None) -> bool | None:
200200
"""Parse optional bool field in source data.
201201
202-
:param value: value to process
202+
:param value: Value to process.
203203
:type value: str | bool | None
204-
:return: boolean value if applicable
204+
:return: Boolean value if applicable.
205205
:rtype: bool | None
206206
"""
207207
if value is None or isinstance(value, bool):
@@ -215,9 +215,9 @@ def from_ssh_config(
215215
) -> SSHConfig:
216216
"""Construct config from Paramiko parsed file.
217217
218-
:param ssh_config: paramiko parsed ssh config or it reconstruction as a dict
218+
:param ssh_config: Paramiko parsed ssh config or it reconstruction as a dict.
219219
:type ssh_config: paramiko.config.SSHConfigDict | dict[str, str | int | bool | list[str]]
220-
:return: SSHConfig with supported values from config
220+
:return: SSHConfig with supported values from config.
221221
:rtype: SSHConfig
222222
"""
223223
return cls(
@@ -235,7 +235,7 @@ def from_ssh_config(
235235
def as_dict(self) -> SSHConfigDictLikeT:
236236
"""Dictionary for rebuilding config.
237237
238-
:return: config as dictionary with only not None values
238+
:return: Config as dictionary with only not None values.
239239
:rtype: dict[str, str | int | bool | list[str]]
240240
"""
241241
result: SSHConfigDictLikeT = {"hostname": self.hostname}
@@ -258,9 +258,9 @@ def as_dict(self) -> SSHConfigDictLikeT:
258258
def overridden_by(self, ssh_config: SSHConfig) -> SSHConfig:
259259
"""Get copy with values overridden by another config.
260260
261-
:param ssh_config: Other ssh config
261+
:param ssh_config: Other ssh config.
262262
:type ssh_config: SSHConfig
263-
:return: Composite from 2 configs with priority of second one
263+
:return: Composite from two configs with priority of second one.
264264
:rtype: SSHConfig
265265
"""
266266
cls: type[SSHConfig] = self.__class__
@@ -281,7 +281,7 @@ def __eq__(
281281
) -> bool | type(NotImplemented): # type: ignore[valid-type]
282282
"""Equality check.
283283
284-
:return: other equals self
284+
:return: Other equals self.
285285
:rtype: bool
286286
"""
287287
if isinstance(other, SSHConfig):
@@ -306,7 +306,7 @@ def __eq__(
306306
def hostname(self) -> str:
307307
"""Hostname which config relates.
308308
309-
:return: remote hostname
309+
:return: Remote hostname.
310310
:rtype: str
311311
"""
312312
return self.__hostname
@@ -315,7 +315,7 @@ def hostname(self) -> str:
315315
def port(self) -> int | None:
316316
"""Remote port.
317317
318-
:return: propagated remote port for connection
318+
:return: Propagated remote port for connection.
319319
:rtype: int | None
320320
"""
321321
return self.__port
@@ -324,7 +324,7 @@ def port(self) -> int | None:
324324
def user(self) -> str | None:
325325
"""Remote user.
326326
327-
:return: propagated username for connection
327+
:return: Propagated username for connection.
328328
:rtype: str | None
329329
"""
330330
return self.__user
@@ -333,7 +333,7 @@ def user(self) -> str | None:
333333
def identityfile(self) -> Collection[str]:
334334
"""Connection ssh keys file names.
335335
336-
:return: list of ssh private keys names
336+
:return: List of ssh private keys names.
337337
:rtype: Collection[str]
338338
"""
339339
if self.__identityfile is None:
@@ -346,7 +346,7 @@ def identityfile(self) -> Collection[str]:
346346
def proxycommand(self) -> str | None:
347347
"""Proxy command for ssh connection.
348348
349-
:return: command to be executed for socket creation if applicable
349+
:return: Command to be executed for socket creation if applicable.
350350
:rtype: str | None
351351
"""
352352
return self.__proxycommand
@@ -355,7 +355,7 @@ def proxycommand(self) -> str | None:
355355
def proxyjump(self) -> str | None:
356356
"""Proxy host name.
357357
358-
:return: proxy hostname if applicable
358+
:return: Proxy hostname if applicable.
359359
:rtype: str | None
360360
"""
361361
return self.__proxyjump
@@ -364,7 +364,7 @@ def proxyjump(self) -> str | None:
364364
def controlpath(self) -> str | None:
365365
"""Shared socket file path for re-using connection by multiple instances.
366366
367-
:return: shared socket filesystem path
367+
:return: Shared socket filesystem path.
368368
:rtype: str | None
369369
"""
370370
return self.__controlpath
@@ -373,7 +373,7 @@ def controlpath(self) -> str | None:
373373
def controlmaster(self) -> bool | None:
374374
"""Re-use connection.
375375
376-
:return: connection should be re-used if possible
376+
:return: Connection should be re-used if possible.
377377
:rtype: bool | None
378378
"""
379379
return self.__controlmaster
@@ -382,17 +382,17 @@ def controlmaster(self) -> bool | None:
382382
class HostsSSHConfigs(typing.Dict[str, SSHConfig]):
383383
"""Specific dictionary for managing SSHConfig records.
384384
385-
Instead of creating new record by request just generate default value and return if not exists.
385+
Instead of creating a new record by request, just generate default value and return if not exists.
386386
"""
387387

388388
def __missing__(self, key: str) -> SSHConfig:
389389
"""Missing key handling.
390390
391-
:param key: nonexistent key
391+
:param key: Nonexistent key.
392392
:type key: str
393-
:return: generated ssh config for host
393+
:return: Generated ssh config for host.
394394
:rtype: SSHConfig
395-
:raises KeyError: key is not string
395+
:raises KeyError: key is not string.
396396
.. versionadded:: 6.0.0
397397
"""
398398
if isinstance(key, str):
@@ -403,11 +403,11 @@ def __missing__(self, key: str) -> SSHConfig:
403403
def _parse_paramiko_ssh_config(conf: paramiko.SSHConfig, host: str) -> HostsSSHConfigs:
404404
"""Parse Paramiko ssh config for specific host to dictionary.
405405
406-
:param conf: Paramiko SSHConfig instance
406+
:param conf: Paramiko SSHConfig instance.
407407
:type conf: paramiko.SSHConfig
408-
:param host: hostname to seek in config
408+
:param host: Hostname to seek in config.
409409
:type host: str
410-
:return: parsed dictionary with proxy jump path, if available
410+
:return: Parsed dictionary with a proxy jump path, if available.
411411
:rtype: HostsSSHConfigs
412412
"""
413413
config = HostsSSHConfigs({host: SSHConfig.from_ssh_config(conf.lookup(host))})
@@ -424,11 +424,11 @@ def _parse_paramiko_ssh_config(conf: paramiko.SSHConfig, host: str) -> HostsSSHC
424424
def _parse_dict_ssh_config(conf: SSHConfigsDictT, host: str) -> HostsSSHConfigs:
425425
"""Extract required data from pre-parsed ssh config for specific host to dictionary.
426426
427-
:param conf: pre-parsed dictionary
427+
:param conf: Pre-parsed dictionary.
428428
:type conf: dict[str, dict[str, str | int | bool | list[str]]]
429-
:param host: hostname to seek in config
429+
:param host: Hostname to seek in config.
430430
:type host: str
431-
:return: parsed dictionary with proxy jump path, if available
431+
:return: Parsed dictionary with a proxy jump path, if available.
432432
:rtype: HostsSSHConfigs
433433
"""
434434
config = HostsSSHConfigs({host: SSHConfig.from_ssh_config(conf.get(host, {"hostname": host}))})
@@ -454,9 +454,9 @@ def parse_ssh_config(
454454
| paramiko.SSHConfig
455455
| dict[str, dict[str, str | int | bool | list[str]]]
456456
| None
457-
:param host: remote hostname
457+
:param host: Remote hostname.
458458
:type host: str
459-
:return: parsed ssh config if available
459+
:return: Parsed ssh config if available.
460460
:rtype: HostsSSHConfigs
461461
"""
462462
if isinstance(ssh_config, paramiko.SSHConfig):

‎exec_helpers/_subprocess_helpers.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ def kill_proc_tree(pid: int, including_parent: bool = True) -> None: # pragma:
3939
def safe_stop(proc: psutil.Process, kill: bool = False) -> None:
4040
"""Do not crash on already stopped process.
4141
42-
:param proc: target process
42+
:param proc: Target process.
4343
:type proc: psutil.Process
44-
:param kill: use SIGKILL instead of SIGTERM
44+
:param kill: Use SIGKILL instead of SIGTERM.
4545
:type kill: bool
4646
"""
4747
with contextlib.suppress(psutil.NoSuchProcess):
@@ -52,7 +52,7 @@ def safe_stop(proc: psutil.Process, kill: bool = False) -> None:
5252
try:
5353
parent = psutil.Process(pid)
5454
except psutil.NoSuchProcess:
55-
# Process is already closed
55+
# The process is already closed
5656
return
5757
children: list[psutil.Process] = parent.children(recursive=True)
5858
child: psutil.Process

‎exec_helpers/api.py

+139-139
Large diffs are not rendered by default.

‎exec_helpers/async_api/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
def __getattr__(name: str) -> typing.Any:
5555
"""Get attributes lazy.
5656
57-
:return: attribute by name
58-
:raises AttributeError: attribute is not defined for lazy load
57+
:return: Attribute by name.
58+
:raises AttributeError: Attribute is not defined for the lazy load.
5959
"""
6060
if name in _deprecated:
6161
warnings.warn(

‎exec_helpers/async_api/api.py

+123-123
Large diffs are not rendered by default.

‎exec_helpers/async_api/exec_result.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ async def _poll_stream( # type: ignore[override] # pylint: disable=invalid-ove
4444
) -> list[bytes]:
4545
"""Stream poll helper.
4646
47-
:param src: source to read from
48-
:param log: logger instance, if line per line logging expected
49-
:param verbose: use INFO level for logging
50-
:return: read result as list of bytes strings
47+
:param src: Source to read from.
48+
:param log: Logger instance, if line per-line logging is expected.
49+
:param verbose: Use INFO level for logging.
50+
:return: Read result as a list of byte strings.
5151
"""
5252
dst: list[bytes] = []
5353
with contextlib.suppress(IOError):
@@ -68,13 +68,13 @@ async def read_stdout( # type: ignore[override] # pylint: disable=invalid-over
6868
) -> None:
6969
"""Read asyncio stdout transport to stdout.
7070
71-
:param src: source
71+
:param src: Source.
7272
:type src: AsyncIterable[bytes] | None
73-
:param log: logger
73+
:param log: Logger.
7474
:type log: logging.Logger | None
75-
:param verbose: use log.info instead of log.debug
75+
:param verbose: Use log.info instead of log.debug.
7676
:type verbose: bool
77-
:raises RuntimeError: Exit code is already received
77+
:raises RuntimeError: Exit code is already received.
7878
7979
.. versionadded:: 3.0.0
8080
"""
@@ -95,13 +95,13 @@ async def read_stderr( # type: ignore[override] # pylint: disable=invalid-over
9595
) -> None:
9696
"""Read asyncio stderr transport to stdout.
9797
98-
:param src: source
98+
:param src: Source.
9999
:type src: AsyncIterable[bytes] | None
100-
:param log: logger
100+
:param log: Logger.
101101
:type log: logging.Logger | None
102-
:param verbose: use log.info instead of log.debug
102+
:param verbose: Use log.info instead of log.debug.
103103
:type verbose: bool
104-
:raises RuntimeError: Exit code is already received
104+
:raises RuntimeError: Exit code is already received.
105105
106106
.. versionadded:: 3.0.0
107107
"""

‎exec_helpers/async_api/subprocess.py

+111-111
Large diffs are not rendered by default.

‎exec_helpers/exceptions.py

+32-32
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class ExecCalledProcessError(ExecHelperError):
5959

6060

6161
class ExecHelperTimeoutProcessError(ExecCalledProcessError):
62-
"""Timeout based errors."""
62+
"""Timeout-based errors."""
6363

6464
__slots__ = ("result", "timeout")
6565

@@ -72,11 +72,11 @@ def __init__(
7272
) -> None:
7373
"""Exception for error on process calls.
7474
75-
:param message: exception message
75+
:param message: Exception message.
7676
:type message: str
77-
:param result: execution result
77+
:param result: Execution result.
7878
:type result: exec_result.ExecResult
79-
:param timeout: timeout for command
79+
:param timeout: Timeout for command.
8080
:type timeout: int | float
8181
"""
8282
super().__init__(message)
@@ -87,23 +87,23 @@ def __init__(
8787
def cmd(self) -> str:
8888
"""Failed command.
8989
90-
:return: command
90+
:return: Command.
9191
"""
9292
return self.result.cmd
9393

9494
@property
9595
def stdout(self) -> str:
9696
"""Command stdout.
9797
98-
:return: command stdout as string
98+
:return: Command STDOUT as string.
9999
"""
100100
return self.result.stdout_str
101101

102102
@property
103103
def stderr(self) -> str:
104104
"""Command stderr.
105105
106-
:return: command stderr as string
106+
:return: Command STDERR as string.
107107
"""
108108
return self.result.stderr_str
109109

@@ -123,9 +123,9 @@ def __init__(
123123
) -> None:
124124
"""Exception for error on process calls.
125125
126-
:param result: execution result
126+
:param result: Execution result.
127127
:type result: exec_result.ExecResult
128-
:param timeout: timeout for command
128+
:param timeout: Timeout for command.
129129
:type timeout: int | float
130130
"""
131131
message: str = (
@@ -142,8 +142,8 @@ def __init__(
142142
class ExecHelperTimeoutError(ExecHelperTimeoutProcessError):
143143
"""Execution timeout.
144144
145-
.. versionchanged:: 1.3.0 provide full result and timeout inside.
146-
.. versionchanged:: 1.3.0 subclass ExecCalledProcessError
145+
.. versionchanged:: 1.3.0 Provide full result and timeout inside.
146+
.. versionchanged:: 1.3.0 Subclass ExecCalledProcessError
147147
"""
148148

149149
__slots__ = ()
@@ -155,9 +155,9 @@ def __init__(
155155
) -> None:
156156
"""Exception for error on process calls.
157157
158-
:param result: execution result
158+
:param result: Execution result.
159159
:type result: exec_result.ExecResult
160-
:param timeout: timeout for command
160+
:param timeout: Timeout for command.
161161
:type timeout: int | float
162162
"""
163163
message: str = _log_templates.CMD_WAIT_ERROR.format(result=result, timeout=timeout)
@@ -176,13 +176,13 @@ def __init__(
176176
) -> None:
177177
"""Exception for error on process calls.
178178
179-
:param result: execution result
179+
:param result: Execution result.
180180
:type result: exec_result.ExecResult
181-
:param expected: expected return codes
181+
:param expected: Expected return codes.
182182
:type expected: Iterable[int | proc_enums.ExitCodes]
183183
184-
.. versionchanged:: 1.1.1 - provide full result
185-
.. versionchanged:: 3.4.0 Expected is not optional, defaults os dependent
184+
.. versionchanged:: 1.1.1 - provide full result.
185+
.. versionchanged:: 3.4.0 Expected is not optional, defaults os dependent.
186186
"""
187187
self.result: exec_result.ExecResult = result
188188
self.expected: Sequence[ExitCodeT] = proc_enums.exit_codes_to_enums(expected)
@@ -198,31 +198,31 @@ def __init__(
198198
def returncode(self) -> ExitCodeT:
199199
"""Command return code.
200200
201-
:return: command return code
201+
:return: Command return code.
202202
"""
203203
return self.result.exit_code
204204

205205
@property
206206
def cmd(self) -> str:
207207
"""Failed command.
208208
209-
:return: command
209+
:return: Command.
210210
"""
211211
return self.result.cmd
212212

213213
@property
214214
def stdout(self) -> str:
215215
"""Command stdout.
216216
217-
:return: command stdout as string
217+
:return: Command STDOUT as string.
218218
"""
219219
return self.result.stdout_str
220220

221221
@property
222222
def stderr(self) -> str:
223223
"""Command stderr.
224224
225-
:return: command stderr as string
225+
:return: Command STDERR as string.
226226
"""
227227
return self.result.stderr_str
228228

@@ -243,15 +243,15 @@ def __init__(
243243
) -> None:
244244
"""Exception during parallel execution.
245245
246-
:param command: command
246+
:param command: Command.
247247
:type command: str
248-
:param errors: results with errors
248+
:param errors: Results with errors.
249249
:type errors: dict[tuple[str, int], ExecResult]
250-
:param results: all results
250+
:param results: All results.
251251
:type results: dict[tuple[str, int], ExecResult]
252-
:param expected: expected return codes
252+
:param expected: Expected return codes.
253253
:type expected: Iterable[int | proc_enums.ExitCodes]
254-
:param _message: message override
254+
:param _message: Message override.
255255
:type _message: str | None
256256
257257
.. versionchanged:: 3.4.0 Expected is not optional, defaults os dependent
@@ -288,17 +288,17 @@ def __init__(
288288
) -> None:
289289
"""Exception raised during parallel call as result of exceptions.
290290
291-
:param command: command
291+
:param command: Command.
292292
:type command: str
293-
:param exceptions: Exceptions on connections
293+
:param exceptions: Exceptions on connections.
294294
:type exceptions: dict[tuple[str, int], Exception]
295-
:param errors: results with errors
295+
:param errors: Results with errors.
296296
:type errors: dict[tuple[str, int], ExecResult]
297-
:param results: all results
297+
:param results: All results.
298298
:type results: dict[tuple[str, int], ExecResult]
299-
:param expected: expected return codes
299+
:param expected: Expected return codes.
300300
:type expected: Iterable[int | proc_enums.ExitCodes]
301-
:param _message: message override
301+
:param _message: Message override.
302302
:type _message: str | None
303303
304304
.. versionchanged:: 3.4.0 Expected is not optional, defaults os dependent

‎exec_helpers/exec_result.py

+86-86
Large diffs are not rendered by default.

‎exec_helpers/proc_enums.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class SigNum(enum.IntEnum):
7171
def __str__(self) -> str:
7272
"""Representation for logs.
7373
74-
:return: string with value in decimal, hex and text information
74+
:return: String with value in decimal, hex and text information.
7575
:rtype: str
7676
"""
7777
return f"{self.name}<{self.value:d}(0x{self.value:02X})>" # pragma: no cover
@@ -177,7 +177,7 @@ class ExitCodes(enum.IntEnum):
177177
def __str__(self) -> str:
178178
"""Representation for logs.
179179
180-
:return: string with value in decimal, hex and text information
180+
:return: String with value in decimal, hex and text information.
181181
:rtype: str
182182
"""
183183
return f"{self.name}<{self.value:d}(0x{self.value:02X})>"
@@ -191,8 +191,8 @@ def __str__(self) -> str:
191191
def exit_code_to_enum(code: ExitCodeT) -> ExitCodeT: # pragma: no cover
192192
"""Convert exit code to enum if possible.
193193
194-
:param code: code to convert from
195-
:return: enum code if suitable else original code
194+
:param code: Code to convert from.
195+
:return: Enum code if suitable else original code.
196196
"""
197197
if sys.platform == "win32":
198198
return int(code)
@@ -204,8 +204,8 @@ def exit_code_to_enum(code: ExitCodeT) -> ExitCodeT: # pragma: no cover
204204
def exit_codes_to_enums(codes: Iterable[ExitCodeT] | None = None) -> Sequence[ExitCodeT]:
205205
"""Convert integer exit codes to enums.
206206
207-
:param codes: exit codes to process
208-
:return: exit codes as enums if suitable
207+
:param codes: Exit codes to process.
208+
:return: Exit codes as enums if suitable.
209209
"""
210210
if codes is None:
211211
# noinspection PyRedundantParentheses

‎exec_helpers/ssh.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ class SSHClient(_ssh_base.SSHClientBase):
3939
def _path_esc(path: str) -> str:
4040
"""Escape space character in the path.
4141
42-
:param path: path to be escaped
42+
:param path: Path to be escaped.
4343
:type path: str
44-
:return: path with escaped spaces
44+
:return: Path with escaped spaces.
4545
:rtype: str
4646
"""
4747
return path.replace(" ", r"\ ")
4848

4949
def mkdir(self, path: SupportPathT) -> None:
5050
"""Run 'mkdir -p path' on remote.
5151
52-
:param path: path to create
52+
:param path: Path to create.
5353
:type path: str | pathlib.PurePath
5454
"""
5555
if self.exists(path):
@@ -60,7 +60,7 @@ def mkdir(self, path: SupportPathT) -> None:
6060
def rm_rf(self, path: SupportPathT) -> None:
6161
"""Run 'rm -rf path' on remote.
6262
63-
:param path: path to remove
63+
:param path: Path to remove.
6464
:type path: str | pathlib.PurePath
6565
"""
6666
# noinspection PyTypeChecker
@@ -69,9 +69,9 @@ def rm_rf(self, path: SupportPathT) -> None:
6969
def upload(self, source: SupportPathT, target: SupportPathT) -> None:
7070
"""Upload file(s) from source to target using SFTP session.
7171
72-
:param source: local path
72+
:param source: Local path.
7373
:type source: str | pathlib.PurePath
74-
:param target: remote path
74+
:param target: Remote path.
7575
:type target: str | pathlib.PurePath
7676
"""
7777
self.logger.debug(f"Copying '{source}' -> '{target}'")
@@ -101,11 +101,11 @@ def upload(self, source: SupportPathT, target: SupportPathT) -> None:
101101
def download(self, destination: SupportPathT, target: SupportPathT) -> bool:
102102
"""Download file(s) to target from destination.
103103
104-
:param destination: remote path
104+
:param destination: Remote path.
105105
:type destination: str | pathlib.PurePath
106-
:param target: local path
106+
:param target: Local path.
107107
:type target: str | pathlib.PurePath
108-
:return: downloaded file present on local filesystem
108+
:return: Downloaded file present on local filesystem.
109109
:rtype: bool
110110
"""
111111
self.logger.debug(f"Copying '{destination}' -> '{target}' from remote to local host")

‎exec_helpers/ssh_auth.py

+50-50
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@ def __init__(
5555
Single SSHAuth object is associated with single host:port.
5656
Password and key is private, other data is read-only.
5757
58-
:param username: remote username.
58+
:param username: Remote username.
5959
:type username: str | None
60-
:param password: remote password
60+
:param password: Remote password.
6161
:type password: str | None
62-
:param key: Main connection key
62+
:param key: Main connection key.
6363
:type key: paramiko.PKey | None
64-
:param keys: Alternate connection keys
64+
:param keys: Alternate connection keys.
6565
:type keys: Sequence[paramiko.PKey | None] | None
66-
:param key_filename: filename(s) for additional key files
66+
:param key_filename: Filename(s) for additional key files.
6767
:type key_filename: Iterable[str] | str | None
68-
:param passphrase: passphrase for keys. Need, if differs from password
68+
:param passphrase: Passphrase for keys. Need, if differs from password.
6969
:type passphrase: str | None
7070
7171
.. versionchanged:: 1.0.0
@@ -107,7 +107,7 @@ def __init__(
107107
def username(self) -> str | None:
108108
"""Username for auth.
109109
110-
:return: auth username
110+
:return: Auth username.
111111
:rtype: str
112112
"""
113113
return self.__username
@@ -116,9 +116,9 @@ def username(self) -> str | None:
116116
def __get_public_key(key: paramiko.PKey | None) -> str | None:
117117
"""Internal method for get public key from private.
118118
119-
:param key: SSH private key
119+
:param key: SSH private key.
120120
:type key: paramiko.PKey
121-
:return: public key text if applicable
121+
:return: Public key text if applicable.
122122
:rtype: str | None
123123
"""
124124
if key is None:
@@ -127,9 +127,9 @@ def __get_public_key(key: paramiko.PKey | None) -> str | None:
127127

128128
@property
129129
def public_key(self) -> str | None:
130-
"""Public key for stored private key if presents else None.
130+
"""Public key for the stored private key if presents else None.
131131
132-
:return: public key for current private key
132+
:return: Public key for the current private key.
133133
:rtype: str
134134
"""
135135
return self.__get_public_key(self.__keys[self.__key_index])
@@ -138,7 +138,7 @@ def public_key(self) -> str | None:
138138
def key_filename(self) -> Collection[str]:
139139
"""Key filename(s).
140140
141-
:return: copy of used key filename (original should not be changed via mutability).
141+
:return: Copy of used key filename (original should not be changed via mutability).
142142
.. versionadded:: 1.0.0
143143
.. versionchanged:: 7.0.5 changed type relying on paramiko sources
144144
"""
@@ -149,7 +149,7 @@ def enter_password(self, tgt: typing.BinaryIO) -> None:
149149
150150
Note: required for 'sudo' call
151151
152-
:param tgt: Target
152+
:param tgt: Target.
153153
:type tgt: typing.BinaryIO
154154
"""
155155
# noinspection PyTypeChecker
@@ -165,19 +165,19 @@ def connect(
165165
sock: paramiko.ProxyCommand | paramiko.Channel | socket.socket | None = None,
166166
allow_ssh_agent: bool = True,
167167
) -> None:
168-
"""Connect SSH client object using credentials.
168+
"""Connect the SSH client object using credentials.
169169
170-
:param client: SSH Client (low level)
170+
:param client: SSH Client (low level).
171171
:type client: paramiko.SSHClient
172-
:param hostname: remote hostname
172+
:param hostname: Remote hostname.
173173
:type hostname: str
174-
:param port: remote ssh port
174+
:param port: Remote ssh port.
175175
:type port: int
176-
:param log: Log on generic connection failure
176+
:param log: Log on generic connection failure.
177177
:type log: bool
178-
:param sock: socket for connection. Useful for ssh proxies support
178+
:param sock: Socket for connection. Useful for ssh proxies support.
179179
:type sock: paramiko.ProxyCommand | paramiko.Channel | socket.socket | None
180-
:param allow_ssh_agent: use SSH Agent if available
180+
:param allow_ssh_agent: Use SSH Agent if available.
181181
:type allow_ssh_agent: bool
182182
:raises PasswordRequiredException: No password has been set, but required.
183183
:raises AuthenticationException: Authentication failed.
@@ -223,7 +223,7 @@ def connect(
223223
def __hash__(self) -> int:
224224
"""Hash for usage as dict keys and comparison.
225225
226-
:return: hash value
226+
:return: Hash value.
227227
:rtype: int
228228
"""
229229
return hash(
@@ -240,29 +240,29 @@ def __hash__(self) -> int:
240240
def __eq__(self, other: object) -> bool:
241241
"""Comparison helper.
242242
243-
:param other: other SSHAuth instance
243+
:param other: Another SSHAuth instance.
244244
:type other: typing.Any
245-
:return: current object equals other
245+
:return: Current object equals other.
246246
:rtype: bool
247247
"""
248248
return hash(self) == hash(other)
249249

250250
def __ne__(self, other: object) -> bool:
251251
"""Comparison helper.
252252
253-
:param other: other SSHAuth instance
253+
:param other: Another SSHAuth instance.
254254
:type other: typing.Any
255-
:return: current object not equals other
255+
:return: Current object doesn't equal other.
256256
:rtype: bool
257257
"""
258258
return not self.__eq__(other)
259259

260260
def __deepcopy__(self, memo: typing.Any) -> SSHAuth:
261261
"""Helper for copy.deepcopy.
262262
263-
:param memo: copy.deepcopy() memodict
263+
:param memo: copy.deepcopy() memodict.
264264
:type memo: typing.Any
265-
:return: re-constructed copy of current class
265+
:return: Re-constructed copy of the current class.
266266
:rtype: SSHAuth
267267
"""
268268
# noinspection PyTypeChecker
@@ -278,7 +278,7 @@ def __deepcopy__(self, memo: typing.Any) -> SSHAuth:
278278
def __copy__(self) -> SSHAuth:
279279
"""Copy self.
280280
281-
:return: re-constructed copy of current class
281+
:return: Re-constructed copy of the current class.
282282
:rtype: SSHAuth
283283
"""
284284
# noinspection PyTypeChecker
@@ -294,7 +294,7 @@ def __copy__(self) -> SSHAuth:
294294
def __repr__(self) -> str:
295295
"""Representation for debug purposes.
296296
297-
:return: partial instance fields in human-friendly format
297+
:return: Partial instance fields in human-friendly format.
298298
:rtype: str
299299
"""
300300
if self.__keys[self.__key_index] is None:
@@ -322,16 +322,16 @@ def __repr__(self) -> str:
322322
def __str__(self) -> str:
323323
"""Representation for debug purposes.
324324
325-
:return: user name related to class instance
325+
:return: Username related to class instance.
326326
:rtype: str
327327
"""
328328
return f"{self.__class__.__name__} for {self.username}"
329329

330330

331331
class SSHAuthMapping(typing.Dict[str, SSHAuth]):
332-
"""Specific dictionary for ssh hostname - auth mapping.
332+
"""Specific dictionary for ssh hostname - auth mapping.
333333
334-
keys are always string and saved/collected lowercase.
334+
Keys are always string and saved/collected lowercase.
335335
"""
336336

337337
__slots__ = ()
@@ -341,13 +341,13 @@ def __init__(
341341
auth_dict: dict[str, SSHAuth] | SSHAuthMapping | None = None,
342342
**auth_mapping: SSHAuth,
343343
) -> None:
344-
"""Specific dictionary for ssh hostname - auth mapping.
344+
"""Specific dictionary for ssh hostname - auth mapping.
345345
346-
:param auth_dict: original hostname - source ssh auth mapping (dictionary of SSHAuthMapping)
346+
:param auth_dict: Original hostname - source ssh auth mapping (dictionary of SSHAuthMapping).
347347
:type auth_dict: dict[str, SSHAuth] | SSHAuthMapping | None
348-
:param auth_mapping: SSHAuth setting via **kwargs
348+
:param auth_mapping: SSHAuth setting via **kwargs.
349349
:type auth_mapping: SSHAuth
350-
:raises TypeError: Incorrect type of auth dict or auth object
350+
:raises TypeError: Incorrect type of auth dict or auth object.
351351
"""
352352
super().__init__()
353353
if auth_dict is not None:
@@ -366,11 +366,11 @@ def __init__(
366366
def __setitem__(self, hostname: str, auth: SSHAuth) -> None:
367367
"""Dict-like access.
368368
369-
:param hostname: key - hostname
369+
:param hostname: Key - hostname.
370370
:type hostname: str
371-
:param auth: value - SSHAuth object
371+
:param auth: value - SSHAuth object.
372372
:type auth: SSHAuth
373-
:raises TypeError: key is not string or value is not SSHAuth.
373+
:raises TypeError: Key is not string or value is not SSHAuth.
374374
"""
375375
if not isinstance(hostname, str): # pragma: no cover
376376
raise TypeError(f"Hostname should be string only! Got: {hostname!r}")
@@ -381,11 +381,11 @@ def __setitem__(self, hostname: str, auth: SSHAuth) -> None:
381381
def __getitem__(self, hostname: str) -> SSHAuth:
382382
"""Dict-like access.
383383
384-
:param hostname: key - hostname
384+
:param hostname: Key - hostname.
385385
:type hostname: str
386-
:return: associated SSHAuth object
386+
:return: Associated SSHAuth object.
387387
:rtype: SSHAuth
388-
:raises TypeError: key is not string.
388+
:raises TypeError: Key is not a string.
389389
"""
390390
if not isinstance(hostname, str): # pragma: no cover
391391
raise TypeError(f"Hostname should be string only! Got: {hostname!r}")
@@ -417,17 +417,17 @@ def get_with_alt_hostname(
417417
) -> SSHAuth | None:
418418
"""Try to guess hostname with credentials.
419419
420-
:param hostname: expected target hostname
420+
:param hostname: Expected target hostname.
421421
:type hostname: str
422-
:param host_names: alternate host names
422+
:param host_names: Alternate host names.
423423
:type host_names: str
424-
:param default: credentials if hostname not found
424+
:param default: Credentials if hostname not found.
425425
:type default: SSHAuth | None
426-
:return: guessed credentials
426+
:return: Guessed credentials.
427427
:rtype: SSHAuth | None
428-
:raises TypeError: Default SSH Auth object is not SSHAuth
428+
:raises TypeError: Default SSH Auth object is not SSHAuth.
429429
430-
Method used in cases, when 1 host share 2 or more names in config.
430+
Method used in cases when 1 host shares two or more names in config.
431431
"""
432432
if default is not None and not isinstance(default, SSHAuth): # pragma: no cover
433433
raise TypeError(f"Default SSH Auth object is not SSHAuth!. (got {default!r})")
@@ -441,9 +441,9 @@ def get_with_alt_hostname(
441441
def __delitem__(self, hostname: str) -> None:
442442
"""Dict-like access.
443443
444-
:param hostname: key - hostname
444+
:param hostname: Key - hostname.
445445
:type hostname: str
446-
:raises TypeError: key is not string.
446+
:raises TypeError: Key is not a string.
447447
"""
448448
if not isinstance(hostname, str): # pragma: no cover
449449
raise TypeError(f"Hostname should be string only! Got: {hostname!r}")

‎exec_helpers/subprocess.py

+110-110
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.