zfec: setup: copy in latest version of ez_setup.py, which works even if setuptools...
authorzooko <zooko@zooko.com>
Sat, 22 Dec 2007 04:38:42 +0000 (10:08 +0530)
committerzooko <zooko@zooko.com>
Sat, 22 Dec 2007 04:38:42 +0000 (10:08 +0530)
darcs-hash:e840d057bcf9a3e24b36f63d4642ce5de735317b

zfec/ez_setup.py

index de9a8a001c003abcbe501657fa6f0b530e15ca68..6dd60f947f08f1f72748d404668ba740776ef74d 100755 (executable)
@@ -68,10 +68,33 @@ def parse_version(s):
 def setuptools_is_new_enough(required_version):
     """Return True if setuptools is already installed and has a version
     number >= required_version."""
-    (cin, cout, cerr,) = os.popen3("%s -c \"import os,sys; sys.path.extend([x for x in os.listdir('.') if x.endswith('.egg')] ; import setuptools;print setuptools.__version__\"" % (sys.executable,))
-    verstr = cout.read().strip()
-    ver = parse_version(verstr)
-    return ver and ver >= parse_version(required_version)
+    if 'pkg_resources' in sys.modules:
+        import pkg_resources
+        try:
+            pkg_resources.require('setuptools >= %s' % (required_version,))
+        except pkg_resources.VersionConflict:
+            # An insufficiently new version is installed.
+            return False
+        else:
+            return True
+    else:
+        try:
+            import pkg_resources
+        except ImportError:
+            # Okay it is not installed.
+            return False
+        else:
+            try:
+                pkg_resources.require('setuptools >= %s' % (required_version,))
+            except pkg_resources.VersionConflict:
+                # An insufficiently new version is installed.
+                pkg_resources.__dict__.clear() # "If you want to be absolutely sure... before deleting it." --said PJE on IRC
+                del sys.modules['pkg_resources']
+                return False
+            else:
+                pkg_resources.__dict__.clear() # "If you want to be absolutely sure... before deleting it." --said PJE on IRC
+                del sys.modules['pkg_resources']
+                return True
 
 def use_setuptools(
     version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,