示例#1
0
    def generate_python_code(module_node):
        cw = CodeWriter()
        cw.visit(module_node)
        try:
            os.makedirs(result.output_dir)
        except OSError:
            pass
        
        open(os.path.join(result.output_dir, "__init__.py"), "w").close()

        output_file = codecs.open(options.output_file, "w", encoding="utf-8")
        output_file.write("# -*- encoding: utf-8 -*-\n")
        output_file.write("\n".join(cw.result.lines))
        output_file.write("\n")
        output_file.close()
示例#2
0
    def run(self, func_or_ast, pyx_header):
        self.__pyx_header = pyx_header

        # we already has a AST: just run it
        if isinstance(func_or_ast, ast.AST):
            cyast = self.visit(func_or_ast)
        else:
            check_argument(isinstance(func_or_ast, types.FunctionType))
            # ignore varargs and keywords
            self.__func_params_name_list = inspect.getfullargspec(func_or_ast).args
            self.__globals = func_or_ast.__globals__
            cyast = self.parse(inspect.getsource(func_or_ast))

        writer = patch_cython_codewriter(CodeWriter())
        cycode = "\n".join(writer.write(cyast).lines)
        return cycode
示例#3
0
 def codeToLines(self, tree):
     writer = CodeWriter()
     writer.write(tree)
     return writer.result.lines
示例#4
0
文件: TestUtils.py 项目: DT021/wau
 def codeToLines(self, tree):
     writer = CodeWriter()
     writer.write(tree)
     return writer.result.lines
示例#5
0
 def compile(self, source):
     """Compile source into cython code."""
     cyast = self.parse(source)
     writer = patch_cython_codewriter(CodeWriter())
     return "\n".join(writer.write(cyast).lines)