Commits

Jason R. Coombs committed 9b40215

Refactored Cython/Pyrex optional build support to unify logic

Comments (0)

Files changed (1)

setuptools/extension.py

 from setuptools.dist import _get_unpatched
 _Extension = _get_unpatched(_Extension)
 
-try:
-    # testing Cython first as it is supposed to replace pyrex
-    from Cython.Distutils.build_ext import build_ext
-except ImportError:
-    try:
-        from Pyrex.Distutils.build_ext import build_ext
-    except:
-        have_pyrex = False
-    else:
-        has_pyrex = True
-
-    have_pyrex = False
-else:
-    have_pyrex = True
+# Prefer Cython to Pyrex
+pyrex_impls = 'Cython.Distutils.build_ext', 'Pyrex.Distutils.build_ext'
+for pyrex_impl in pyrex_impls:
+	try:
+		# from (pyrex_impl) import build_ext
+		build_ext = __import__(pyrex_impl, fromlist=['build_ext']).build_ext
+		break
+	except:
+		pass
+have_pyrex = 'build_ext' in globals()
 
 
 class Extension(_Extension):