File: utils.py

package info (click to toggle)
aws-crt-python 0.24.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 75,932 kB
  • sloc: ansic: 418,984; python: 23,626; makefile: 6,035; sh: 4,075; ruby: 208; java: 82; perl: 73; cpp: 25; xml: 11
file content (37 lines) | stat: -rw-r--r-- 971 bytes parent folder | download | duplicates (3)
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
32
33
34
35
36
37
import os
import shlex
import subprocess
import sys
from typing import Sequence, Union


def run(args: Union[str, Sequence[str]]):
    """
    Run a program.

    args may be a string, or list of argument strings.

    If the program is "python3", this is replaced with the
    full path to the current python executable.
    """

    # convert string to list
    # so that we don't need to pass shell=True to subprocess.run()
    # because turning on shell can mess things up (i.e. clang-format hangs forever for some reason)
    if isinstance(args, str):
        args = shlex.split(args)

    # ensure proper python executable is used
    if args[0] == 'python3':
        args[0] = sys.executable

    # run
    print(f'+ {subprocess.list2cmdline(args)}')
    result = subprocess.run(args)
    if result.returncode != 0:
        sys.exit('FAILED')


def chdir_project_root():
    root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
    os.chdir(root)