-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.py
More file actions
28 lines (20 loc) · 944 Bytes
/
util.py
File metadata and controls
28 lines (20 loc) · 944 Bytes
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
import os
import shlex
import shutil
import subprocess
from typing import List
from .logging import get_logger
logger = get_logger("util")
def run_command(command: List[str | os.PathLike], **kwargs):
# a small but valuable improvement for the log message: let's just resolve the path to the command we try to run
# beforehand
actual_command = shutil.which(command[0])
# commands which do not exist (or whose path does not exist) will yield an empty string, so we just replace the
# command if which() provided us with some output
if actual_command:
command[0] = actual_command
logger.info(f"running command {shlex.join(map(str, command))}")
# this is for people who know how Python renders lists
# it allows the user to introspect the types of the parameters passed to this function
logger.debug(f"command args: {repr(list(command))}")
return subprocess.check_call(command, **kwargs)