Skip to content

Commit 5137ce2

Browse files
committed
Use full keyring path
1 parent 43abcf0 commit 5137ce2

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/pip/_internal/network/auth.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,20 @@ class KeyRingCli:
4141
PATH.
4242
"""
4343

44-
@classmethod
45-
def get_password(cls, service_name: str, username: str) -> Optional[str]:
46-
cmd = ["keyring", "get", service_name, username]
44+
def __init__(self, keyring: str) -> None:
45+
self.keyring = keyring
46+
47+
def get_password(self, service_name: str, username: str) -> Optional[str]:
48+
cmd = [self.keyring, "get", service_name, username]
4749
res = subprocess.run(
4850
cmd, capture_output=True, env=dict(PYTHONIOENCODING="utf-8")
4951
)
5052
if res.returncode:
5153
return None
5254
return res.stdout.decode("utf-8").strip("\n")
5355

54-
@classmethod
55-
def set_password(cls, service_name: str, username: str, password: str) -> None:
56-
cmd = ["keyring", "set", service_name, username]
56+
def set_password(self, service_name: str, username: str, password: str) -> None:
57+
cmd = [self.keyring, "set", service_name, username]
5758
input_ = password.encode("utf-8") + b"\n"
5859
res = subprocess.run(cmd, input=input_, env=dict(PYTHONIOENCODING="utf-8"))
5960
res.check_returncode()
@@ -64,8 +65,9 @@ def set_password(cls, service_name: str, username: str, password: str) -> None:
6465
import keyring
6566
except ImportError:
6667
keyring = None # type: ignore[assignment]
67-
if shutil.which("keyring") is not None:
68-
keyring = KeyRingCli # type: ignore[assignment]
68+
keyring_path = shutil.which("keyring")
69+
if keyring_path is not None:
70+
keyring = KeyRingCli(keyring_path) # type: ignore[assignment]
6971
except Exception as exc:
7072
logger.warning(
7173
"Keyring is skipped due to an exception: %s",

0 commit comments

Comments
 (0)