def runsource(self, source, ignored_filename="<input>", symbol="single"):
        # the following hacked file name is recognized specially by error.py
        hacked_filename = '<inline>\n' + source
        compiler = self.space.getexecutioncontext().compiler

        # CPython 2.6 turns console input into unicode
        if isinstance(source, unicode):
            source = source.encode(sys.stdin.encoding)

        def doit():
            # compile the provided input
            code = compiler.compile_command(source, hacked_filename, symbol,
                                            self.console_compiler_flags)
            if code is None:
                raise IncompleteInput
            self.console_compiler_flags |= compiler.getcodeflags(code)

            # execute it
            self.settrace()
            try:
                code.exec_code(self.space, self.w_globals, self.w_globals)
            finally:
                if self.tracelevel:
                    self.space.unsettrace()
            self.checktrace()

        # run doit() in an exception-catching box
        try:
            main.run_toplevel(self.space, doit, verbose=self.verbose)
        except IncompleteInput:
            return 1
        else:
            return 0
Exemple #2
0
    def runsource(self, source, ignored_filename="<input>", symbol="single"):
        # the following hacked file name is recognized specially by error.py
        hacked_filename = '<inline>\n' + source
        compiler = self.space.getexecutioncontext().compiler

        # CPython 2.6 turns console input into unicode
        if isinstance(source, unicode):
            source = source.encode(sys.stdin.encoding)

        def doit():
            # compile the provided input
            code = compiler.compile_command(source, hacked_filename, symbol,
                                            self.console_compiler_flags)
            if code is None:
                raise IncompleteInput
            self.console_compiler_flags |= compiler.getcodeflags(code)

            # execute it
            self.settrace()
            try:
                code.exec_code(self.space, self.w_globals, self.w_globals)
            finally:
                if self.tracelevel:
                    self.space.unsettrace()
            self.checktrace()

        # run doit() in an exception-catching box
        try:
            main.run_toplevel(self.space, doit, verbose=self.verbose)
        except IncompleteInput:
            return 1
        else:
            return 0
Exemple #3
0
def main_(argv=None):
    starttime = time.time()
    config, parser = option.get_standard_options()
    interactiveconfig = Config(cmdline_optiondescr)
    to_optparse(interactiveconfig, parser=parser)

    def set_family_of_options(option, opt, value, parser):
        from pypy.config.pypyoption import set_pypy_opt_level
        set_pypy_opt_level(config, value)

    parser.add_option('--cc',
                      type=str,
                      action="callback",
                      callback=set_compiler,
                      help="Compiler to use for compiling generated C")
    parser.add_option(
        '--opt',
        type=str,
        action="callback",
        callback=set_family_of_options,
        help="Set the family of options based on -opt=0,1,2,jit...")
    args = option.process_options(parser, argv[1:])
    if interactiveconfig.verbose:
        error.RECORD_INTERPLEVEL_TRACEBACK = True
    # --allworkingmodules takes really long to start up, but can be forced on
    config.objspace.suggest(allworkingmodules=False)
    config.objspace.usemodules.struct = True
    if config.objspace.allworkingmodules:
        pypyoption.enable_allworkingmodules(config)
    if config.objspace.usemodules._continuation:
        config.translation.continuation = True
    if config.objspace.usemodules.thread:
        config.translation.thread = True

    # create the object space

    space = option.make_objspace(config)

    space._starttime = starttime
    space.setitem(space.sys.w_dict, space.wrap('executable'),
                  space.wrap(argv[0]))

    if interactiveconfig.optimize:
        #change the optimize flag's value and set __debug__ to False
        space.appexec([], """():
            import sys
            flags = list(sys.flags)
            flags[3] = 2
            sys.flags = type(sys.flags)(flags)
            __builtins__.__dict__['__debug__'] = False
        """)

    # call pypy_find_stdlib: the side-effect is that it sets sys.prefix and
    # sys.exec_prefix
    executable = argv[0]
    space.appexec([space.wrap(executable)], """(executable):
        import sys
        sys.pypy_find_stdlib(executable)
    """)

    # set warning control options (if any)
    warn_arg = interactiveconfig.warn
    if warn_arg is not None:
        space.appexec([space.wrap(warn_arg)], """(arg):
        import sys
        sys.warnoptions.append(arg)""")

    w_path = space.sys.get('path')
    path = os.getenv('PYTHONPATH')
    if path:
        path = path.split(os.pathsep)
    else:
        path = []
    path.insert(0, '')
    for i, dir in enumerate(path):
        space.call_method(w_path, 'insert', space.wrap(i), space.wrap(dir))

    # store the command-line arguments into sys.argv
    go_interactive = interactiveconfig.interactive
    banner = ''
    exit_status = 0
    command = None
    if interactiveconfig.runcommand:
        command = args[0]
        args[0] = '-c'
    if interactiveconfig.runmodule:
        command = args.pop(0)
    for arg in args:
        space.call_method(space.sys.get('argv'), 'append',
                          space.newfilename(arg))

    # load the source of the program given as command-line argument
    if interactiveconfig.runcommand:

        def doit():
            main.run_string(command, space=space)
    elif interactiveconfig.runmodule:

        def doit():
            main.run_module(command, args, space=space)
    elif args:
        scriptdir = os.path.dirname(os.path.abspath(args[0]))
        space.call_method(space.sys.get('path'), 'insert', space.wrap(0),
                          space.wrap(scriptdir))

        def doit():
            main.run_file(args[0], space=space)
    else:

        def doit():
            pass

        space.call_method(space.sys.get('argv'), 'append', space.wrap(''))
        go_interactive = 1
        banner = None

    try:

        def do_start():
            space.startup()
            pypy_init(space, space.wrap(not interactiveconfig.no_site_import))

        if main.run_toplevel(space,
                             do_start,
                             verbose=interactiveconfig.verbose):
            # compile and run it
            if not main.run_toplevel(
                    space, doit, verbose=interactiveconfig.verbose):
                exit_status = 1

            # start the interactive console
            if go_interactive or os.getenv('PYTHONINSPECT'):
                try:
                    import readline
                except:
                    pass
                con = interactive.PyPyConsole(
                    space,
                    verbose=interactiveconfig.verbose,
                    completer=interactiveconfig.completer)
                if banner == '':
                    banner = '%s / %s' % (con.__class__.__name__, repr(space))
                con.interact(banner)
                exit_status = 0
    finally:

        def doit():
            space.finish()

        main.run_toplevel(space, doit, verbose=interactiveconfig.verbose)

    return exit_status
