Commits

tarek  committed a10ff67

the parse API needs to return distribute when setuptools is asked

  • Participants
  • Parent commits 295c6dd
  • Branches 0.6-maintenance

Comments (0)

Files changed (2)

File distribute_setup.py

     was_imported = 'pkg_resources' in sys.modules or \
         'setuptools' in sys.modules
     try:
-        import pkg_resources
-        if not hasattr(pkg_resources, '_distribute'):
-            fake_setuptools()
-            raise ImportError
-    except ImportError:
-        return _do_download(version, download_base, to_dir, download_delay)
-    try:
-        pkg_resources.require("distribute>="+version)
-        return
-    except pkg_resources.VersionConflict, e:
-        if was_imported:
-            print >>sys.stderr, (
-            "The required version of distribute (>=%s) is not available, and\n"
-            "can't be installed while this script is running. Please install\n"
-            " a more recent version first, using 'easy_install -U distribute'."
-            "\n\n(Currently using %r)") % (version, e.args[0])
-            sys.exit(2)
-        else:
-            del pkg_resources, sys.modules['pkg_resources']    # reload ok
+        try:
+            import pkg_resources
+            if not hasattr(pkg_resources, '_distribute'):
+                fake_setuptools()
+                raise ImportError
+        except ImportError:
             return _do_download(version, download_base, to_dir, download_delay)
-    except pkg_resources.DistributionNotFound:
-        return _do_download(version, download_base, to_dir, download_delay)
-
+        try:
+            pkg_resources.require("distribute>="+version)
+            return
+        except pkg_resources.VersionConflict, e:
+            if was_imported:
+                print >>sys.stderr, (
+                "The required version of distribute (>=%s) is not available,\n"
+                "and can't be installed while this script is running. Please\n"
+                "install a more recent version first, using\n"
+                "'easy_install -U distribute'."
+                "\n\n(Currently using %r)") % (version, e.args[0])
+                sys.exit(2)
+            else:
+                del pkg_resources, sys.modules['pkg_resources']    # reload ok
+                return _do_download(version, download_base, to_dir,
+                                    download_delay)
+        except pkg_resources.DistributionNotFound:
+            return _do_download(version, download_base, to_dir,
+                                download_delay)
+    finally:
+        _create_fake_setuptools_pkg_info(to_dir)
 
 def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
                         to_dir=os.curdir, delay=15):
 def _after_install(dist):
     log.warn('After install bootstrap.')
     placeholder = dist.get_command_obj('install').install_purelib
+    _create_fake_setuptools_pkg_info(placeholder)
+
+def _create_fake_setuptools_pkg_info(placeholder):
     if not placeholder or not os.path.exists(placeholder):
         log.warn('Could not find the install location')
         return

File pkg_resources.py

 
     #@staticmethod
     def parse(s):
+        # if asked for setuptools distribution
+        # and if distribute is installed, we want to give
+        # distribute instead
+        stripped_s = s.replace(' ', '')
+        stripped_s = stripped_s.strip()
+        if stripped_s in ('setuptools', 'setuptools==0.6c9',
+                          'setuptools>0.6c9', 'setuptools>=0.6c9'):
+            reqs = list(parse_requirements('distribute'))
+            if reqs:
+                if len(reqs)==1:
+                    # ok we can replace the requirement
+                    return reqs[0]
+
         reqs = list(parse_requirements(s))
         if reqs:
             if len(reqs)==1: