[Python-checkins] r60813 - sandbox/branches/setuptools-0.6/ez_setup.py sandbox/branches/setuptools-0.6/setuptools.txt

phillip.eby python-checkins at python.org
Thu Feb 14 20:47:52 CET 2008


Author: phillip.eby
Date: Thu Feb 14 20:47:51 2008
New Revision: 60813

Modified:
   sandbox/branches/setuptools-0.6/ez_setup.py
   sandbox/branches/setuptools-0.6/setuptools.txt
Log:
Allow ``ez_setup.use_setuptools()`` to upgrade existing setuptools
installations when called from a standalone ``setup.py``. (backport
from trunk)


Modified: sandbox/branches/setuptools-0.6/ez_setup.py
==============================================================================
--- sandbox/branches/setuptools-0.6/ez_setup.py	(original)
+++ sandbox/branches/setuptools-0.6/ez_setup.py	Thu Feb 14 20:47:51 2008
@@ -77,31 +77,31 @@
     this routine will print a message to ``sys.stderr`` and raise SystemExit in
     an attempt to abort the calling script.
     """
-    try:
-        import setuptools
-        if setuptools.__version__ == '0.0.1':
-            print >>sys.stderr, (
-            "You have an obsolete version of setuptools installed.  Please\n"
-            "remove it from your system entirely before rerunning this script."
-            )
-            sys.exit(2)
-    except ImportError:
+    was_imported = 'pkg_resources' in sys.modules or 'setuptools' in sys.modules
+    def do_download():
         egg = download_setuptools(version, download_base, to_dir, download_delay)
         sys.path.insert(0, egg)
         import setuptools; setuptools.bootstrap_install_from = egg
-
-    import pkg_resources
     try:
-        pkg_resources.require("setuptools>="+version)
-
+        import pkg_resources
+    except ImportError:
+        return do_download()       
+    try:
+        pkg_resources.require("setuptools>="+version); return
     except pkg_resources.VersionConflict, e:
-        # XXX could we install in a subprocess here?
-        print >>sys.stderr, (
+        if was_imported:
+            print >>sys.stderr, (
             "The required version of setuptools (>=%s) is not available, and\n"
             "can't be installed while this script is running. Please install\n"
-            " a more recent version first.\n\n(Currently using %r)"
-        ) % (version, e.args[0])
-        sys.exit(2)
+            " a more recent version first, using 'easy_install -U setuptools'."
+            "\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()
+    except pkg_resources.DistributionNotFound:
+        return do_download()
 
 def download_setuptools(
     version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
@@ -150,9 +150,43 @@
             if dst: dst.close()
     return os.path.realpath(saveto)
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 def main(argv, version=DEFAULT_VERSION):
     """Install or upgrade setuptools and EasyInstall"""
-
     try:
         import setuptools
     except ImportError:
@@ -167,8 +201,11 @@
                 os.unlink(egg)
     else:
         if setuptools.__version__ == '0.0.1':
-            # tell the user to uninstall obsolete version
-            use_setuptools(version)
+            print >>sys.stderr, (
+            "You have an obsolete version of setuptools installed.  Please\n"
+            "remove it from your system entirely before rerunning this script."
+            )
+            sys.exit(2)
 
     req = "setuptools>="+version
     import pkg_resources
@@ -189,8 +226,6 @@
             print "Setuptools version",version,"or greater has been installed."
             print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)'
 
-
-
 def update_md5(filenames):
     """Update our built-in md5 registry"""
 

Modified: sandbox/branches/setuptools-0.6/setuptools.txt
==============================================================================
--- sandbox/branches/setuptools-0.6/setuptools.txt	(original)
+++ sandbox/branches/setuptools-0.6/setuptools.txt	Thu Feb 14 20:47:51 2008
@@ -2625,6 +2625,9 @@
 
  * Fixed not fetching eggs in ``install_requires`` when running tests.
 
+ * Allow ``ez_setup.use_setuptools()`` to upgrade existing setuptools
+   installations when called from a standalone ``setup.py``.
+
 0.6c7
  * Fixed ``distutils.filelist.findall()`` crashing on broken symlinks, and 
    ``egg_info`` command failing on new, uncommitted SVN directories.


More information about the Python-checkins mailing list