OLD | NEW |
(Empty) | |
| 1 """ |
| 2 Tool to run Cython files (.pyx) into .c and .cpp. |
| 3 |
| 4 TODO: |
| 5 - Add support for dynamically selecting in-process Cython |
| 6 through CYTHONINPROCESS variable. |
| 7 - Have a CYTHONCPP option which turns on C++ in flags and |
| 8 changes output extension at the same time |
| 9 |
| 10 VARIABLES: |
| 11 - CYTHON - The path to the "cython" command line tool. |
| 12 - CYTHONFLAGS - Flags to pass to the "cython" command line tool. |
| 13 |
| 14 AUTHORS: |
| 15 - David Cournapeau |
| 16 - Dag Sverre Seljebotn |
| 17 |
| 18 """ |
| 19 import SCons |
| 20 from SCons.Builder import Builder |
| 21 from SCons.Action import Action |
| 22 |
| 23 #def cython_action(target, source, env): |
| 24 # print target, source, env |
| 25 # from Cython.Compiler.Main import compile as cython_compile |
| 26 # res = cython_compile(str(source[0])) |
| 27 |
| 28 cythonAction = Action("$CYTHONCOM") |
| 29 |
| 30 def create_builder(env): |
| 31 try: |
| 32 cython = env['BUILDERS']['Cython'] |
| 33 except KeyError: |
| 34 cython = SCons.Builder.Builder( |
| 35 action = cythonAction, |
| 36 emitter = {}, |
| 37 suffix = cython_suffix_emitter, |
| 38 single_source = 1) |
| 39 env['BUILDERS']['Cython'] = cython |
| 40 |
| 41 return cython |
| 42 |
| 43 def cython_suffix_emitter(env, source): |
| 44 return "$CYTHONCFILESUFFIX" |
| 45 |
| 46 def generate(env): |
| 47 env["CYTHON"] = "cython" |
| 48 env["CYTHONCOM"] = "$CYTHON $CYTHONFLAGS -o $TARGET $SOURCE" |
| 49 env["CYTHONCFILESUFFIX"] = ".c" |
| 50 |
| 51 c_file, cxx_file = SCons.Tool.createCFileBuilders(env) |
| 52 |
| 53 c_file.suffix['.pyx'] = cython_suffix_emitter |
| 54 c_file.add_action('.pyx', cythonAction) |
| 55 |
| 56 c_file.suffix['.py'] = cython_suffix_emitter |
| 57 c_file.add_action('.py', cythonAction) |
| 58 |
| 59 create_builder(env) |
| 60 |
| 61 def exists(env): |
| 62 try: |
| 63 # import Cython |
| 64 return True |
| 65 except ImportError: |
| 66 return False |
OLD | NEW |