From 6c9c3c7e4d53394149c82637f18c0e55d4baca65 Mon Sep 17 00:00:00 2001 From: Brooks Kindle Date: Sat, 23 Apr 2016 11:01:39 -0700 Subject: 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. --- setuptools/command/upload.py | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'setuptools/command/upload.py') 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 -- cgit v1.2.1