def cython_import(filename, verbose=False, compile_message=False, use_cache=False, create_local_c_file=True): """ Compile a file containing Cython code, then import and return the module. Raises an ``ImportError`` if anything goes wrong. INPUT: - ``filename`` - a string; name of a file that contains Cython code OUTPUT: - the module that contains the compiled Cython code. """ name, build_dir = cython(filename, verbose=verbose, compile_message=compile_message, use_cache=use_cache, create_local_c_file=create_local_c_file) sys.path.append(build_dir) return import_module(name)
def load_cython(name): """ Helper function to load a Cython file. INPUT: - ``name`` -- filename of the Cython file OUTPUT: - A string with Python code to import the names from the compiled module. """ from sage.misc.cython import cython mod, dir = cython(name, compile_message=True, use_cache=True) import sys sys.path.append(dir) return 'from {} import *'.format(mod)