From 152f6ef002b760acaaaa0211e7a1af3ed014d825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 11 Aug 2020 16:26:54 +0200 Subject: [PATCH] Only ask for keyring password once This makes https://bugzilla.redhat.com/show_bug.cgi?id=1859476 much less painful. --- 8744.patch | 79 +++++++++++++++++++++++++++++++++++++++++++++++++ python-pip.spec | 9 +++++- 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 8744.patch diff --git a/8744.patch b/8744.patch new file mode 100644 index 0000000..1dfc974 --- /dev/null +++ b/8744.patch @@ -0,0 +1,79 @@ +From 23a2fef3919d773041f0c06e5f1a85471132098c Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= +Date: Mon, 3 Aug 2020 10:41:03 +0200 +Subject: [PATCH] When one keyring attempt fails, don't bother with more + +This makes https://github.com/pypa/pip/issues/8090 much less painful. +--- + news/8090.bugfix | 3 +++ + src/pip/_internal/network/auth.py | 2 ++ + tests/unit/test_networking_auth.py | 26 ++++++++++++++++++++++++++ + 3 files changed, 31 insertions(+) + create mode 100644 news/8090.bugfix + +diff --git a/news/8090.bugfix b/news/8090.bugfix +new file mode 100644 +index 0000000..e9f2b7c +--- /dev/null ++++ b/news/8090.bugfix +@@ -0,0 +1,3 @@ ++Only attempt to use the keyring once and if it fails, don't try again. ++This prevents spamming users with several keyring unlock prompts when they ++cannot unlock or don't want to do so. +diff --git a/src/pip/_internal/network/auth.py b/src/pip/_internal/network/auth.py +index 1e1da54..c101f93 100644 +--- a/src/pip/_internal/network/auth.py ++++ b/src/pip/_internal/network/auth.py +@@ -45,6 +45,7 @@ except Exception as exc: + + def get_keyring_auth(url, username): + """Return the tuple auth for a given url from keyring.""" ++ global keyring + if not url or not keyring: + return None + +@@ -70,6 +71,7 @@ def get_keyring_auth(url, username): + logger.warning( + "Keyring is skipped due to an exception: %s", str(exc), + ) ++ keyring = None + + + class MultiDomainBasicAuth(AuthBase): +diff --git a/tests/unit/test_networking_auth.py b/tests/unit/test_networking_auth.py +index 0f0b679..0fc5799 100644 +--- a/tests/unit/test_networking_auth.py ++++ b/tests/unit/test_networking_auth.py +@@ -222,3 +222,29 @@ def test_keyring_get_credential(monkeypatch, url, expect): + assert auth._get_new_credentials( + url, allow_netrc=False, allow_keyring=True + ) == expect ++ ++ ++class KeyringModuleBroken(object): ++ """Represents the current supported API of keyring, but broken""" ++ ++ def __init__(self): ++ self._call_count = 0 ++ ++ def get_credential(self, system, username): ++ self._call_count += 1 ++ raise Exception("This keyring is broken!") ++ ++ ++def test_broken_keyring_disables_keyring(monkeypatch): ++ keyring_broken = KeyringModuleBroken() ++ monkeypatch.setattr(pip._internal.network.auth, 'keyring', keyring_broken) ++ ++ auth = MultiDomainBasicAuth(index_urls=["http://example.com/"]) ++ ++ assert keyring_broken._call_count == 0 ++ for i in range(5): ++ url = "http://example.com/path" + str(i) ++ assert auth._get_new_credentials( ++ url, allow_netrc=False, allow_keyring=True ++ ) == (None, None) ++ assert keyring_broken._call_count == 1 +-- +2.26.2 + diff --git a/python-pip.spec b/python-pip.spec index ebac4e9..abbcb0b 100644 --- a/python-pip.spec +++ b/python-pip.spec @@ -16,7 +16,7 @@ Name: python-%{srcname} # When updating, update the bundled libraries versions bellow! # You can use vendor_meta.sh in the dist git repo Version: 19.3.1 -Release: 3%{?dist} +Release: 4%{?dist} Summary: A tool for installing and managing Python packages # We bundle a lot of libraries with pip, which itself is under MIT license. @@ -104,6 +104,9 @@ Patch6: callable-main.patch # Backported from https://github.com/pypa/pip/pull/7873 Patch7: 7873.patch +# Backported from https://github.com/pypa/pip/pull/8744 +Patch8: 8744.patch + # Downstream only patch # Users might have local installations of pip from using # `pip install --user --upgrade pip` on older/newer versions. @@ -261,6 +264,7 @@ popd %endif %patch6 -p1 %patch7 -p1 +%patch8 -p1 # this goes together with patch4 rm src/pip/_vendor/certifi/*.pem @@ -388,6 +392,9 @@ ln -sf %{buildroot}%{_bindir}/pip3 _bin/pip %{python_wheeldir}/%{python_wheelname} %changelog +* Tue Aug 11 2020 Miro Hrončok - 19.3.1-4 +- Only ask for keyring password once (#1859476) + * Fri Apr 10 2020 Miro Hrončok - 19.3.1-3 - Allow setting $TMPDIR to $PWD/... during pip wheel (#1806625)