Commits

guyroz  committed 1a1ab84

Issue #244 raises ValueError in upload and register commands if using a section without a repository value

  • Participants
  • Parent commits 7c60e9f

Comments (0)

Files changed (4)

File distribute.egg-info/entry_points.txt

 egg_info = setuptools.command.egg_info:egg_info
 register = setuptools.command.register:register
 upload_docs = setuptools.command.upload_docs:upload_docs
+upload = setuptools.command.upload:upload
 install_egg_info = setuptools.command.install_egg_info:install_egg_info
 alias = setuptools.command.alias:alias
 easy_install = setuptools.command.easy_install:easy_install
 
 [console_scripts]
 easy_install = setuptools.command.easy_install:main
-easy_install-2.6 = setuptools.command.easy_install:main
+easy_install-2.3 = setuptools.command.easy_install:main
 
 [setuptools.file_finders]
 svn_cvs = setuptools.command.sdist:_default_revctrl

File setuptools/command/__init__.py

 from setuptools.command import install_scripts
 import sys
 
-if sys.version>='2.5':
-    # In Python 2.5 and above, distutils includes its own upload command
-    __all__.remove('upload')
-
 from distutils.command.bdist import bdist
 
-
 if 'egg' not in bdist.format_commands:
     bdist.format_command['egg'] = ('bdist_egg', "Python .egg file")
     bdist.format_commands.append('egg')

File setuptools/command/register.py

 from distutils.command.register import register as _register
+from ConfigParser import ConfigParser
+import os
 
 class register(_register):
     __doc__ = _register.__doc__
     def run(self):
         # Make sure that we are using valid current name/version info
         self.run_command('egg_info')
+        self._section_name = self.repository
         _register.run(self)
 
+    def _read_pypirc(self):
+        """Reads the .pypirc file."""
+        rc = self._get_rc_file()
+        if os.path.exists(rc):
+            repository = self.repository
+            config = ConfigParser()
+            config.read(rc)
+            sections = config.sections()
+            if 'distutils' in sections:
+                # let's get the list of servers
+                index_servers = config.get('distutils', 'index-servers')
+                _servers = [server.strip() for server in
+                            index_servers.split('\n')
+                            if server.strip() != '']
+                if _servers == []:
+                    # nothing set, let's try to get the default pypi
+                    if 'pypi' in sections:
+                        _servers = ['pypi']
+                    else:
+                        # the file is not properly defined, returning
+                        # an empty dict
+                        return {}
+                for server in _servers:
+                    current = {'server': server}
+                    current['username'] = config.get(server, 'username')
+
+                    # optional params
+                    for key, default in (('repository',
+                                          None),
+                                         ('realm', self.DEFAULT_REALM),
+                                         ('password', None)):
+                        if config.has_option(server, key):
+                            current[key] = config.get(server, key)
+                        else:
+                            current[key] = default
+                    if (current['server'] == repository or
+                        current['repository'] == repository):
+                        return current
+            elif 'server-login' in sections:
+                # old format
+                server = 'server-login'
+                if config.has_option(server, 'repository'):
+                    repository = config.get(server, 'repository')
+                else:
+                    repository = None
+                return {'username': config.get(server, 'username'),
+                        'password': config.get(server, 'password'),
+                        'repository': repository,
+                        'server': server,
+                        'realm': self.DEFAULT_REALM}
+
+        return {}
+
+    def _set_config(self):
+        _register._set_config(self)
+        if self.repository is None:
+                raise ValueError('%s is missing a repository value in .pypirc' % self._section_name)

File setuptools/command/upload.py

 
 Implements the Distutils 'upload' subcommand (upload package to PyPI)."""
 
+
 from distutils.errors import *
 from distutils.core import Command
 from distutils.spawn import spawn
 except ImportError:
     from md5 import md5
 import os
+import sys
 import socket
 import platform
 import ConfigParser
 import urlparse
 import cStringIO as StringIO
 
-class upload(Command):
+class _upload(Command):
 
     description = "upload binary package to PyPI"
 
                 if not self.password:
                     self.password = config.get('server-login', 'password')
         if not self.repository:
-            self.repository = self.DEFAULT_REPOSITORY
+            raise ValueError('%s is missing a repository value in .pypirc' % self._section_name)
 
     def run(self):
         if not self.distribution.dist_files:
                           log.ERROR)
         if self.show_response:
             print '-'*75, r.read(), '-'*75
+
+if sys.version >= "2.5":
+    from distutils.command.upload import upload as distutils_upload
+    class upload(distutils_upload):
+
+        def run(self):
+            self._section_name = self.repository
+            distutils_upload.run(self)
+
+        def _read_pypirc(self):
+            """Reads the .pypirc file."""
+            self._section_name = self.repository
+            rc = self._get_rc_file()
+            if os.path.exists(rc):
+                repository = self.repository
+                config = ConfigParser.ConfigParser()
+                config.read(rc)
+                sections = config.sections()
+                if 'distutils' in sections:
+                    # let's get the list of servers
+                    index_servers = config.get('distutils', 'index-servers')
+                    _servers = [server.strip() for server in
+                                index_servers.split('\n')
+                                if server.strip() != '']
+                    if _servers == []:
+                        # nothing set, let's try to get the default pypi
+                        if 'pypi' in sections:
+                            _servers = ['pypi']
+                        else:
+                            # the file is not properly defined, returning
+                            # an empty dict
+                            return {}
+                    for server in _servers:
+                        current = {'server': server}
+                        current['username'] = config.get(server, 'username')
+
+                        # optional params
+                        for key, default in (('repository',
+                                              None),
+                                             ('realm', self.DEFAULT_REALM),
+                                             ('password', None)):
+                            if config.has_option(server, key):
+                                current[key] = config.get(server, key)
+                            else:
+                                current[key] = default
+                        if (current['server'] == repository or
+                            current['repository'] == repository):
+                            return current
+                elif 'server-login' in sections:
+                    # old format
+                    server = 'server-login'
+                    if config.has_option(server, 'repository'):
+                        repository = config.get(server, 'repository')
+                    else:
+                        repository = None
+                    return {'username': config.get(server, 'username'),
+                            'password': config.get(server, 'password'),
+                            'repository': repository,
+                            'server': server,
+                            'realm': self.DEFAULT_REALM}
+
+            return {}
+
+        def finalize_options(self):
+            distutils_upload.finalize_options(self)
+            if not self.repository:
+                raise ValueError('%s is missing a repository value in .pypirc' % self._section_name)
+
+
+else:
+    upload = _upload
+