""" pypython.py Save this in your pypy root directory Allows you to run files via pypy. This should eventually duplicate calling 'python' from the command line exactly. """ # we figure out what the parent folder is here # and add it to pythonpath. That way we can # store the pypython heirarchy outside of # CPython's PYTHONPATH. import sys, os if '__file__' in dir(): folder = os.path.split(__file__)[0] folder = os.path.split(folder)[0] if folder not in sys.path: sys.path.append(folder) else: pass # better be in pythonpath already from pypy.interpreter import executioncontext from pypy.interpreter import pyframe from pypy.interpreter import baseobjspace import pywin.debugger class bootstrap: def __init__(self, objSpaceType = 'trivial'): classname = objSpaceType.capitalize() + "ObjSpace" module = __import__('pypy.objspace.%s' % objSpaceType, globals(), locals(),[classname]) ObjSpace = getattr(module, classname) self.space = ObjSpace() self.ec = executioncontext.ExecutionContext(self.space) self.w_globals = self.ec.make_standard_w_globals() self.space.setitem(self.w_globals, self.space.wrap("__name__"), self.space.wrap("__main__")) def execString(self, string): code = compile(string, "", "exec") frame = pyframe.PyFrame(self.space, code, self.w_globals, self.w_globals) self.ec.eval_frame(frame) def execFile(self, filename): f = file(filename) self.execString(f.read()) if __name__ == "__main__": if len(sys.argv) <= 2: x = bootstrap() if len(sys.argv) == 1: x.execString("print 'foo'") x.execString("exec 'print 1' in {},{}") x.execString("import code") x.execString("ic = code.InteractiveConsole()") x.execString("ic.interact()") else: x.execFile(sys.argv[1]) else: print "USAGE: pypython.py script"