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

Proposed by Colin Watson
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 Approve
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.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS.rst'
--- NEWS.rst 2020-04-14 11:29:16 +0000
+++ NEWS.rst 2020-04-17 01:53:49 +0000
@@ -2,6 +2,11 @@
2NEWS for launchpadlib2NEWS for launchpadlib
3=====================3=====================
44
51.10.12
6=======
7- Postpone keyring.errors import in the same way that we postpone importing
8 keyring itself.
9
51.10.11 (2020-04-14)101.10.11 (2020-04-14)
6====================11====================
7- Don't store credentials or open a browser window when running under sudo.12- Don't store credentials or open a browser window when running under sudo.
813
=== modified file 'src/launchpadlib/credentials.py'
--- src/launchpadlib/credentials.py 2020-04-13 20:40:37 +0000
+++ src/launchpadlib/credentials.py 2020-04-17 01:53:49 +0000
@@ -41,10 +41,6 @@
41from sys import stdin41from sys import stdin
42import time42import time
43try:43try:
44 from keyring.errors import NoKeyringError
45except ImportError:
46 NoKeyringError = RuntimeError
47try:
48 from urllib.parse import urlencode44 from urllib.parse import urlencode
49except ImportError:45except ImportError:
50 from urllib import urlencode46 from urllib import urlencode
@@ -381,6 +377,12 @@
381 if 'keyring' not in globals():377 if 'keyring' not in globals():
382 global keyring378 global keyring
383 import keyring379 import keyring
380 if 'NoKeyringError' not in globals():
381 global NoKeyringError
382 try:
383 from keyring.errors import NoKeyringError
384 except ImportError:
385 NoKeyringError = RuntimeError
384386
385 def do_save(self, credentials, unique_key):387 def do_save(self, credentials, unique_key):
386 """Store newly-authorized credentials in the keyring."""388 """Store newly-authorized credentials in the keyring."""
387389
=== modified file 'src/launchpadlib/testing/helpers.py'
--- src/launchpadlib/testing/helpers.py 2011-01-10 14:34:03 +0000
+++ src/launchpadlib/testing/helpers.py 2020-04-17 01:53:49 +0000
@@ -133,10 +133,12 @@
133 # The real keyring package should never be imported during tests.133 # The real keyring package should never be imported during tests.
134 assert_keyring_not_imported()134 assert_keyring_not_imported()
135 launchpadlib.credentials.keyring = fake135 launchpadlib.credentials.keyring = fake
136 launchpadlib.credentials.NoKeyringError = RuntimeError
136 try:137 try:
137 yield138 yield
138 finally:139 finally:
139 del launchpadlib.credentials.keyring140 del launchpadlib.credentials.keyring
141 del launchpadlib.credentials.NoKeyringError
140142
141143
142class FauxSocketModule:144class FauxSocketModule:

Subscribers

People subscribed via source and target branches