From 882b1f5695fdf46698cccd56a58b9a4796c1f0c9 Mon Sep 17 00:00:00 2001 From: Scott Gasch Date: Mon, 12 Jun 2023 16:35:20 -0700 Subject: [PATCH] Improve docstrings. --- src/pyutils/exec_utils.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/pyutils/exec_utils.py b/src/pyutils/exec_utils.py index 6fcd340..c235171 100644 --- a/src/pyutils/exec_utils.py +++ b/src/pyutils/exec_utils.py @@ -126,7 +126,6 @@ def cmd_exitcode(command: str, timeout_seconds: Optional[float] = None) -> int: def cmd(command: str, timeout_seconds: Optional[float] = None) -> str: """Run a command and capture its output to stdout and stderr into a string buffer. Return that string as this function's output. - Raises subprocess.CalledProcessError or TimeoutExpired on error. Args: command: the command to run @@ -136,6 +135,10 @@ def cmd(command: str, timeout_seconds: Optional[float] = None) -> str: Returns: The captured output of the subprocess' stdout as a string buffer + Raises: + CalledProcessError: the child process didn't exit cleanly + TimeoutExpired: the child process ran too long + >>> cmd('/bin/echo foo')[:-1] 'foo' @@ -234,7 +237,11 @@ def cmd_in_background(command: str, *, silent: bool = False) -> subprocess.Popen def cmd_list(command: List[str]) -> str: """Run a command with args encapsulated in a list and return the - output text as a string. Raises subprocess.CalledProcessError. + output text as a string. + + Raises: + CalledProcessError: the child process didn't exit cleanly + TimeoutExpired: the child process ran too long """ ret = subprocess.run(command, capture_output=True, check=True).stdout return ret.decode("utf-8") -- 2.46.0