From 897aebe1f49d3f0250e90ff3add084140bb30d33 Mon Sep 17 00:00:00 2001 From: Jerome Leclanche Date: Fri, 30 Sep 2022 20:52:16 +0200 Subject: [PATCH] Fix crashes when warnings would be produced by running Python Fixes #6664 --- src/poetry/utils/env.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index ac4bc547c9e..408ce96a511 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -1503,7 +1503,14 @@ def run_pip(self, *args: str, **kwargs: Any) -> int | str: def run_python_script(self, content: str, **kwargs: Any) -> int | str: return self.run( - self._executable, "-I", "-W", "ignore", "-", input_=content, **kwargs + self._executable, + "-I", + "-W", + "ignore", + "-", + input_=content, + stderr=subprocess.PIPE, + **kwargs, ) def _run(self, cmd: list[str], **kwargs: Any) -> int | str: @@ -1513,23 +1520,22 @@ def _run(self, cmd: list[str], **kwargs: Any) -> int | str: call = kwargs.pop("call", False) input_ = kwargs.pop("input_", None) env = kwargs.pop("env", dict(os.environ)) + stderr = kwargs.pop("stderr", subprocess.STDOUT) try: if input_: output = subprocess.run( cmd, stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, + stderr=stderr, input=encode(input_), check=True, **kwargs, ).stdout elif call: - return subprocess.call(cmd, stderr=subprocess.STDOUT, env=env, **kwargs) + return subprocess.call(cmd, stderr=stderr, env=env, **kwargs) else: - output = subprocess.check_output( - cmd, stderr=subprocess.STDOUT, env=env, **kwargs - ) + output = subprocess.check_output(cmd, stderr=stderr, env=env, **kwargs) except CalledProcessError as e: raise EnvCommandError(e, input=input_)