def PyrexCompile ( Errors, Main, source, pxddirectories = None ): """Convert a Pyrex file to C.""" options = Main.default_options # . Change for Pyrex version 0.9.6: options is now a dictionary not a CompilationOptions object so convert to a CompilationOptions object. if isinstance ( options, dict ): options = Main.CompilationOptions ( options ) if pxddirectories is not None: options.include_path.extend ( pxddirectories ) context = Main.Context ( options.include_path ) try: result = context.compile ( source, options ) QFAILURE = ( result.num_errors > 0 ) except Errors.PyrexError, e: print >>sys.stderr, e QFAILURE = True
def PyrexCompile ( Errors, Main, source, pxdDirectories = None ): """Convert a Pyrex file to C.""" options = Main.default_options # . Change for Pyrex version 0.9.6: options is now a dictionary not a CompilationOptions object so convert to a CompilationOptions object. if isinstance ( options, dict ): options = Main.CompilationOptions ( options ) if pxdDirectories is not None: options.include_path.extend ( pxdDirectories ) context = Main.Context ( options.include_path, {} ) try: result = Main.compile ( source, options ) failed = ( result.num_errors > 0 ) except Errors.PyrexError as e: print ( e ) failed = True if failed: raise ValueError ( "There was a Pyrex compiler error." )
def parser(module): """ Read, parse a Cython code and generate an abstract syntaxique tree. Context: Compilation context: contains every pxd ever loaded, path information and the data related to the compilation. Class where it is implemented Cython parse method. options: To set Compilation Options as language_level: The source language level to use, formal_grammar: to define if it will be used to Parse the file evaluate_tree_assertions: To evaluate parse tree show_version : To display version number use_listing_file: Generate a .lis file errors_to_stderr: Echo errors to stderr when using .lis include_path: Directories to search for include files output_file: Name of generated .c file generate_pxi: Generate .pxi file for public declarations capi_reexport_cincludes: Add cincluded headers to any auto-generated header files. timestamps: Only compile changed source files verbose : Always print source names being compiled compiler_directives: Overrides for pragma options (see Options.py) embedded_metadata: Metadata to embed in the C file as json. evaluate_tree_assertions: Test support: evaluate parse tree assertions cplus : Compile as c++ code Here default options were used except language level Scanning.FileSourceDescriptor: Represents a code source. Only file sources for Cython code supported """ options = opt(**options_defaults) if isinstance(module, Path): context = Main.Context([os.path.dirname(module)], {}, cpp=False, language_level=2, options=options) scope = context.find_submodule(module) with open(module.encode('utf-8'), 'r') as f: source = f.read() source_desc = Scanning.FileSourceDescriptor(module, source) tree = context.parse(source_desc, scope, pxd=None, full_module_name=module) else: from Cython.Compiler.TreeFragment import parse_from_strings if sys.version_info[0] < 3: module = unicode(module) tree = parse_from_strings("module", module) return tree