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 authored and radoering committed Feb 13, 2023
1 parent e92de61 commit 897aebe
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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_)

Expand Down

0 comments on commit 897aebe

Please sign in to comment.