def load_module(self, name): if DEBUG: print('loading', name, 'from', self.pathname) if PY2: return imp.load_module(name, self.fp, self.pathname, self.description) else: return _call_with_frames_removed( imp.load_module, name, self.fp, self.pathname, self.description)
def source_to_code(self, data, path, *, _optimize=-1): """Return the code object compiled from source. The 'data' argument can be any object type that compile() supports. """ return _bootstrap._call_with_frames_removed(compile, data, path, 'exec', dont_inherit=True, optimize=_optimize)
def exec_module(Notebook, module): """exec_module explicitly rewrites _bootstrap_external._LoaderBasics.exec_module to pass globals into the import. This version of exec_module will always __complete__ if an ImportError is not raised. __complete__ may hold an exception. """ from importlib import _bootstrap_external, _bootstrap from types import MethodType module.__doc__ = module.__doc__ or """""" module.__complete__ = False code = Notebook.get_code(module.__name__) code is None and """Raise the expected error.""" and super().exec_module(module) try: _bootstrap._call_with_frames_removed(exec, code, module.__dict__, module.__dict__) module.__complete__ = True except BaseException as Exception: module.__complete__ = Exception return module
def main(): # Load file path = os.path.dirname( os.path.realpath(__file__)) + os.path.sep + 'input.stpy' origdata = get_data(path) # 'Trans-compile' it transformer = CodeLocationTransformer() data = b'' outlineno = 1 for inlineno, line in enumerate(origdata, 1): if line == b'\n': continue data += line transformer.add_line_mapping(outlineno, inlineno) outlineno += 1 # Parse into AST astnode = _call_with_frames_removed(compile, data, path, 'exec', flags=ast.PyCF_ONLY_AST, dont_inherit=True) # Modify AST code line and columns numbers astnode = transformer.visit(astnode) # Compile modified AST into code object codeobj = _call_with_frames_removed(compile, astnode, path, 'exec', dont_inherit=True) # Load as module module_dict = {} _call_with_frames_removed(exec, codeobj, module_dict) # Call test function module_dict['test']()
def source_to_code(self, data, path, *, _optimize=-1): """Return the Python code object compiled from DistAlgo source. """ from .. import compiler codeobj = _call_with_frames_removed(compiler.dastr_to_pycode, data, path, _optimize=_optimize, args=common.get_runtime_option( 'compiler_args', default=[])) if codeobj is None: raise ImportError("Unable to compile {}.".format(path)) return codeobj
def source_to_code(self, data, path, *, _optimize=-1): """Return the Python code object compiled from DistAlgo source. """ from . import compiler codeobj = _call_with_frames_removed(compiler.dastr_to_pycode, data, path, _optimize=_optimize, args=get_runtime_option( 'compiler_args', default=[])) if codeobj is None: raise ImportError("Unable to compile {}.".format(path)) return codeobj