From 911b8034ab22ee52272b8e67c84920007db89060 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sun, 8 Jun 2008 14:56:56 +0200 Subject: [PATCH] compile Cython.Plex.Scanners module on install to speed up compilation --- setup.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index ad65a14a..1d6cb486 100644 --- 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, -- 2.26.2