potiuk commented on a change in pull request #21145:
URL: https://github.com/apache/airflow/pull/21145#discussion_r808909739
##########
File path: dev/breeze/src/airflow_breeze/utils/run_utils.py
##########
@@ -40,12 +41,22 @@ def run_command(
verbose: bool = False,
suppress_raise_exception: bool = False,
suppress_console_print: bool = False,
+ env: Optional[Mapping[str, str]] = None,
**kwargs,
):
if verbose:
- console.print(f"[blue]$ {' '.join(shlex.quote(c) for c in cmd)}")
+ command_to_print = ' '.join(shlex.quote(c) for c in cmd)
+ # if we pass environment variables to execute, then
+ env_to_print = ' '.join(f'{key}="{val}"' for (key, val) in
env.items()) if env else ''
+ # Soft wrap allows to copy&paste and run resulting output as it has no
hard EOL
+ console.print(f"[blue]{env_to_print} {command_to_print}[/]",
soft_wrap=True)
try:
- return subprocess.run(cmd, check=check, **kwargs)
+ # copy existing environment variables
+ cmd_env = deepcopy(os.environ)
Review comment:
This is also needed here because we need to "add" our environment
variables to the existing ones. When you pass "env" to "subprocess.run" - the
env passed will replace the current ones (and for example PATH will be missing,
so "docker-compose" command will not be found. By cloning the os.environ first
and updating the clone with the new env variables, I make sure that the old
variables remain and the new ones are added.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]