Skip to content

Commit

Permalink
env: do not modify os.environ
Browse files Browse the repository at this point in the history
Replace updates of os.environ with explicit passing of `env` to
subprocess calls in `Env.execute()`.

Relates-to: python-poetry#3199
  • Loading branch information
abn committed Apr 28, 2021
1 parent 9a10e32 commit 1811374
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,7 @@ def _run(self, cmd: List[str], **kwargs: Any) -> Union[int, str]:
"""
call = kwargs.pop("call", False)
input_ = kwargs.pop("input_", None)
env = kwargs.pop("env", {k: v for k, v in os.environ.items()})

try:
if self._is_windows:
Expand All @@ -1263,10 +1264,10 @@ def _run(self, cmd: List[str], **kwargs: Any) -> Union[int, str]:
**kwargs,
).stdout
elif call:
return subprocess.call(cmd, stderr=subprocess.STDOUT, **kwargs)
return subprocess.call(cmd, stderr=subprocess.STDOUT, env=env, **kwargs)
else:
output = subprocess.check_output(
cmd, stderr=subprocess.STDOUT, **kwargs
cmd, stderr=subprocess.STDOUT, env=env, **kwargs
)
except CalledProcessError as e:
raise EnvCommandError(e, input=input_)
Expand Down

0 comments on commit 1811374

Please sign in to comment.