Exemple #4
0
def main_(argv=None):
    starttime = time.time()
    config, parser = option.get_standard_options()
    interactiveconfig = Config(cmdline_optiondescr)
    to_optparse(interactiveconfig, parser=parser)
    def set_family_of_options(option, opt, value, parser):
        from pypy.config.pypyoption import set_pypy_opt_level
        set_pypy_opt_level(config, value)
    parser.add_option(
        '--cc', type=str, action="callback",
        callback=set_compiler,
        help="Compiler to use for compiling generated C")
    parser.add_option(
        '--opt', type=str, action="callback",
        callback=set_family_of_options,
        help="Set the family of options based on -opt=0,1,2,jit...")
    args = option.process_options(parser, argv[1:])
    if interactiveconfig.verbose:
        error.RECORD_INTERPLEVEL_TRACEBACK = True
    # --allworkingmodules takes really long to start up, but can be forced on
    config.objspace.suggest(allworkingmodules=False)
    if config.objspace.allworkingmodules:
        pypyoption.enable_allworkingmodules(config)
    if config.objspace.usemodules._continuation:
        config.translation.continuation = True
    if config.objspace.usemodules.thread:
        config.translation.thread = True

    # create the object space

    space = option.make_objspace(config)

    space._starttime = starttime
    space.setitem(space.sys.w_dict, space.wrap('executable'),
                  space.wrap(argv[0]))

    if interactiveconfig.optimize:
        #change the optimize flag's value and set __debug__ to False
        space.appexec([], """():
            import sys
            flags = list(sys.flags)
            flags[6] = 2
            sys.flags = type(sys.flags)(flags)
            import __pypy__
            __pypy__.set_debug(False)
        """)

    # call pypy_find_stdlib: the side-effect is that it sets sys.prefix and
    # sys.exec_prefix
    executable = argv[0]
    space.appexec([space.wrap(executable)], """(executable):
        import sys
        sys.pypy_find_stdlib(executable)
    """)

    # set warning control options (if any)
    warn_arg = interactiveconfig.warn
    if warn_arg is not None:
        space.appexec([space.wrap(warn_arg)], """(arg): 
        import sys
        sys.warnoptions.append(arg)""")

    w_path = space.sys.get('path')
    path = os.getenv('PYTHONPATH')
    if path:
        path = path.split(os.pathsep)
    else:
        path = []
    path.insert(0, '')
    for i, dir in enumerate(path):
        space.call_method(w_path, 'insert', space.wrap(i), space.wrap(dir))

    # store the command-line arguments into sys.argv
    go_interactive = interactiveconfig.interactive
    banner = ''
    exit_status = 0
    command = None
    if interactiveconfig.runcommand:
        command = args[0]
        args[0] = '-c'
    if interactiveconfig.runmodule:
        command = args.pop(0)
    for arg in args:
        space.call_method(space.sys.get('argv'), 'append',
                          space.wrap_fsdecoded(arg))

    # load the source of the program given as command-line argument
    if interactiveconfig.runcommand:
        def doit():
            main.run_string(command, space=space)
    elif interactiveconfig.runmodule:
        def doit():
            main.run_module(command, args, space=space)
    elif args:
        scriptdir = os.path.dirname(os.path.abspath(args[0]))
        space.call_method(space.sys.get('path'), 'insert',
                          space.wrap(0), space.wrap(scriptdir))
        def doit():
            main.run_file(args[0], space=space)
    else:
        def doit():
            pass
        space.call_method(space.sys.get('argv'), 'append', space.wrap(''))
        go_interactive = 1
        banner = None

    try:
        def do_start():
            space.startup()
            pypy_init(space, space.wrap(not interactiveconfig.no_site_import))
        if main.run_toplevel(space, do_start,
                             verbose=interactiveconfig.verbose):
            # compile and run it
            if not main.run_toplevel(space, doit,
                                     verbose=interactiveconfig.verbose):
                exit_status = 1

            # start the interactive console
            if go_interactive or os.getenv('PYTHONINSPECT'):
                try:
                    import readline
                except:
                    pass
                con = interactive.PyPyConsole(
                    space, verbose=interactiveconfig.verbose,
                    completer=interactiveconfig.completer)
                if banner == '':
                    banner = '%s / %s'%(con.__class__.__name__,
                                        repr(space))
                con.interact(banner)
                exit_status = 0
    finally:
        def doit():
            space.finish()
        main.run_toplevel(space, doit, verbose=interactiveconfig.verbose)

    return exit_status
