Skip to content

Commit d325245

Browse files
uranusjrDos Moonen
authored and
Dos Moonen
committed
Better subprocess handling
1 parent 0a9ff9d commit d325245

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/pip/_internal/network/auth.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,14 @@ def _set_password(self, service_name: str, username: str, password: str) -> None
138138
"""Mirror the implementation of keyring.set_password using cli"""
139139
if self.keyring is None:
140140
return None
141-
142-
cmd = [self.keyring, "set", service_name, username]
143-
input_ = (password + os.linesep).encode("utf-8")
144141
env = os.environ.copy()
145142
env["PYTHONIOENCODING"] = "utf-8"
146-
res = subprocess.run(cmd, input=input_, env=env)
147-
res.check_returncode()
143+
subprocess.run(
144+
[self.keyring, "set", service_name, username],
145+
input=f"{password}{os.linesep}".encode("utf-8"),
146+
env=env,
147+
check=True,
148+
)
148149
return None
149150

150151

tests/unit/test_network_auth.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,13 @@ def __call__(
406406
stdin: Optional[Any] = None,
407407
stdout: Optional[Any] = None,
408408
input: Optional[bytes] = None,
409+
check: Optional[bool] = None
409410
) -> Any:
410411
if cmd[1] == "get":
411412
assert stdin == -3 # subprocess.DEVNULL
412413
assert stdout == subprocess.PIPE
413414
assert env["PYTHONIOENCODING"] == "utf-8"
415+
assert check is None
414416

415417
password = self.get_password(*cmd[2:])
416418
if password is None:
@@ -426,6 +428,7 @@ def __call__(
426428
assert stdout is None
427429
assert env["PYTHONIOENCODING"] == "utf-8"
428430
assert input is not None
431+
assert check
429432

430433
# Input from stdin is encoded
431434
self.set_password(cmd[2], cmd[3], input.decode("utf-8").strip(os.linesep))

0 commit comments

Comments
 (0)