Run a PIO command with automatic process tracking. This is a drop-in replacement for subprocess.run() that tracks the process and ensures it's killed on program exit if still running. Args: args: Command to execute cwd: Working directory env: Environment variabl
(
args: list[str],
cwd: str | None = None,
env: dict[str, str] | None = None,
shell: bool = False,
capture_output: bool = False,
text: bool = True,
check: bool = False,
timeout: float | None = None,
)
| 411 | |
| 412 | |
| 413 | def run_pio_tracked( |
| 414 | args: list[str], |
| 415 | cwd: str | None = None, |
| 416 | env: dict[str, str] | None = None, |
| 417 | shell: bool = False, |
| 418 | capture_output: bool = False, |
| 419 | text: bool = True, |
| 420 | check: bool = False, |
| 421 | timeout: float | None = None, |
| 422 | ) -> subprocess.CompletedProcess[Any]: |
| 423 | """Run a PIO command with automatic process tracking. |
| 424 | |
| 425 | This is a drop-in replacement for subprocess.run() that tracks the process |
| 426 | and ensures it's killed on program exit if still running. |
| 427 | |
| 428 | Args: |
| 429 | args: Command to execute |
| 430 | cwd: Working directory |
| 431 | env: Environment variables |
| 432 | shell: Use shell execution |
| 433 | capture_output: Capture stdout/stderr |
| 434 | text: Text mode for I/O |
| 435 | check: Raise CalledProcessError on non-zero exit |
| 436 | timeout: Maximum time to wait in seconds |
| 437 | |
| 438 | Returns: |
| 439 | subprocess.CompletedProcess instance |
| 440 | """ |
| 441 | stdout_pipe = subprocess.PIPE if capture_output else None |
| 442 | stderr_pipe = subprocess.PIPE if capture_output else None |
| 443 | |
| 444 | with TrackedPopen( |
| 445 | args, |
| 446 | cwd=cwd, |
| 447 | env=env, |
| 448 | shell=shell, |
| 449 | stdout=stdout_pipe, |
| 450 | stderr=stderr_pipe, |
| 451 | text=text, |
| 452 | ) as tracked: |
| 453 | try: |
| 454 | stdout, stderr = tracked.communicate(timeout=timeout) |
| 455 | except subprocess.TimeoutExpired: |
| 456 | tracked.kill() |
| 457 | stdout, stderr = tracked.communicate() |
| 458 | raise subprocess.TimeoutExpired( |
| 459 | args, timeout or 0.0, output=stdout, stderr=stderr |
| 460 | ) |
| 461 | |
| 462 | retcode = tracked.returncode |
| 463 | |
| 464 | if check and retcode: |
| 465 | raise subprocess.CalledProcessError(retcode, args, output=stdout, stderr=stderr) |
| 466 | |
| 467 | return subprocess.CompletedProcess(args, retcode or 0, stdout, stderr) |
nothing calls this directly
no test coverage detected