aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2016-02-11 23:47:28 -0500
committerJason R. Coombs <jaraco@jaraco.com>2016-02-11 23:47:28 -0500
commit5367a7399762a9098ea689c7cdcb54fb9748dd66 (patch)
tree6bc8d62b0468c64e1811c7b24729018aaa45429e
parent0975916c1436759b5e373733561142caf708def4 (diff)
downloadexternal_python_setuptools-5367a7399762a9098ea689c7cdcb54fb9748dd66.tar.gz
external_python_setuptools-5367a7399762a9098ea689c7cdcb54fb9748dd66.tar.bz2
external_python_setuptools-5367a7399762a9098ea689c7cdcb54fb9748dd66.zip
Override upload command to load passwords from keyring when available and not otherwise specified.20.1
-rw-r--r--CHANGES.txt8
-rw-r--r--docs/setuptools.txt16
-rw-r--r--setuptools/command/__init__.py2
-rw-r--r--setuptools/command/upload.py23
4 files changed, 48 insertions, 1 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 9089b4b8..a7a70ab7 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,6 +2,14 @@
CHANGES
=======
+20.1
+----
+
+Added support for using passwords from keyring in the upload
+command. See `the upload docs
+<http://pythonhosted.org/setuptools/setuptools.html#upload-upload-source-and-or-egg-distributions-to-pypi>`_
+for details.
+
20.0
----
diff --git a/docs/setuptools.txt b/docs/setuptools.txt
index 064acd5f..610a0e61 100644
--- a/docs/setuptools.txt
+++ b/docs/setuptools.txt
@@ -2332,6 +2332,22 @@ The ``upload`` command is implemented and `documented
<https://docs.python.org/3.1/distutils/uploading.html>`_
in distutils.
+Setuptools augments the ``upload`` command with support
+for `keyring <https://pypi.python.org/pypi/keyring>`_,
+allowing the password to be stored in a secure
+location and not in plaintext in the .pypirc file. To use
+keyring, first install keyring and set the password for
+the relevant repository, e.g.::
+
+ python -m keyring set <repository> <username>
+ Password for '<username>' in '<repository>': ********
+
+Then, in .pypirc, set the repository configuration as normal,
+but omit the password. Thereafter, uploads will use the
+password from the keyring.
+
+New in 20.1: Added keyring support.
+
.. _upload_docs:
``upload_docs`` - Upload package documentation to PyPI
diff --git a/setuptools/command/__init__.py b/setuptools/command/__init__.py
index f6dbc39c..3fb2f6df 100644
--- a/setuptools/command/__init__.py
+++ b/setuptools/command/__init__.py
@@ -2,7 +2,7 @@ __all__ = [
'alias', 'bdist_egg', 'bdist_rpm', 'build_ext', 'build_py', 'develop',
'easy_install', 'egg_info', 'install', 'install_lib', 'rotate', 'saveopts',
'sdist', 'setopt', 'test', 'install_egg_info', 'install_scripts',
- 'register', 'bdist_wininst', 'upload_docs',
+ 'register', 'bdist_wininst', 'upload_docs', 'upload',
]
from distutils.command.bdist import bdist
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