From 472d440ae3ceaab5f1ed45e66598d3a5e3e7d757 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 562c7751b14..505691d7fc2 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -1476,7 +1476,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.DEVNULL, + **kwargs, ) def _run(self, cmd: list[str], **kwargs: Any) -> int | str: @@ -1486,6 +1493,7 @@ 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 self._is_windows: @@ -1501,18 +1509,16 @@ def _run(self, cmd: list[str], **kwargs: Any) -> int | str: output = subprocess.run( command, stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, + stderr=stderr, input=encode(input_), check=True, **kwargs, ).stdout elif call: - return subprocess.call( - command, stderr=subprocess.STDOUT, env=env, **kwargs - ) + return subprocess.call(command, stderr=stderr, env=env, **kwargs) else: output = subprocess.check_output( - command, stderr=subprocess.STDOUT, env=env, **kwargs + command, stderr=stderr, env=env, **kwargs ) except CalledProcessError as e: raise EnvCommandError(e, input=input_)