Merge lp:~cjwatson/launchpadlib/postpone-keyring-errors-import into lp:launchpadlib

Proposed by Colin Watson on 2020-04-17
Status: Merged
Merged at revision: 180
Proposed branch: lp:~cjwatson/launchpadlib/postpone-keyring-errors-import
Merge into: lp:launchpadlib
Diff against target: 60 lines (+13/-4)
3 files modified
NEWS.rst (+5/-0)
src/launchpadlib/credentials.py (+6/-4)
src/launchpadlib/testing/helpers.py (+2/-0)
To merge this branch: bzr merge lp:~cjwatson/launchpadlib/postpone-keyring-errors-import
Reviewer Review Type Date Requested Status
William Grant code 2020-04-17 Approve on 2020-04-17
Review via email: mp+382465@code.launchpad.net

Commit message

Postpone keyring.errors import.

Description of the change

We import the keyring module late because it does environment-dependent backend initialisation at import time, and we want to postpone this until we actually need it; importing it early can also cause test problems. We need to take the same care when importing keyring.errors.

I think this will fix failures on Ubuntu's autopkgtest runners (e.g. https://objectstorage.prodstack4-5.canonical.com/v1/AUTH_77e2ada1e7a84929a74ba3b87153c0ac/autopkgtest-focal/focal/amd64/p/python-launchpadlib/20200415_171509_0c21d@/log.gz).

To post a comment you must log in.
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS.rst'
2--- NEWS.rst 2020-04-14 11:29:16 +0000
3+++ NEWS.rst 2020-04-17 01:53:49 +0000
4@@ -2,6 +2,11 @@
5 NEWS for launchpadlib
6 =====================
7
8+1.10.12
9+=======
10+- Postpone keyring.errors import in the same way that we postpone importing
11+ keyring itself.
12+
13 1.10.11 (2020-04-14)
14 ====================
15 - Don't store credentials or open a browser window when running under sudo.
16
17=== modified file 'src/launchpadlib/credentials.py'
18--- src/launchpadlib/credentials.py 2020-04-13 20:40:37 +0000
19+++ src/launchpadlib/credentials.py 2020-04-17 01:53:49 +0000
20@@ -41,10 +41,6 @@
21 from sys import stdin
22 import time
23 try:
24- from keyring.errors import NoKeyringError
25-except ImportError:
26- NoKeyringError = RuntimeError
27-try:
28 from urllib.parse import urlencode
29 except ImportError:
30 from urllib import urlencode
31@@ -381,6 +377,12 @@
32 if 'keyring' not in globals():
33 global keyring
34 import keyring
35+ if 'NoKeyringError' not in globals():
36+ global NoKeyringError
37+ try:
38+ from keyring.errors import NoKeyringError
39+ except ImportError:
40+ NoKeyringError = RuntimeError
41
42 def do_save(self, credentials, unique_key):
43 """Store newly-authorized credentials in the keyring."""
44
45=== modified file 'src/launchpadlib/testing/helpers.py'
46--- src/launchpadlib/testing/helpers.py 2011-01-10 14:34:03 +0000
47+++ src/launchpadlib/testing/helpers.py 2020-04-17 01:53:49 +0000
48@@ -133,10 +133,12 @@
49 # The real keyring package should never be imported during tests.
50 assert_keyring_not_imported()
51 launchpadlib.credentials.keyring = fake
52+ launchpadlib.credentials.NoKeyringError = RuntimeError
53 try:
54 yield
55 finally:
56 del launchpadlib.credentials.keyring
57+ del launchpadlib.credentials.NoKeyringError
58
59
60 class FauxSocketModule:

Subscribers

People subscribed via source and target branches