[Numpy-discussion] Setuptools leftover junk
Fernando Perez
fperez.net at gmail.com
Wed Jun 28 15:11:36 EDT 2006
On 6/28/06, Robert Kern <robert.kern at gmail.com> wrote:
> numpy.distutils uses setuptools if it is importable in order to make sure that
> the two don't stomp on each other. It's probable that that test could probably
> be done with Andrew Straw's method:
>
> if 'setuptools' in sys.modules:
> have_setuptools = True
> from setuptools import setup as old_setup
> else:
> have_setuptools = False
> from distutils.core import setup as old_setup
>
> Tested patches welcome.
Well, tested as in 'I wrote a unittest for installation', no. But
tested as in 'I built numpy, scipy, matplotlib, and my f2py-using
code', yes. They all build/install fine, and no more *egg-info
directories are strewn around.
If this satisfies your 'tested patches', the code is:
Index: numpy/distutils/core.py
===================================================================
--- numpy/distutils/core.py (revision 2698)
+++ numpy/distutils/core.py (working copy)
@@ -1,16 +1,30 @@
-
import sys
from distutils.core import *
-try:
- 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
- have_setuptools = 1
-except ImportError:
+
+# 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:
+ 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
+
+# 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 = 0
from numpy.distutils.extension import Extension
from numpy.distutils.command import config
May I?
keeping-the-world-setuptools-free-one-script-at-a-time-ly yours,
f
More information about the NumPy-Discussion
mailing list