From 3fd06fb6206f46b6d18fbb8a512da63832dea98b Mon Sep 17 00:00:00 2001 From: Titus von Koeller Date: Mon, 1 Aug 2022 09:30:29 -0700 Subject: refactored subshell execution code for greater readability and moved it to utils --- bitsandbytes/utils.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'bitsandbytes/utils.py') diff --git a/bitsandbytes/utils.py b/bitsandbytes/utils.py index 29b9c90..6797407 100644 --- a/bitsandbytes/utils.py +++ b/bitsandbytes/utils.py @@ -1,6 +1,28 @@ +import shlex +import subprocess import sys +def execute_and_return(command_string: str) -> Tuple[str, str]: + def _decode(subprocess_err_out_tuple): + return tuple( + to_decode.decode("UTF-8").strip() + for to_decode in subprocess_err_out_tuple + ) + + def execute_and_return_decoded_std_streams(command_string): + return _decode( + subprocess.Popen( + shlex.split(command_string), + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ).communicate() + ) + + std_out, std_err = execute_and_return_decoded_std_streams() + return std_out, std_err + + def print_err(s: str) -> None: print(s, file=sys.stderr) -- cgit v1.2.3