summaryrefslogtreecommitdiff
path: root/bitsandbytes
diff options
context:
space:
mode:
authorTitus von Koeller <titus@vonkoeller.com>2022-08-01 09:30:29 -0700
committerTitus von Koeller <titus@vonkoeller.com>2022-08-01 09:30:29 -0700
commit3fd06fb6206f46b6d18fbb8a512da63832dea98b (patch)
tree508f4a024c1101674d445ce64d18bcb79f5232d1 /bitsandbytes
parent54efd874a8b180baa132cde118d963eca98e0d87 (diff)
refactored subshell execution code for greater readability and moved it to utils
Diffstat (limited to 'bitsandbytes')
-rw-r--r--bitsandbytes/cuda_setup.py11
-rw-r--r--bitsandbytes/utils.py22
2 files changed, 22 insertions, 11 deletions
diff --git a/bitsandbytes/cuda_setup.py b/bitsandbytes/cuda_setup.py
index 0dd53c5..8cc2c03 100644
--- a/bitsandbytes/cuda_setup.py
+++ b/bitsandbytes/cuda_setup.py
@@ -19,8 +19,6 @@ evaluation:
"""
import ctypes
-import shlex
-import subprocess
from os import environ as env
from pathlib import Path
from typing import Set, Union
@@ -28,15 +26,6 @@ from typing import Set, Union
from .utils import print_err, warn_of_missing_prerequisite
-def execute_and_return(strCMD):
- proc = subprocess.Popen(
- shlex.split(strCMD), stdout=subprocess.PIPE, stderr=subprocess.PIPE
- )
- out, err = proc.communicate()
- out, err = out.decode("UTF-8").strip(), err.decode("UTF-8").strip()
- return out, err
-
-
def check_cuda_result(cuda, result_val):
if result_val != 0:
cuda.cuGetErrorString(result_val, ctypes.byref(error_str))
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)