Exemple #5
0
def main_(argv=None):
    starttime = time.time()
    config, parser = option.get_standard_options()
    interactiveconfig = Config(cmdline_optiondescr)
    to_optparse(interactiveconfig, parser=parser)
    parser.add_option('--cc',
                      type=str,
                      action="callback",
                      callback=set_compiler,
                      help="Compiler to use for compiling generated C")
    args = option.process_options(parser, argv[1:])
    if interactiveconfig.verbose:
        error.RECORD_INTERPLEVEL_TRACEBACK = True
    # --allworkingmodules takes really long to start up, but can be forced on
    config.objspace.suggest(allworkingmodules=False)
    if config.objspace.allworkingmodules:
        pypyoption.enable_allworkingmodules(config)

    # create the object space

    space = option.make_objspace(config)

    space._starttime = starttime
    space.setitem(space.sys.w_dict, space.wrap('executable'),
                  space.wrap(argv[0]))

    # set warning control options (if any)
    warn_arg = interactiveconfig.warn
    if warn_arg is not None:
        space.appexec([space.wrap(warn_arg)], """(arg): 
        import sys
        sys.warnoptions.append(arg)""")

    w_path = space.sys.get('path')
    path = os.getenv('PYTHONPATH')
    if path:
        path = path.split(os.pathsep)
    else:
        path = []
    path.insert(0, '')
    for i, dir in enumerate(path):
        space.call_method(w_path, 'insert', space.wrap(i), space.wrap(dir))

    # store the command-line arguments into sys.argv
    go_interactive = interactiveconfig.interactive
    banner = ''
    exit_status = 0
    if interactiveconfig.runcommand is not None:
        args = ['-c'] + args
    for arg in args:
        space.call_method(space.sys.get('argv'), 'append', space.wrap(arg))

    # load the source of the program given as command-line argument
    if interactiveconfig.runcommand is not None:

        def doit():
            main.run_string(interactiveconfig.runcommand, space=space)
    elif interactiveconfig.runmodule:

        def doit():
            main.run_module(interactiveconfig.runmodule, args, space=space)
    elif args:
        scriptdir = os.path.dirname(os.path.abspath(args[0]))
        space.call_method(space.sys.get('path'), 'insert', space.wrap(0),
                          space.wrap(scriptdir))

        def doit():
            main.run_file(args[0], space=space)
    else:

        def doit():
            pass

        space.call_method(space.sys.get('argv'), 'append', space.wrap(''))
        go_interactive = 1
        banner = None

    try:

        def do_start():
            space.startup()
            pypy_init(space, space.wrap(not interactiveconfig.no_site_import))

        if main.run_toplevel(space,
                             do_start,
                             verbose=interactiveconfig.verbose):
            # compile and run it
            if not main.run_toplevel(
                    space, doit, verbose=interactiveconfig.verbose):
                exit_status = 1

            # start the interactive console
            if go_interactive or os.getenv('PYTHONINSPECT'):
                try:
                    import readline
                except:
                    pass
                con = interactive.PyPyConsole(
                    space,
                    verbose=interactiveconfig.verbose,
                    completer=interactiveconfig.completer)
                if banner == '':
                    banner = '%s / %s' % (con.__class__.__name__, repr(space))
                con.interact(banner)
                exit_status = 0
    finally:

        def doit():
            space.finish()

        main.run_toplevel(space, doit, verbose=interactiveconfig.verbose)

    return exit_status
