(
cmd: str,
cwd: Optional[str] = None,
shell: bool = True,
check: bool = True,
capture: bool = True,
)
| 35 | |
| 36 | |
| 37 | def run( |
| 38 | cmd: str, |
| 39 | cwd: Optional[str] = None, |
| 40 | shell: bool = True, |
| 41 | check: bool = True, |
| 42 | capture: bool = True, |
| 43 | ) -> str: |
| 44 | print(f"Running: {cmd}") |
| 45 | result = subprocess.run( |
| 46 | cmd, shell=shell, cwd=cwd, check=False, capture_output=capture, text=False |
| 47 | ) |
| 48 | if capture: |
| 49 | stdout = result.stdout.decode("utf-8") if result.stdout else "" |
| 50 | stderr = result.stderr.decode("utf-8") if result.stderr else "" |
| 51 | else: |
| 52 | stdout = "" |
| 53 | stderr = "" |
| 54 | if result.returncode != 0: |
| 55 | msg = f"Command failed with exit code {result.returncode}:\nstdout:\n{stdout}\n\nstderr:\n{stderr}" |
| 56 | warnings.warn(msg) |
| 57 | if check: |
| 58 | raise subprocess.CalledProcessError( |
| 59 | result.returncode, cmd, output=result.stdout |
| 60 | ) |
| 61 | return stdout.strip() |
| 62 | |
| 63 | |
| 64 | def get_git_info() -> tuple[str, str]: |
no test coverage detected