Source

cy-cxxfwk / cython.py

##
## stdlib imports
import re

## waflib imports
import waflib
import waflib.Logs as _msg
from waflib.Task import Task
from waflib.TaskGen import extension, feature, before, after

re_cyt = re.compile('import\\s(\\w+)\\s*$', re.M)
def cy_scan(self):

    txt = self.inputs[0].read()
    mods = []
    for m in re_cyt.finditer(txt):
        mods.append(m.group(1))

    _msg.debug("modules: %r" % mods)
    incs = getattr(self.generator, 'cython_includes', [])
    incs = [self.generator.path.find_dir(x) for x in incs]
    incs.append(self.inputs[0].parent)

    found = []
    missing = []
    for x in mods:
        for y in incs:
            k = y.find_resource(x + '.pxd')
            if k:
                found.append(k)
                break
        else:
            missing.append(x)
    _msg.debug("==> cython defs: %r" % found)
    return (found, missing)

@extension('.pyx')
def decide_ext(self, node):
    if 'cxx' in self.features:
        self.env.append_unique('CYTHONFLAGS', '--cplus')
        return ['.cc']
    return ['.c']
    
waflib.TaskGen.declare_chain(
    name      = 'cython',
    rule      = '${CYTHON} ${CYTHONFLAGS} -o ${TGT} ${SRC}',
    color     = 'GREEN',
    ext_in    = '.pyx',
    ext_out   = ['.h'],
    scan      = cy_scan,
    reentrant = True,
    decider   = decide_ext,
)
    
def options(ctx):
    ctx.load('compiler_c')
    ctx.load('compiler_cxx')
    ctx.load('python')

    ctx.add_option('--cython-flags',
                   action='store',
                   default='',
                   help='space separated list of flags to pass to cython')
    
def configure(ctx):
    ctx.find_program('cython', var='CYTHON')
    
    if ctx.options.cython_flags:
        ctx.env.CYTHONFLAGS = ctx.options.cython_flags

    ctx.load('compiler_c')
    ctx.load('compiler_cxx')

    ctx.load('python')
    ctx.check_python_headers()

@feature('cython')
def feature_cython(self):
    return 
    
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.