compile Cython.Plex.Scanners module on install to speed up compilation
authorStefan Behnel <scoder@users.berlios.de>
Sun, 8 Jun 2008 12:56:56 +0000 (14:56 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Sun, 8 Jun 2008 12:56:56 +0000 (14:56 +0200)
setup.py

index ad65a14a575691e0b603479fd578b7230ba0a285..1d6cb486aa3825c517ffae618b85229c4550f84e 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,6 @@
-from distutils.core import setup
+from distutils.core import setup, Extension
 from distutils.sysconfig import get_python_lib
-import os, sys
+import os, os.path
 import sys
 from Cython.Compiler.Version import version
 
@@ -22,6 +22,31 @@ if os.name == "posix":
 else:
     scripts = ["cython.py"]
 
+try:
+    sys.argv.remove("--no-compile")
+except ValueError:
+    try:
+        from Cython.Compiler.Main import compile
+        source_root = os.path.dirname(__file__)
+        compiled_modules = ["Cython.Plex.Scanners"]
+        extensions = []
+        for module in compiled_modules:
+            source_file = os.path.join(source_root, *module.split('.'))
+            print("Compiling module %s ..." % module)
+            result = compile(source_file + ".py")
+            if result.c_file:
+                extensions.append(
+                    Extension(module, sources = [result.c_file])
+                    )
+            else:
+                print("Compilation failed")
+        if extensions:
+            setup_args['ext_modules'] = extensions
+    except Exception:
+        print("ERROR: %s" % sys.exc_info()[1])
+        print("Extension module compilation failed, using plain Python implementation")
+
+
 setup(
   name = 'Cython', 
   version = version,