summaryrefslogtreecommitdiff
path: root/bitsandbytes/utils.py
blob: 67974072b10e405928ee1bec5f66be8f7bde5c3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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)


def warn_of_missing_prerequisite(s: str) -> None:
    print_err("WARNING, missing pre-requisite: " + s)