Debian Codegraph @

scripts/utils.py

raw symbols SCIP
1 import os
2 import shlex
3 import subprocess
4 import sys
5 from typing import Sequence, Union
6
7
8 def run(args: Union[str, Sequence[str]]):
9 """
10 Run a program.
11
12 args may be a string, or list of argument strings.
13
14 If the program is "python3", this is replaced with the
15 full path to the current python executable.
16 """
17
18 # convert string to list
19 # so that we don't need to pass shell=True to subprocess.run()
20 # because turning on shell can mess things up (i.e. clang-format hangs forever for some reason)
21 if isinstance(args, str):
22 args = shlex.split(args)
23
24 # ensure proper python executable is used
25 if args[0] == 'python3':
26 args[0] = sys.executable
27
28 # run
29 print(f'+ {subprocess.list2cmdline(args)}')
30 result = subprocess.run(args)
31 if result.returncode != 0:
32 sys.exit('FAILED')
33
34
35 def chdir_project_root():
36 root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
37 os.chdir(root)