Exemple #1
0
def _run_eval_string(source, filename, space, eval):
    if eval:
        cmd = 'eval'
    else:
        cmd = 'exec'

    try:
        if space is None:
            from pypy.objspace.std.objspace import StdObjSpace
            space = StdObjSpace()

        pycode = compilecode(space, source, filename or '<string>', cmd)

        mainmodule = ensure__main__(space)
        w_globals = mainmodule.w_dict

        space.setitem(w_globals, space.newtext('__builtins__'), space.builtin)
        if filename is not None:
            space.setitem(w_globals, space.newtext('__file__'), space.newtext(filename))

        retval = pycode.exec_code(space, w_globals, w_globals)
        if eval:
            return retval
        else:
            return

    except OperationError as operationerr:
        operationerr.record_interpreter_traceback()
        raise
Exemple #2
0
 def setup_class(cls):
     init_extmodule_code()
     conf = get_pypy_config()
     conf.objspace.extmodules = 'testext.extmod'
     old_sys_path[:] = sys.path[:]
     sys.path.insert(0, str(udir))
     space = StdObjSpace(conf)
     cls.space = space
    def get_entry_point(self, config):
        global space1, space2, w_entry_point_1, w_entry_point_2
        space1 = StdObjSpace(config)
        space2 = StdObjSpace(config)

        space1.setattr(space1.getbuiltinmodule('sys'),
                       space1.wrap('pypy_space'),
                       space1.wrap(1))
        space2.setattr(space2.getbuiltinmodule('sys'),
                       space2.wrap('pypy_space'),
                       space2.wrap(2))

        # manually imports app_main.py
        filename = os.path.join(this_dir, 'app_main.py')
        w_dict = space1.newdict()
        space1.exec_(open(filename).read(), w_dict, w_dict)
        w_entry_point_1 = space1.getitem(w_dict, space1.wrap('entry_point'))

        w_dict = space2.newdict()
        space2.exec_(open(filename).read(), w_dict, w_dict)
        w_entry_point_2 = space2.getitem(w_dict, space2.wrap('entry_point'))

        return entry_point, None, PyPyAnnotatorPolicy()
Exemple #4
0
def run_module(module_name, args, space=None):
    """Implements PEP 338 'Executing modules as scripts', overwriting
    sys.argv[1:] using `args` and executing the module `module_name`.
    sys.argv[0] always is `module_name`.

    Delegates the real work to the runpy module provided as the reference
    implementation.
    """
    if space is None:
        from pypy.objspace.std.objspace import StdObjSpace
        space = StdObjSpace()
    argv = [module_name]
    if args is not None:
        argv.extend(args)
    space.setitem(space.sys.w_dict, space.newtext('argv'), space.wrap(argv))
    w_import = space.builtin.get('__import__')
    runpy = space.call_function(w_import, space.newtext('runpy'))
    w_run_module = space.getitem(runpy.w_dict, space.newtext('run_module'))
    return space.call_function(w_run_module, space.newtext(module_name),
                               space.w_None, space.newtext('__main__'),
                               space.w_True)
Exemple #5
0
        w_typ.getdict()
        print "*%s*" % typedef.name

    for typedef in space.model.pythontypes:
        w_typ = getattr(space, 'w_' + typedef.name)
        w_typ.getdict()

        print "*%s*" % typedef.name
        #print w_typ.dict_w.keys()

    space.builtin.get('file').getdict()

    space.appexec([], """():
    try:
       raise ValueError
    except ValueError:
       pass
    exec 'pass'    
""")
    # freeze caches?
    print "cache build finished"


if __name__ == '__main__':
    import autopath
    from pypy.objspace.std.objspace import StdObjSpace

    space = StdObjSpace()

    buildcache(space)
Exemple #6
0
def make_objspace(config):
    from pypy.objspace.std.objspace import StdObjSpace
    return StdObjSpace(config)