Index: Doc/distutils/uploading.rst =================================================================== --- Doc/distutils/uploading.rst (révision 67338) +++ Doc/distutils/uploading.rst (copie de travail) @@ -22,7 +22,9 @@ The :command:`upload` command uses the username, password, and repository URL from the :file:`$HOME/.pypirc` file (see section :ref:`pypirc` for more on this -file). +file). If a :command:`register` command was previously called in the same command, +and if the password was entered in the prompt, :command:`upload` will reuse the +entered password. You can specify another PyPI server with the :option:`--repository=*url*` option:: Index: Lib/distutils/config.py =================================================================== --- Lib/distutils/config.py (révision 67338) +++ Lib/distutils/config.py (copie de travail) @@ -82,12 +82,12 @@ for server in _servers: current = {'server': server} current['username'] = config.get(server, 'username') - current['password'] = config.get(server, 'password') # optional params for key, default in (('repository', self.DEFAULT_REPOSITORY), - ('realm', self.DEFAULT_REALM)): + ('realm', self.DEFAULT_REALM), + ('password', None)): if config.has_option(server, key): current[key] = config.get(server, key) else: Index: Lib/distutils/tests/test_upload.py =================================================================== --- Lib/distutils/tests/test_upload.py (révision 67338) +++ Lib/distutils/tests/test_upload.py (copie de travail) @@ -9,6 +9,17 @@ from distutils.tests import support from distutils.tests.test_config import PYPIRC, PyPIRCCommandTestCase +PYPIRC_NOPASSWORD = """\ +[distutils] + +index-servers = + server1 + +[server1] +username:me +""" + + class uploadTestCase(PyPIRCCommandTestCase): def test_finalize_options(self): @@ -26,7 +37,24 @@ ('repository', 'http://pypi.python.org/pypi')): self.assertEquals(getattr(cmd, attr), waited) + def test_saved_password(self): + # file with no password + f = open(self.rc, 'w') + f.write(PYPIRC_NOPASSWORD) + f.close() + # make sure it passes + dist = Distribution() + cmd = upload(dist) + cmd.finalize_options() + self.assertEquals(cmd.password, None) + + # make sure we get it as well, if another command + # initialized it at the dist level + dist.password = 'xxx' + cmd = upload(dist) + cmd.finalize_options() + self.assertEquals(cmd.password, 'xxx') def test_suite(): return unittest.makeSuite(uploadTestCase) Index: Lib/distutils/tests/test_register.py =================================================================== --- Lib/distutils/tests/test_register.py (révision 0) +++ Lib/distutils/tests/test_register.py (révision 0) @@ -0,0 +1,55 @@ +"""Tests for distutils.command.register.""" +import sys +import os +import unittest + +from distutils.command.register import register +from distutils.core import Distribution + +from distutils.tests.test_config import PYPIRC, PyPIRCCommandTestCase + +PYPIRC_NOPASSWORD = """\ +[distutils] + +index-servers = + server1 + +[server1] +username:me +""" + +# patching the password prompt +import getpass +def _getpass(prompt): + return 'password' +getpass.getpass = _getpass + +# patch for the call to pypi +def _post_to_server(*args): + return 200, '' + +class registerTestCase(PyPIRCCommandTestCase): + + def test_password_not_in_file(self): + + f = open(self.rc, 'w') + f.write(PYPIRC_NOPASSWORD) + f.close() + + dist = Distribution() + cmd = register(dist) + cmd.post_to_server = _post_to_server + + cmd._set_config() + cmd.finalize_options() + cmd.send_metadata() + + # dist.password should be set + # therefore used afterwards by other commands + self.assertEquals(dist.password, 'password') + +def test_suite(): + return unittest.makeSuite(registerTestCase) + +if __name__ == "__main__": + unittest.main(defaultTest="test_suite") Index: Lib/distutils/command/register.py =================================================================== --- Lib/distutils/command/register.py (révision 67338) +++ Lib/distutils/command/register.py (copie de travail) @@ -170,16 +170,19 @@ print 'Server response (%s): %s' % (code, result) # possibly save the login - if not self.has_config and code == 200: - print 'I can store your PyPI login so future submissions will be faster.' - print '(the login will be stored in %s)' % self._get_rc_file() - choice = 'X' - while choice.lower() not in 'yn': - choice = raw_input('Save your login (y/N)?') - if not choice: - choice = 'n' - if choice.lower() == 'y': - self._store_pypirc(username, password) + if code == 200: + if self.has_config: + self.distribution.password = password + else: + print 'I can store your PyPI login so future submissions will be faster.' + print '(the login will be stored in %s)' % self._get_rc_file() + choice = 'X' + while choice.lower() not in 'yn': + choice = raw_input('Save your login (y/N)?') + if not choice: + choice = 'n' + if choice.lower() == 'y': + self._store_pypirc(username, password) elif choice == '2': data = {':action': 'user'} Index: Lib/distutils/command/upload.py =================================================================== --- Lib/distutils/command/upload.py (révision 67338) +++ Lib/distutils/command/upload.py (copie de travail) @@ -50,6 +50,9 @@ self.repository = config['repository'] self.realm = config['realm'] + if not self.password and self.distribution.password: + self.password = self.distribution.password + def run(self): if not self.distribution.dist_files: raise DistutilsOptionError("No dist file created in earlier command") Index: Lib/distutils/dist.py =================================================================== --- Lib/distutils/dist.py (révision 67338) +++ Lib/distutils/dist.py (copie de travail) @@ -206,6 +206,7 @@ self.extra_path = None self.scripts = None self.data_files = None + self.password = '' # And now initialize bookkeeping stuff that can't be supplied by # the caller at all. 'command_obj' maps command names to