runutil

Running external tools.

This module implements utilities for running external tools as subprocesses: * Redirecting stdin / stdout / stderr * Piping data between multiple subprocesses * Quoting parameters

class runutil.PipeProcessInfo(arguments: List[str], cwd: str | None = None, env: Dict[str, str] = None, check_returncode: bool = True)

Process information to be used in a pipeline

runutil.get_mpi_ntask_default() int

Get the number of MPI tasks to use if not specified.

runutil.inherit_env(custom: Dict[str, str]) Dict[str, str]

Utility to inherit the current plus custom environment variables.

runutil.is_mpi_installed() bool

Is MPI installed?

runutil.quote_for_cmd_exe(argument: str, force: bool = False) str

Quote a string for passing as a command line argument to a sub-process via cmd.exe. In addition to the normal quoting, we need to escape cmd.exe metacharacters. See https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/ See https://msdn.microsoft.com/en-us/library/17w5ykft(v=vs.85).aspx

runutil.quote_for_subprocess(argument: str, force: bool = False) str

Quote a string for passing as a command line argument to a sub-process directly. The string could be a path with spaces, or already contain quotes that need to be preserved. See https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/ See https://msdn.microsoft.com/en-us/library/17w5ykft(v=vs.85).aspx force: Quote the argument even if it does not contain any characters that would ordinarily require quoting.

runutil.quote_naively(s: str) str

Quote naively by wrapping the string in double quotes.

runutil.run(name: str, arguments: List[str], *, input: str | None = None, cwd: str | None = None, env: Dict[str, str] = None, encoding: str | None = None, check_returncode: bool = True, pipe: bool = True, hideWindow: bool = True) CompletedProcess

Run an external tool as a subprocess.

runutil.run_mpi(name: str, arguments: List[str], ntasks: int = None, **kwargs) CompletedProcess

Run an MS MPI subprocess.

runutil.run_pipe(name: str, pipe: List[PipeProcessInfo], input_filename: str = None, output_filename: str = None) List[CompletedProcess]

Run subprocesses and pipe data optionally from an input file to an output file.

runutil.run_reconstruction(arguments: List[str], **kwargs) CompletedProcess

Run uct_reconstruction.exe as a subprocess.

runutil.run_rscript(arguments: List[str], **kwargs) CompletedProcess

Run Rscript.exe as a subprocess.

runutil.startupinfo(hideWindow: bool = True) STARTUPINFO

Utility to start a process with a hidden window.