Skip to content

Commit 472d440

Browse files
committed
Fix crashes when warnings would be produced by running Python
Fixes #6664
1 parent 7222118 commit 472d440

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/poetry/utils/env.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,14 @@ def run_pip(self, *args: str, **kwargs: Any) -> int | str:
14761476

14771477
def run_python_script(self, content: str, **kwargs: Any) -> int | str:
14781478
return self.run(
1479-
self._executable, "-I", "-W", "ignore", "-", input_=content, **kwargs
1479+
self._executable,
1480+
"-I",
1481+
"-W",
1482+
"ignore",
1483+
"-",
1484+
input_=content,
1485+
stderr=subprocess.DEVNULL,
1486+
**kwargs,
14801487
)
14811488

14821489
def _run(self, cmd: list[str], **kwargs: Any) -> int | str:
@@ -1486,6 +1493,7 @@ def _run(self, cmd: list[str], **kwargs: Any) -> int | str:
14861493
call = kwargs.pop("call", False)
14871494
input_ = kwargs.pop("input_", None)
14881495
env = kwargs.pop("env", dict(os.environ))
1496+
stderr = kwargs.pop("stderr", subprocess.STDOUT)
14891497

14901498
try:
14911499
if self._is_windows:
@@ -1501,18 +1509,16 @@ def _run(self, cmd: list[str], **kwargs: Any) -> int | str:
15011509
output = subprocess.run(
15021510
command,
15031511
stdout=subprocess.PIPE,
1504-
stderr=subprocess.STDOUT,
1512+
stderr=stderr,
15051513
input=encode(input_),
15061514
check=True,
15071515
**kwargs,
15081516
).stdout
15091517
elif call:
1510-
return subprocess.call(
1511-
command, stderr=subprocess.STDOUT, env=env, **kwargs
1512-
)
1518+
return subprocess.call(command, stderr=stderr, env=env, **kwargs)
15131519
else:
15141520
output = subprocess.check_output(
1515-
command, stderr=subprocess.STDOUT, env=env, **kwargs
1521+
command, stderr=stderr, env=env, **kwargs
15161522
)
15171523
except CalledProcessError as e:
15181524
raise EnvCommandError(e, input=input_)

0 commit comments

Comments
 (0)