aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/command/upload.py
diff options
context:
space:
mode:
authorBrooks Kindle <brooks.kindle@wsu.edu>2016-04-23 11:01:39 -0700
committerBrooks Kindle <brooks.kindle@wsu.edu>2016-04-23 11:01:39 -0700
commit6c9c3c7e4d53394149c82637f18c0e55d4baca65 (patch)
tree96ca272968c1d7300519be1b49028a3f1fc5ec68 /setuptools/command/upload.py
parent5cc432e39c4e8689d117ccc9001d03e47ac5a902 (diff)
downloadexternal_python_setuptools-6c9c3c7e4d53394149c82637f18c0e55d4baca65.tar.gz
external_python_setuptools-6c9c3c7e4d53394149c82637f18c0e55d4baca65.tar.bz2
external_python_setuptools-6c9c3c7e4d53394149c82637f18c0e55d4baca65.zip
Prompt for password on upload.
The upload command wasn't prompting for a password. If there was no password specified in ~/.pypirc, the upload command, python setup.py sdist upload would fail and raise a TypeError. The workaround for this was to use python setup.py sdist register upload since the register command does prompt for a password. This commit ensures that the upload command prompts for a password if not given one by ~/.pypirc or the register command.
Diffstat (limited to 'setuptools/command/upload.py')
-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