Exemple #6
0
def main_(argv=None):
    starttime = time.time()
    config, parser = option.get_standard_options()
    interactiveconfig = Config(cmdline_optiondescr)
    to_optparse(interactiveconfig, parser=parser)
    args = option.process_options(parser, argv[1:])
    if interactiveconfig.verbose:
        error.RECORD_INTERPLEVEL_TRACEBACK = True

    # create the object space

    space = option.make_objspace(config)

    space._starttime = starttime
    #assert 'pypy.tool.udir' not in sys.modules, (
    #    "running py.py should not import pypy.tool.udir, which is\n"
    #    "only for testing or translating purposes.")
    # ^^^ _socket and other rctypes-based modules need udir
    space.setitem(space.sys.w_dict,space.wrap('executable'),space.wrap(argv[0]))

    # store the command-line arguments into sys.argv
    go_interactive = interactiveconfig.interactive
    banner = ''
    exit_status = 0
    if interactiveconfig.runcommand is not None:
        args = ['-c'] + args
    for arg in args:
        space.call_method(space.sys.get('argv'), 'append', space.wrap(arg))

    # load the source of the program given as command-line argument
    if interactiveconfig.runcommand is not None:
        def doit():
            main.run_string(interactiveconfig.runcommand, space=space)
    elif interactiveconfig.runmodule:
        def doit():
            main.run_module(interactiveconfig.runmodule,
                            args, space=space)
    elif args:
        scriptdir = os.path.dirname(os.path.abspath(args[0]))
        space.call_method(space.sys.get('path'), 'insert',
                          space.wrap(0), space.wrap(scriptdir))
        def doit():
            main.run_file(args[0], space=space)
    else:
        def doit():
            pass
        space.call_method(space.sys.get('argv'), 'append', space.wrap(''))
        go_interactive = 1
        banner = None

    try:
        def do_start():
            space.startup()
            pypy_init(space, space.wrap(not interactiveconfig.no_site_import))
        if main.run_toplevel(space, do_start,
                             verbose=interactiveconfig.verbose):
            # compile and run it
            if not main.run_toplevel(space, doit,
                                     verbose=interactiveconfig.verbose):
                exit_status = 1

            # start the interactive console
            if go_interactive or getenv_w(space, 'PYTHONINSPECT'):
                con = interactive.PyPyConsole(
                    space, verbose=interactiveconfig.verbose,
                    completer=interactiveconfig.completer)
                if banner == '':
                    banner = '%s / %s'%(con.__class__.__name__,
                                        repr(space))
                con.interact(banner)
                exit_status = 0
    finally:
        def doit():
            space.finish()
        main.run_toplevel(space, doit, verbose=interactiveconfig.verbose)

    return exit_status
Exemple #7
0
def main_(argv=None):
    starttime = time.time()
    config, parser = option.get_standard_options()
    interactiveconfig = Config(cmdline_optiondescr)
    to_optparse(interactiveconfig, parser=parser)
    args = option.process_options(parser, argv[1:])
    if interactiveconfig.verbose:
        error.RECORD_INTERPLEVEL_TRACEBACK = True

    # create the object space

    space = option.make_objspace(config)

    space._starttime = starttime
    space.setitem(space.sys.w_dict, space.wrap('executable'),
                  space.wrap(argv[0]))

    # store the command-line arguments into sys.argv
    go_interactive = interactiveconfig.interactive
    banner = ''
    exit_status = 0
    if interactiveconfig.runcommand is not None:
        args = ['-c'] + args
    for arg in args:
        space.call_method(space.sys.get('argv'), 'append', space.wrap(arg))

    # load the source of the program given as command-line argument
    if interactiveconfig.runcommand is not None:

        def doit():
            main.run_string(interactiveconfig.runcommand, space=space)
    elif interactiveconfig.runmodule:

        def doit():
            main.run_module(interactiveconfig.runmodule, args, space=space)
    elif args:
        scriptdir = os.path.dirname(os.path.abspath(args[0]))
        space.call_method(space.sys.get('path'), 'insert', space.wrap(0),
                          space.wrap(scriptdir))

        def doit():
            main.run_file(args[0], space=space)
    else:

        def doit():
            pass

        space.call_method(space.sys.get('argv'), 'append', space.wrap(''))
        go_interactive = 1
        banner = None

    try:

        def do_start():
            space.startup()
            pypy_init(space, space.wrap(not interactiveconfig.no_site_import))

        if main.run_toplevel(space,
                             do_start,
                             verbose=interactiveconfig.verbose):
            # compile and run it
            if not main.run_toplevel(
                    space, doit, verbose=interactiveconfig.verbose):
                exit_status = 1

            # start the interactive console
            if go_interactive or getenv_w(space, 'PYTHONINSPECT'):
                try:
                    import readline
                except:
                    pass
                con = interactive.PyPyConsole(
                    space,
                    verbose=interactiveconfig.verbose,
                    completer=interactiveconfig.completer)
                if banner == '':
                    banner = '%s / %s' % (con.__class__.__name__, repr(space))
                con.interact(banner)
                exit_status = 0
    finally:

        def doit():
            space.finish()

        main.run_toplevel(space, doit, verbose=interactiveconfig.verbose)

    return exit_status
