From 5367a7399762a9098ea689c7cdcb54fb9748dd66 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 11 Feb 2016 23:47:28 -0500 Subject: Override upload command to load passwords from keyring when available and not otherwise specified. --- setuptools/command/upload.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 setuptools/command/upload.py (limited to 'setuptools/command/upload.py') diff --git a/setuptools/command/upload.py b/setuptools/command/upload.py new file mode 100644 index 00000000..08c20ba8 --- /dev/null +++ b/setuptools/command/upload.py @@ -0,0 +1,23 @@ +from distutils.command import upload as orig + + +class upload(orig.upload): + """ + Override default upload behavior to look up password + in the keyring if available. + """ + + def finalize_options(self): + orig.upload.finalize_options(self) + self.password or self._load_password_from_keyring() + + def _load_password_from_keyring(self): + """ + Attempt to load password from keyring. Suppress Exceptions. + """ + try: + keyring = __import__('keyring') + self.password = keyring.get_password(self.repository, + self.username) + except Exception: + pass -- cgit v1.2.1