Skip to content

Commit

Permalink
Fix crashes when warnings would be produced by running Python
Browse files Browse the repository at this point in the history
  • Loading branch information
jleclanche committed Sep 30, 2022
1 parent 7222118 commit b4c08cb
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,13 @@ 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,
"-W",
"ignore",
"-",
input_=content,
stderr=subprocess.DEVNULL,
**kwargs,
)

def _run(self, cmd: list[str], **kwargs: Any) -> int | str:
Expand All @@ -1486,6 +1492,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:
Expand All @@ -1501,18 +1508,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_)
Expand Down

0 comments on commit b4c08cb

Please sign in to comment.