From 1020573bb4e8bf4a8c4f21a9e4c56a94538ebc48 Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Wed, 30 Aug 2023 09:49:47 -0500 Subject: [PATCH] Allow additional Popen arguments through task.run This is a follow-up to b6c977a55b17d22c35ba94603c89f1c5e1ebe20c, which made the same change to subprocess.run, which this function calls. --- colcon_core/task/__init__.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/colcon_core/task/__init__.py b/colcon_core/task/__init__.py index e5c2b709..d2bed7f8 100644 --- a/colcon_core/task/__init__.py +++ b/colcon_core/task/__init__.py @@ -148,8 +148,7 @@ async def check_call( async def run( - context, cmd, *, cwd=None, env=None, shell=False, use_pty=None, - capture_output=None + context, cmd, *, use_pty=None, capture_output=None, **other_popen_kwargs ): """ Run the command described by cmd. @@ -159,10 +158,11 @@ async def run( All output to `stdout` and `stderr` is posted as `StdoutLine` and `StderrLine` events to the event queue. + See the documentation of `subprocess.Popen() + ` for + other parameters. + :param cmd: The command and its arguments - :param cwd: the working directory for the subprocess - :param env: a dictionary with environment variables - :param shell: whether to use the shell as the program to execute :param use_pty: whether to use a pseudo terminal :param capture_output: whether to store stdout and stderr :returns: the result of the completed process @@ -174,12 +174,16 @@ def stdout_callback(line): def stderr_callback(line): context.put_event_into_queue(StderrLine(line)) + cwd = other_popen_kwargs.get('cwd', None) + env = other_popen_kwargs.get('env', None) + shell = other_popen_kwargs.get('shell', False) + context.put_event_into_queue( Command(cmd, cwd=cwd, env=env, shell=shell)) completed = await colcon_core_subprocess_run( cmd, stdout_callback, stderr_callback, - cwd=cwd, env=env, shell=shell, use_pty=use_pty, - capture_output=capture_output) + use_pty=use_pty, capture_output=capture_output, + **other_popen_kwargs) context.put_event_into_queue( CommandEnded( cmd, cwd=cwd, env=env, shell=shell,