Commit 6c9c3c7e authored by Brooks Kindle's avatar Brooks Kindle

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.
parent 5cc432e3
...@@ -3,13 +3,18 @@ from distutils.command import upload as orig ...@@ -3,13 +3,18 @@ from distutils.command import upload as orig
class upload(orig.upload): class upload(orig.upload):
""" """
Override default upload behavior to look up password Override default upload behavior to obtain password
in the keyring if available. in a variety of different ways.
""" """
def finalize_options(self): def finalize_options(self):
orig.upload.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): def _load_password_from_keyring(self):
""" """
...@@ -17,7 +22,22 @@ class upload(orig.upload): ...@@ -17,7 +22,22 @@ class upload(orig.upload):
""" """
try: try:
keyring = __import__('keyring') keyring = __import__('keyring')
self.password = keyring.get_password(self.repository, password = keyring.get_password(self.repository, self.username)
self.username)
except Exception: 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment