setup.py: fallback to .c if we don't have Cython
authorTero Marttila <terom@fixme.fi>
Tue, 26 Jan 2010 20:49:05 +0200
changeset 117 2da34e3aa885
parent 116 6841b56e128b
child 118 dc77a9f66f59
setup.py: fallback to .c if we don't have Cython
setup.py
--- a/setup.py	Tue Jan 26 20:42:55 2010 +0200
+++ b/setup.py	Tue Jan 26 20:49:05 2010 +0200
@@ -1,12 +1,37 @@
 from distutils.core import setup
 from distutils.extension import Extension
-from Cython.Distutils import build_ext
+
+import os.path
+
+build_root = os.path.abspath(os.path.dirname(__file__))
+
+pypngtile_c = "python/pypngtile.c"
+pypngtile_name = "python/pypngtile.pyx"
+
+cmdclass = dict()
+
+try :
+    from Cython.Distutils import build_ext
+    
+    cmdclass['build_ext'] = build_ext
+
+except ImportError :
+    path = os.path.join(build_root, pypngtile_c)
+
+    if os.path.exists(path) :
+        print "Warning: falling back from .pyx -> .c due to missing Cython"
+        # just use the .c
+        pypngtile_name = pypngtile_c
+    
+    else :
+        # fail
+        raise
 
 setup(
     name = 'pngtiles',
-    cmdclass = {'build_ext': build_ext},
+    cmdclass = cmdclass,
     ext_modules = [
-        Extension("pypngtile", ["python/pypngtile.pyx"],
+        Extension("pypngtile", [pypngtile_name],
             include_dirs = ['include'],
             library_dirs = ['lib'],
             libraries = ['pngtile'],