nix-direnv/tests/procs.py
2023-11-29 08:32:38 +01:00

28 lines
623 B
Python

import logging
import shlex
import subprocess
from pathlib import Path
from typing import IO, Any
_FILE = None | int | IO[Any]
_DIR = None | Path | str
log = logging.getLogger(__name__)
def run(
cmd: list[str],
text: bool = True,
check: bool = True,
cwd: _DIR = None,
stderr: _FILE = None,
stdout: _FILE = None,
env: dict[str, str] | None = None,
) -> subprocess.CompletedProcess:
if cwd is not None:
log.debug(f"cd {cwd}")
log.debug(f"$ {shlex.join(cmd)}")
return subprocess.run(
cmd, text=text, check=check, cwd=cwd, stderr=stderr, stdout=stdout, env=env
)