Commits

Daniel Stutzbach  committed b36e896 Merge

Merged bugfixes from the danielstutzbach fork

  • Participants
  • Parent commits de6444e, a936c45
  • Branches 0.6-maintenance

Comments (0)

Files changed (5)

 * use_setuptools now properly respects the requested version
 * use_setuptools will no longer try to import a distribute egg for the
   wrong Python version
+* Issue 74: no_fake should be True by default.
+* Issue 72: avoid a bootstrapping issue with easy_install -U
 
 -----
 0.6.6

File distribute_setup.py

 
 
 def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
-                   to_dir=os.curdir, download_delay=15, no_fake=False):
+                   to_dir=os.curdir, download_delay=15, no_fake=True):
     # making sure we use the absolute path
     to_dir = os.path.abspath(to_dir)
     was_imported = 'pkg_resources' in sys.modules or \
             import pkg_resources
             if not hasattr(pkg_resources, '_distribute'):
                 if not no_fake:
-                    fake_setuptools()
+                    _fake_setuptools()
                 raise ImportError
         except ImportError:
             return _do_download(version, download_base, to_dir, download_delay)
             return _do_download(version, download_base, to_dir,
                                 download_delay)
     finally:
-        _create_fake_setuptools_pkg_info(to_dir)
+        if not no_fake:
+            _create_fake_setuptools_pkg_info(to_dir)
 
 def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
                         to_dir=os.curdir, delay=15):
 
 def _before_install():
     log.warn('Before install bootstrap.')
-    fake_setuptools()
+    _fake_setuptools()
 
 
 def _under_prefix(location):
     return True
 
 
-def fake_setuptools():
+def _fake_setuptools():
     log.warn('Scanning installed packages')
     try:
         import pkg_resources

File pkg_resources.py

     from sets import ImmutableSet as frozenset
 
 # capture these to bypass sandboxing
-from os import utime, rename, unlink, mkdir
+from os import utime
+try:
+    from os import mkdir, rename, unlink
+    WRITE_SUPPORT = True
+except ImportError:
+    # no write support, probably under GAE
+    WRITE_SUPPORT = False
+
 from os import open as os_open
 from os.path import isdir, split
 
 
 def _bypass_ensure_directory(name, mode=0777):
     # Sandbox-bypassing version of ensure_directory()
+    if not WRITE_SUPPORT:
+        raise IOError('"os.mkdir" not supported on this platform.')
     dirname, filename = split(name)
     if dirname and filename and not isdir(dirname):
         _bypass_ensure_directory(dirname)
         timestamp = time.mktime(date_time)
 
         try:
+            if not WRITE_SUPPORT:
+                raise IOError('"os.rename" and "os.unlink" are not supported '
+                              'on this platform')
+
             real_path = manager.get_cache_path(
                 self.egg_name, self._parts(zip_path)
             )
                     self.copy_file(srcfile, exe_target)
 
                 srcfile = os.path.abspath(srcfile)
+
+                # avoid a bootstrapping issue with easy_install -U (when the
+                # previous version doesn't have convert_2to3_doctests)
+                if not hasattr(self.distribution, 'convert_2to3_doctests'):
+                    return
+
                 if copied and srcfile in self.distribution.convert_2to3_doctests:
                     self.__doctests_2to3.append(outf)
 

File tests/test_distribute_setup.py

         distribute_setup.python_cmd = _faked
         _install(self.tarball)
 
+    def test_use_setuptools(self):
+        self.assertEquals(use_setuptools(), None)
+
+        # make sure fake_setuptools is not called by default
+        import pkg_resources
+        del pkg_resources._distribute
+        def fake_setuptools(*args):
+            raise AssertionError
+
+        pkg_resources._fake_setuptools = fake_setuptools
+        use_setuptools()
+
 if __name__ == '__main__':
     unittest.main()