[Numpy-discussion] Setuptools leftover junk

Fernando Perez fperez.net at gmail.com
Wed Jun 28 14:18:35 CDT 2006


On 6/28/06, David M. Cooke <cookedm at physics.mcmaster.ca> wrote:

> Done. I've also added a 'setupegg.py' module that wraps running 'setup.py'
> with an import of setuptools (it's based on the one used in matplotlib).
>
> easy_install still works, also.

You beat me to it :)

However, your patch has slightly different semantics from mine: if
bdist_egg fails to import, the rest of setuptools is still used.  I
don't know if that's safe.  My patch would consider /any/ failure in
the setuptools imports as a complete setuptools failure, and revert
out to basic distutils.

Let me know if you want me to put in my code instead, here's a patch
from my code against current svn (after your patch), in case you'd
like to try it out.

Cheers,

f



Index: core.py
===================================================================
--- core.py     (revision 2701)
+++ core.py     (working copy)
@@ -1,20 +1,30 @@
-
 import sys
 from distutils.core import *

-if 'setuptools' in sys.modules:
-    have_setuptools = True
-    from setuptools import setup as old_setup
-    # easy_install imports math, it may be picked up from cwd
-    from setuptools.command import develop, easy_install
+# Don't pull setuptools in unless the user explicitly requests by having it
+# imported (Andrew's trick).
+have_setuptools = 'setuptools' in sys.modules
+
+# Even if setuptools is in, do a few things carefully to make sure the version
+# is recent enough to have everything we need before assuming we can proceed
+# using setuptools throughout
+if have_setuptools:
     try:
-        # very old versions of setuptools don't have this
+        from setuptools import setup as old_setup
+        # very old setuptools don't have this
         from setuptools.command import bdist_egg
+        # easy_install imports math, it may be picked up from cwd
+        from setuptools.command import develop, easy_install
     except ImportError:
+        # Any failure here is probably due to an old or broken setuptools
+        # leftover in sys.modules, so treat it as if it simply weren't
+        # available.
         have_setuptools = False
-else:
+
+# If setuptools was flagged as unavailable due to import problems, we need the
+# basic distutils support
+if not have_setuptools:
     from distutils.core import setup as old_setup
-    have_setuptools = False

 from numpy.distutils.extension import Extension
 from numpy.distutils.command import config




More information about the Numpy-discussion mailing list