def simple_cythonize(src, destdir=None, cwd=None, logger=None,
                     full_module_name=None, only_update=False,
                     **cy_kwargs):
    """
    Generates a C file from a Cython source file.

    Parameters
    ----------
    src: path string
        path to Cython source
    destdir: path string (optional)
        Path to output directory (default: '.')
    cwd: path string (optional)
        Root of relative paths (default: '.')
    logger: logging.Logger
        info level used.
    full_module_name: string
        passed to cy_compile (default: None)
    only_update: bool
        Only cythonize if source is newer. default: False
    **cy_kwargs:
        second argument passed to cy_compile.
        Generates a .cpp file if cplus=True in cy_kwargs, else a .c file.
    """
    from Cython.Compiler.Main import (
        default_options, CompilationOptions
    )
    from Cython.Compiler.Main import compile as cy_compile

    assert src.lower().endswith('.pyx') or src.lower().endswith('.py')
    cwd = cwd or '.'
    destdir = destdir or '.'

    ext = '.cpp' if cy_kwargs.get('cplus', False) else '.c'
    c_name = os.path.splitext(os.path.basename(src))[0] + ext

    dstfile = os.path.join(destdir, c_name)

    if only_update:
        if not missing_or_other_newer(dstfile, src, cwd=cwd):
            msg = '{0} newer than {1}, did not re-cythonize.'.format(
                dstfile, src)
            if logger:
                logger.info(msg)
            else:
                print(msg)
            return dstfile

    if cwd:
        ori_dir = os.getcwd()
    else:
        ori_dir = '.'
    os.chdir(cwd)
    try:
        cy_options = CompilationOptions(default_options)
        cy_options.__dict__.update(cy_kwargs)
        if logger:
            logger.info("Cythonizing {0} to {1}".format(
                src, dstfile))
        cy_result = cy_compile([src], cy_options, full_module_name=full_module_name)
        if cy_result.num_errors > 0:
            raise ValueError("Cython compilation failed.")
        if os.path.abspath(os.path.dirname(
                src)) != os.path.abspath(destdir):
            if os.path.exists(dstfile):
                os.unlink(dstfile)
            shutil.move(os.path.join(os.path.dirname(src), c_name),
                        destdir)
    finally:
        os.chdir(ori_dir)
    return dstfile
def simple_cythonize ( src , destdir = None , cwd = None , logger = None , full_module_name = None , only_update = False , ** cy_kwargs ) : from Cython . Compiler . Main import ( default_options , CompilationOptions ) from Cython . Compiler . Main import compile as cy_compile assert src . lower ( ) . endswith ( '.pyx' ) or src . lower ( ) . endswith ( '.py' ) cwd = cwd or '.' destdir = destdir or '.' ext = '.cpp' if cy_kwargs . get ( 'cplus' , False ) else '.c' c_name = os . path . splitext ( os . path . basename ( src ) ) [ 0 ] + ext dstfile = os . path . join ( destdir , c_name ) if only_update : if not missing_or_other_newer ( dstfile , src , cwd = cwd ) : msg = '{0} newer than {1}, did not re-cythonize.' . format ( dstfile , src ) if logger : logger . info ( msg ) else : print ( msg ) return dstfile if cwd : ori_dir = os . getcwd ( ) else : ori_dir = '.' os . chdir ( cwd ) try : cy_options = CompilationOptions ( default_options ) cy_options . __dict__ . update ( cy_kwargs ) if logger : logger . info ( "Cythonizing {0} to {1}" . format ( src , dstfile ) ) cy_result = cy_compile ( [ src ] , cy_options , full_module_name = full_module_name ) if cy_result . num_errors > 0 : raise ValueError ( "Cython compilation failed." ) if os . path . abspath ( os . path . dirname ( src ) ) != os . path . abspath ( destdir ) : if os . path . exists ( dstfile ) : os . unlink ( dstfile ) shutil . move ( os . path . join ( os . path . dirname ( src ) , c_name ) , destdir ) finally : os . chdir ( ori_dir ) return dstfile
Generates a C file from a Cython source file.

    Parameters
    ----------
    src: path string
        path to Cython source
    destdir: path string (optional)
        Path to output directory (default: '.')
    cwd: path string (optional)
        Root of relative paths (default: '.')
    logger: logging.Logger
        info level used.
    full_module_name: string
        passed to cy_compile (default: None)
    only_update: bool
        Only cythonize if source is newer. default: False
    **cy_kwargs:
        second argument passed to cy_compile.
        Generates a .cpp file if cplus=True in cy_kwargs, else a .c file.