meltano.edk.process.Invoker#

class meltano.edk.process.Invoker#

Invoker utility class for invoking subprocesses.

__init__(bin: str, cwd: str | None = None, env: dict[str, Any] | None = None) None#

Minimal invoker for running subprocesses.

Parameters:
  • bin – The path/name of the binary to run.

  • cwd – The working directory to run from.

  • env – Env to use when calling Popen, defaults to current os.environ if None.

run(*args: str | bytes, stdout: None | int | IO = -1, stderr: None | int | IO = -1, text: bool = True, **kwargs: Any) CompletedProcess#

Run a subprocess. Simple wrapper around subprocess.run.

Note that output from stdout and stderr is NOT logged automatically. Especially useful when you want to run a command, but don’t care about its output and only care about its return code.

stdout and stderr by default are set up to use subprocess.PIPE. If you do not want to capture io from the subprocess use subprocess.DEVNULL to discard it.

The Invoker’s at env and cwd are used when calling subprocess.run. If you want to override these you’re likely better served using subprocess.run directly.

Lastly note that this method is blocking AND subprocess.run is called with check=True. This means that if the subprocess fails a CalledProcessError will be raised.

Parameters:
  • *args – The arguments to pass to the subprocess.

  • stdout – The stdout stream to use.

  • stderr – The stderr stream to use.

  • text – If true, decode stdin, stdout and stderr using the system default.

  • **kwargs – Additional keyword arguments to pass to subprocess.run.

Returns:

The completed process.

run_and_log(sub_command: str | None = None, *args: str | bytes) None#

Run a subprocess and stream the output to the logger.

Note that output from stdout and stderr IS logged. Best used when you want to run a command and stream the output to a user.

Parameters:
  • sub_command – The subcommand to run.

  • *args – The arguments to pass to the subprocess.

Raises:

CalledProcessError – If the subprocess failed.