33import sys
44from functools import wraps
55from pathlib import Path
6- from typing import Callable
6+ from typing import Callable , Optional
77
88from tests .types import P , RawFilesDict , RequirementsBase , RequirementsDict
99
@@ -27,13 +27,29 @@ def _command_setup(venv_cli_path: Path, activate: bool = False) -> list[str]:
2727 return [* bash , full_command ]
2828
2929
30- def run_command (commands : str | list [str ], cwd : Path = Path .cwd (), activated : bool = False ) -> None :
30+ def run_command (
31+ commands : str | list [str ],
32+ cwd : Path = Path .cwd (),
33+ activated : bool = False ,
34+ command_input : Optional [str ] = None ,
35+ ) -> None :
36+ """Run a command in a subprocess, optionally activating the virtual environment first
37+
38+ Args:
39+ commands: The command(s) to run.
40+ cwd: The directory to run the command in. Defaults to the current working directory.
41+ activated: Whether to activate the virtual environment before running the command.
42+ command_input: The input to pass to the command. Defaults to None.
43+
44+ Raises:
45+ subprocess.CalledProcessError: If the command returns a non-zero exit code.
46+ """
3147 input_commands = [commands ] if isinstance (commands , str ) else commands
3248
3349 setup_commands = _command_setup (venv_cli_path = _venv_cli_path , activate = activated )
3450 all_commands = [* setup_commands [:- 1 ], setup_commands [- 1 ] + "; " .join (input_commands )]
3551
36- result = subprocess .run (all_commands , cwd = cwd )
52+ result = subprocess .run (all_commands , cwd = cwd , input = command_input , text = True )
3753 result .check_returncode ()
3854
3955
0 commit comments