diff options
Diffstat (limited to 'setuptools/command/upload.py')
-rw-r--r-- | setuptools/command/upload.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/setuptools/command/upload.py b/setuptools/command/upload.py index 08c20ba8..484baa5a 100644 --- a/setuptools/command/upload.py +++ b/setuptools/command/upload.py @@ -1,15 +1,22 @@ +import getpass from distutils.command import upload as orig class upload(orig.upload): """ - Override default upload behavior to look up password - in the keyring if available. + Override default upload behavior to obtain password + in a variety of different ways. """ def finalize_options(self): orig.upload.finalize_options(self) - self.password or self._load_password_from_keyring() + # Attempt to obtain password. Short circuit evaluation at the first + # sign of success. + self.password = ( + self.password or + self._load_password_from_keyring() or + self._prompt_for_password() + ) def _load_password_from_keyring(self): """ @@ -17,7 +24,15 @@ class upload(orig.upload): """ try: keyring = __import__('keyring') - self.password = keyring.get_password(self.repository, - self.username) + return keyring.get_password(self.repository, self.username) except Exception: pass + + def _prompt_for_password(self): + """ + Prompt for a password on the tty. Suppress Exceptions. + """ + try: + return getpass.getpass() + except (Exception, KeyboardInterrupt): + pass |