aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2016-04-24 23:17:11 -0500
committerJason R. Coombs <jaraco@jaraco.com>2016-04-24 23:17:11 -0500
commit3070dd76d114ac8491d208c138a27afefd26dd6d (patch)
treede1c2b1403ac5fe09ec6a2530c512739a4096626
parent89509b570ffeed71361942b5f13fb07b1e6abf6b (diff)
parent6c9c3c7e4d53394149c82637f18c0e55d4baca65 (diff)
downloadexternal_python_setuptools-3070dd76d114ac8491d208c138a27afefd26dd6d.tar.gz
external_python_setuptools-3070dd76d114ac8491d208c138a27afefd26dd6d.tar.bz2
external_python_setuptools-3070dd76d114ac8491d208c138a27afefd26dd6d.zip
Merge pull request #555 from brookskindle/dev_prompt_password
password prompt on upload command
-rw-r--r--setuptools/command/upload.py32
1 files changed, 26 insertions, 6 deletions
diff --git a/setuptools/command/upload.py b/setuptools/command/upload.py
index 08c20ba8..43c0b0d7 100644
--- a/setuptools/command/upload.py
+++ b/setuptools/command/upload.py
@@ -3,13 +3,18 @@ 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 +22,22 @@ class upload(orig.upload):
"""
try:
keyring = __import__('keyring')
- self.password = keyring.get_password(self.repository,
- self.username)
+ password = keyring.get_password(self.repository, self.username)
except Exception:
- pass
+ password = None
+ finally:
+ return password
+
+ def _prompt_for_password(self):
+ """
+ Prompt for a password on the tty. Suppress Exceptions.
+ """
+ password = None
+ try:
+ import getpass
+ while not password:
+ password = getpass.getpass()
+ except (Exception, KeyboardInterrupt):
+ password = None
+ finally:
+ return password