Exemple #8
0
def main_(argv=None):
    starttime = time.time()
    config, parser = option.get_standard_options()
    interactiveconfig = Config(cmdline_optiondescr)
    to_optparse(interactiveconfig, parser=parser)
    parser.add_option(
        '--cc', type=str, action="callback",
        callback=set_compiler,
        help="Compiler to use for compiling generated C")
    args = option.process_options(parser, argv[1:])
    if interactiveconfig.verbose:
        error.RECORD_INTERPLEVEL_TRACEBACK = True
    # --allworkingmodules takes really long to start up, but can be forced on
    config.objspace.suggest(allworkingmodules=False)
    if config.objspace.allworkingmodules:
        pypyoption.enable_allworkingmodules(config)

    # create the object space

    space = option.make_objspace(config)

    space._starttime = starttime
    space.setitem(space.sys.w_dict, space.wrap('executable'),
                  space.wrap(argv[0]))

    # set warning control options (if any)
    warn_arg = interactiveconfig.warn
    if warn_arg is not None:
        space.appexec([space.wrap(warn_arg)], """(arg): 
        import sys
        sys.warnoptions.append(arg)""")

    w_path = space.sys.get('path')
    path = os.getenv('PYTHONPATH')
    if path:
        path = path.split(os.pathsep)
    else:
        path = []
    path.insert(0, '')
    for i, dir in enumerate(path):
        space.call_method(w_path, 'insert', space.wrap(i), space.wrap(dir))

    # store the command-line arguments into sys.argv
    go_interactive = interactiveconfig.interactive
    banner = ''
    exit_status = 0
    if interactiveconfig.runcommand is not None:
        args = ['-c'] + args
    for arg in args:
        space.call_method(space.sys.get('argv'), 'append', space.wrap(arg))

    # load the source of the program given as command-line argument
    if interactiveconfig.runcommand is not None:
        def doit():
            main.run_string(interactiveconfig.runcommand, space=space)
    elif interactiveconfig.runmodule:
        def doit():
            main.run_module(interactiveconfig.runmodule,
                            args, space=space)
    elif args:
        scriptdir = os.path.dirname(os.path.abspath(args[0]))
        space.call_method(space.sys.get('path'), 'insert',
                          space.wrap(0), space.wrap(scriptdir))
        def doit():
            main.run_file(args[0], space=space)
    else:
        def doit():
            pass
        space.call_method(space.sys.get('argv'), 'append', space.wrap(''))
        go_interactive = 1
        banner = None

    try:
        def do_start():
            space.startup()
            pypy_init(space, space.wrap(not interactiveconfig.no_site_import))
        if main.run_toplevel(space, do_start,
                             verbose=interactiveconfig.verbose):
            # compile and run it
            if not main.run_toplevel(space, doit,
                                     verbose=interactiveconfig.verbose):
                exit_status = 1

            # start the interactive console
            if go_interactive or os.getenv('PYTHONINSPECT'):
                try:
                    import readline
                except:
                    pass
                con = interactive.PyPyConsole(
                    space, verbose=interactiveconfig.verbose,
                    completer=interactiveconfig.completer)
                if banner == '':
                    banner = '%s / %s'%(con.__class__.__name__,
                                        repr(space))
                con.interact(banner)
                exit_status = 0
    finally:
        def doit():
            space.finish()
        main.run_toplevel(space, doit, verbose=interactiveconfig.verbose)

    return exit_status