Henrik Vendelbo avatar Henrik Vendelbo committed 6d08709

command line fixes

Comments (0)

Files changed (3)

 	cp -pLR pypy/lib/* Library/maestro
 	
 test:
-	py/bin/py.test pypy/module/installation
+	py/bin/py.test pypy/module/installation pypy/translator/goal/test2/test_nanos.py
 	
 thepiantest:
 	./thepianpython test Library/thepianpython

pypy/translator/goal/commands_main.py

 options:
   -i             inspect interactively after running script
   -O             dummy optimization flag for compatibility with C Python
-  -c CMD         program passed in as CMD (terminates option list)
+  -c cmd         program passed in as CMD (terminates option list)
   -S             do not 'import site' on initialization
   -u             unbuffered binary stdout and stderr
   -h, --help     show this help message and exit
-  -m             library module to be run as a script (terminates option list)
+  -m mod         library module to be run as a script (terminates option list)
   -W arg         warning control (arg is action:message:category:module:lineno)
+  -E             ignore environment variables (such as PYTHONPATH)
   --version      print the PyPy version
   --info         print translation information about this PyPy executable
 """
 
 originalexcepthook = sys.__excepthook__
 
+def handle_sys_exit(e):
+    # exit if we catch a w_SystemExit
+    exitcode = e.code
+    if exitcode is None:
+        exitcode = 0
+    else:
+        try:
+            exitcode = int(exitcode)
+        except:
+            # not an integer: print it to stderr
+            try:
+                stderr = sys.stderr
+            except AttributeError:
+                pass   # too bad
+            else:
+                print >> stderr, exitcode
+            exitcode = 1
+    raise SystemExit(exitcode)
+
 def run_toplevel(f, *fargs, **fkwds):
     """Calls f() and handles all OperationErrors.
     Intended use is to run the main program or one interactive statement.
                 stdout.write('\n')
 
     except SystemExit, e:
-        # exit if we catch a w_SystemExit
-        exitcode = e.code
-        if exitcode is None:
-            exitcode = 0
-        else:
-            try:
-                exitcode = int(exitcode)
-            except:
-                # not an integer: print it to stderr
-                try:
-                    stderr = sys.stderr
-                except AttributeError:
-                    pass   # too bad
-                else:
-                    print >> stderr, exitcode
-                exitcode = 1
-        raise SystemExit(exitcode)
+        handle_sys_exit(e)
+    except:
+        display_exception()
+        return False
+    return True   # success
+
+def display_exception():
+    etype, evalue, etraceback = sys.exc_info()
+    try:
+        # extra debugging info in case the code below goes very wrong
+        if DEBUG and hasattr(sys, 'stderr'):
+            s = getattr(etype, '__name__', repr(etype))
+            print >> sys.stderr, "debug: exception-type: ", s
+            print >> sys.stderr, "debug: exception-value:", str(evalue)
+            tbentry = etraceback
+            if tbentry:
+                while tbentry.tb_next:
+                    tbentry = tbentry.tb_next
+                lineno = tbentry.tb_lineno
+                filename = tbentry.tb_frame.f_code.co_filename
+                print >> sys.stderr, "debug: exception-tb:    %s:%d" % (
+                    filename, lineno)
+
+        # set the sys.last_xxx attributes
+        sys.last_type = etype
+        sys.last_value = evalue
+        sys.last_traceback = etraceback
+
+        # call sys.excepthook
+        hook = getattr(sys, 'excepthook', originalexcepthook)
+        hook(etype, evalue, etraceback)
+        return # done
 
     except:
-        etype, evalue, etraceback = sys.exc_info()
         try:
-            # extra debugging info in case the code below goes very wrong
-            if DEBUG and hasattr(sys, 'stderr'):
-                s = getattr(etype, '__name__', repr(etype))
-                print >> sys.stderr, "debug: exception-type: ", s
-                print >> sys.stderr, "debug: exception-value:", str(evalue)
-                tbentry = etraceback
-                if tbentry:
-                    while tbentry.tb_next:
-                        tbentry = tbentry.tb_next
-                    lineno = tbentry.tb_lineno
-                    filename = tbentry.tb_frame.f_code.co_filename
-                    print >> sys.stderr, "debug: exception-tb:    %s:%d" % (
-                        filename, lineno)
+            stderr = sys.stderr
+        except AttributeError:
+            pass   # too bad
+        else:
+            print >> stderr, 'Error calling sys.excepthook:'
+            originalexcepthook(*sys.exc_info())
+            print >> stderr
+            print >> stderr, 'Original exception was:'
 
-            # set the sys.last_xxx attributes
-            sys.last_type = etype
-            sys.last_value = evalue
-            sys.last_traceback = etraceback
+    # we only get here if sys.excepthook didn't do its job
+    originalexcepthook(etype, evalue, etraceback)
 
-            # call sys.excepthook
-            hook = getattr(sys, 'excepthook', originalexcepthook)
-            hook(etype, evalue, etraceback)
-            return False   # done
-
-        except:
-            try:
-                stderr = sys.stderr
-            except AttributeError:
-                pass   # too bad
-            else:
-                print >> stderr, 'Error calling sys.excepthook:'
-                originalexcepthook(*sys.exc_info())
-                print >> stderr
-                print >> stderr, 'Original exception was:'
-
-        # we only get here if sys.excepthook didn't do its job
-        originalexcepthook(etype, evalue, etraceback)
-        return False
-
-    return True   # success
 
 # ____________________________________________________________
 # Option parsing
 
-def print_info():
+def print_info(*args):
     try:
         options = sys.pypy_translation_info
     except AttributeError:
         optitems.sort()
         for name, value in optitems:
             print ' %51s: %s' % (name, value)
+    raise SystemExit
 
-def print_help():
-    print 'usage: %s [options]' % (sys.executable,)
+def print_help(*args):
+    print 'usage: %s [options] [-c cmd|-m mod|file.py|-] [arg...]' % (
+        sys.executable,)
     print __doc__.rstrip()
     if 'pypyjit' in sys.builtin_module_names:
-        print_jit_help()
+        _print_jit_help()
     print
+    raise SystemExit
 
-def print_jit_help():
+def _print_jit_help():
     import pypyjit
     items = pypyjit.defaults.items()
     items.sort()
         print '  --jit %s=N %slow-level JIT parameter (default %s)' % (
             key, ' '*(18-len(key)), value)
 
+def print_version(*args):
+    print "Python", sys.version
+    raise SystemExit
+
+def set_jit_option(options, jitparam, *args):
+    if 'pypyjit' not in sys.builtin_module_names:
+        print >> sys.stderr, ("Warning: No jit support in %s" %
+                              (sys.executable,))
+    else:
+        import pypyjit
+        pypyjit.set_param(jitparam)
+
 class CommandLineError(Exception):
     pass
 
 else:
     IS_WINDOWS = False
 
-def get_argument(option, argv, i):
-    arg = argv[i]
-    n = len(option)
-    if len(arg) > n:
-        return arg[n:], i
+def get_library_path(executable):
+    search = executable
+    while 1:
+        dirname = resolvedirof(search)
+        if dirname == search:
+            # not found!  let's hope that the compiled-in path is ok
+            print >> sys.stderr, ('debug: WARNING: library path not found, '
+                                  'using compiled-in sys.path')
+            newpath = sys.path[:]
+            break
+        newpath = sys.pypy_initial_path(dirname)
+        if newpath is None:
+            search = dirname    # walk to the parent directory
+            continue
+        break      # found!
+    return newpath
+
+def setup_sys_executable(executable, nanos):
+    # a substituted os if we are translated
+    global os
+    os = nanos
+    # find the full path to the executable, assuming that if there is no '/'
+    # in the provided one then we must look along the $PATH
+    if we_are_translated() and IS_WINDOWS and not executable.lower().endswith('.exe'):
+        executable += '.exe'
+    if os.sep in executable or (IS_WINDOWS and DRIVE_LETTER_SEP in executable):
+        pass    # the path is already more than just an executable name
     else:
-        i += 1
-        if i >= len(argv):
-            raise CommandLineError('Argument expected for the %s option' %
-                                   option)
-        return argv[i], i
+        path = os.getenv('PATH')
+        if path:
+            for dir in path.split(os.pathsep):
+                fn = os.path.join(dir, executable)
+                if os.path.isfile(fn):
+                    executable = fn
+                    break
+    sys.executable = os.path.abspath(executable)
+
+product_library_paths = [
+    ['Library/%(product)s/%(version)s/'],
+    ['Library/%(product)s-%(version)s/'],
+    ['Library/%(product)s/'],
+    ['share/%(product)s/%(version)s/'],
+    ['share/%(product)s-%(version)s/'],
+    ['share/%(product)s/'],
+]
+                    
+python_library_paths = [
+    ['Library/python/%(version)s/'],
+    ['Library/python-%(version)s/'],
+    ['Library/python%(version)s/'],
+    ['share/python/%(version)s/'],
+    ['share/python-%(version)s/'],
+    ['share/python%(version)s/'],
+]
+                    
+exe_mappings = {
+    '': 'pypy-c',
+    'py.py':'pypy-c',
+}
+
+
+def setup_initial_paths_old(ignore_environment=False, **extra):
+    newpath = get_library_path(sys.executable)
+    readenv = not ignore_environment
+    path = readenv and os.getenv('PYTHONPATH')
+    if path:
+        newpath = path.split(os.pathsep) + newpath
+    # remove duplicates
+    _seen = {}
+    del sys.path[:]
+    for dir in newpath:
+        if dir not in _seen:
+            sys.path.append(dir)
+            _seen[dir] = True
 
 product_library_paths = [
     ['Library/%(product)s/%(version)s/'],
     else:
         return executable_name
         
-def setup_initial_paths(executable, nanos):
+def setup_initial_paths(executable,ignore_environment=False, **ignored):
     """Set up 'sys.executable', 'sys.executable_name' and 'sys.path' before executing the command line 
     
     Walk up directories looking for a library root in . or ./share/pypy-X.X
     ./share/PRODUCT
     
     """
-    # a substituted os if we are translated
-    global os
-    os = nanos
-    
-    # find the full path to the executable, assuming that if there is no '/'
-    # in the provided one then we must look along the $PATH
-    if we_are_translated() and IS_WINDOWS and not executable.lower().endswith('.exe'):
-        executable += '.exe'
-    if os.sep in executable or (IS_WINDOWS and DRIVE_LETTER_SEP in executable):
-        pass    # the path is already more than just an executable name
-    else:
-        path = os.getenv('PATH')
-        if path:
-            for dir in path.split(os.pathsep):
-                fn = os.path.join(dir, executable)
-                if os.path.isfile(fn):
-                    executable = fn
-                    break
-    sys.executable = os.path.abspath(executable)
-    executable_name = sys.executable.split(os.sep)[-1]
-    sys.executable_name = executable_name in exe_mappings and exe_mappings[executable_name] or executable_name
-    sys.product_name = get_product_name(executable_name)
-    
     apppath = None
     search = executable
     while 1:
                 search = dirname    # walk to the parent directory
                 continue
         break      # found!
-    python_path = os.getenv(PATHVAR)
-    if python_path:
-        newpath = python_path.split(os.pathsep) + newpath
+    if not ignore_environment:
+        python_path = os.getenv(PATHVAR)
+        if python_path:
+            newpath = python_path.split(os.pathsep) + newpath
     newpath.insert(0, '')
     
     # remove duplicates
     return executable
 
 
+# Order is significant!
+sys_flags = (
+    "debug",
+    "py3k_warning",
+    "division_warning",
+    "division_new",
+    "inspect",
+    "interactive",
+    "optimize",
+    "dont_write_bytecode",
+    "no_user_site",
+    "no_site",
+    "ignore_environment",
+    "tabcheck",
+    "verbose",
+    "unicode",
+    "bytes_warning",
+)
+
+
+default_options = dict.fromkeys(
+    sys_flags +
+    ("run_command",
+    "run_module",
+    "run_stdin",
+    "warnoptions",
+    "unbuffered"), 0)
+
+
+PYTHON26 = False
+
+def simple_option(options, name, iterargv):
+    options[name] += 1
+
+def div_option(options, div, iterargv):
+    if div == "warn":
+        options["division_warning"] = 1
+    elif div == "warnall":
+        options["division_warning"] = 2
+    elif div == "new":
+        options["division_new"] = 1
+    elif div != "old":
+        raise CommandLineError("invalid division option: %r" % (div,))
+
+def c_option(options, runcmd, iterargv):
+    options["run_command"] = runcmd
+    return ['-c'] + list(iterargv)
+
+def m_option(options, runmodule, iterargv):
+    options["run_module"] = True
+    return [runmodule] + list(iterargv)
+
+def W_option(options, warnoption, iterargv):
+    options["warnoptions"].append(warnoption)
+
+def end_options(options, _, iterargv):
+    return list(iterargv)
+
+cmdline_options = {
+    # simple options just increment the counter of the options listed above
+    'd': (simple_option, 'debug'),
+    'i': (simple_option, 'interactive'),
+    'O': (simple_option, 'optimize'),
+    'S': (simple_option, 'no_site'),
+    'E': (simple_option, 'ignore_environment'),
+    't': (simple_option, 'tabcheck'),
+    'v': (simple_option, 'verbose'),
+    'U': (simple_option, 'unicode'),
+    'u': (simple_option, 'unbuffered'),
+    # more complex options
+    'Q':         (div_option,      Ellipsis),
+    'c':         (c_option,        Ellipsis),
+    'm':         (m_option,        Ellipsis),
+    'W':         (W_option,        Ellipsis),
+    'V':         (print_version,   None),
+    '--version': (print_version,   None),
+    '--info':    (print_info,      None),
+    'h':         (print_help,      None),
+    '--help':    (print_help,      None),
+    '--jit':     (set_jit_option,  Ellipsis),
+    '--':        (end_options,     None),
+    }
+
+if PYTHON26:
+    cmdline_options.update({
+        '3': (simple_option, 'py3k_warning'),
+        'B': (simple_option, 'dont_write_bytecode'),
+        's': (simple_option, 'no_user_site'),
+        'b': (simple_option, 'bytes_warning'),
+        })
+
+
+def handle_argument(c, options, iterargv, iterarg=iter(())):
+    function, funcarg = cmdline_options[c]
+    #
+    # If needed, fill in the real argument by taking it from the command line
+    if funcarg is Ellipsis:
+        remaining = list(iterarg)
+        if remaining:
+            funcarg = ''.join(remaining)
+        else:
+            try:
+                funcarg = iterargv.next()
+            except StopIteration:
+                if len(c) == 1:
+                    c = '-' + c
+                raise CommandLineError('Argument expected for the %r option' % c)
+    #
+    return function(options, funcarg, iterargv)
+
+
 def parse_command_line(argv):
-    go_interactive = False
-    run_command = False
-    import_site = True
-    i = 0
-    run_module = False
-    run_stdin = False
-    warnoptions = []
-    unbuffered = False
-    while i < len(argv):
-        arg = argv[i]
-        if not arg.startswith('-'):
-            break
-        if arg == '-i':
-            go_interactive = True
-        elif arg.startswith('-c'):
-            cmd, i = get_argument('-c', argv, i)
-            argv[i] = '-c'
-            run_command = True
-            break
-        elif arg == '-u':
-            unbuffered = True
-        elif arg == '-O':
-            pass
-        elif arg == '--version' or arg == '-V':
-            print "Python", sys.version
-            return
-        elif arg == '--info':
-            print_info()
-            return
-        elif arg == '-h' or arg == '--help':
-            print_help()
-            return
-        elif arg == '-S':
-            import_site = False
-        elif arg == '-':
-            run_stdin = True
-            break     # not an option but a file name representing stdin
-        elif arg.startswith('-m'):
-            module, i = get_argument('-m', argv, i)
-            argv[i] = module
-            run_module = True
-            break
-        elif arg.startswith('-W'):
-            warnoptions, i = get_argument('-W', argv, i)
-        elif arg.startswith('--jit'):
-            jitparam, i = get_argument('--jit', argv, i)
-            if 'pypyjit' not in sys.builtin_module_names:
-                print >> sys.stderr, ("Warning: No jit support in %s" %
-                                      (sys.executable,))
-            else:
-                import pypyjit
-                pypyjit.set_param(jitparam)
-        elif arg == '--':
-            i += 1
-            break     # terminates option list    
+    options = default_options.copy()
+    options['warnoptions'] = []
+    #
+    iterargv = iter(argv)
+    argv = None
+    for arg in iterargv:
+        #
+        # If the next argument isn't at least two characters long or
+        # doesn't start with '-', stop processing
+        if len(arg) < 2 or arg[0] != '-':
+            if IS_WINDOWS and arg == '/?':      # special case
+                print_help()
+            argv = [arg] + list(iterargv)    # finishes processing
+        #
+        # If the next argument is directly in cmdline_options, handle
+        # it as a single argument
+        elif arg in cmdline_options:
+            argv = handle_argument(arg, options, iterargv)
+        #
+        # Else interpret the rest of the argument character by character
         else:
-            raise CommandLineError('unrecognized option %r' % (arg,))
-        i += 1
-    sys.argv = argv[i:]
-    if not sys.argv:
-        sys.argv.append('')
-        run_stdin = True
-    return locals()
+            iterarg = iter(arg)
+            iterarg.next()     # skip the '-'
+            for c in iterarg:
+                if c not in cmdline_options:
+                    raise CommandLineError('Unknown option: -%s' % (c,))
+                argv = handle_argument(c, options, iterargv, iterarg)
 
-def run_command_line(go_interactive,
+    if not argv:
+        argv = ['']
+        options["run_stdin"] = True
+    elif argv[0] == '-':
+        options["run_stdin"] = True
+
+    # don't change the list that sys.argv is bound to
+    # (relevant in case of "reload(sys)")
+    sys.argv[:] = argv
+
+    if (options["interactive"] or
+        (not options["ignore_environment"] and os.getenv('PYTHONINSPECT'))):
+        options["inspect"] = True
+
+    if PYTHON26 and we_are_translated():
+        flags = [options[flag] for flag in sys_flags]
+        sys.flags = type(sys.flags)(flags)
+        sys.py3kwarning = sys.flags.py3k_warning
+
+##    if not we_are_translated():
+##        for key in sorted(options):
+##            print '%40s: %s' % (key, options[key])
+##        print '%40s: %s' % ("sys.argv", sys.argv)
+
+    return options
+
+def run_command_line(interactive,
+                     inspect,
                      run_command,
-                     import_site,
+                     no_site,
                      run_module,
                      run_stdin,
                      warnoptions,
                      unbuffered,
-                     cmd=None,
+                     ignore_environment,
                      **ignored):
     # with PyPy in top of CPython we can only have around 100 
-    # but we need more in the translated PyPy for the compiler package 
-    sys.setrecursionlimit(5000)
+    # but we need more in the translated PyPy for the compiler package
+    if '__pypy__' not in sys.builtin_module_names:
+        sys.setrecursionlimit(5000)
 
     if unbuffered:
         set_unbuffered_io()
     mainmodule = type(sys)('__main__')
     sys.modules['__main__'] = mainmodule
 
-    if import_site:
+    if not no_site:
         try:
             import site
         except:
             print >> sys.stderr, "'import site' failed"
 
+    readenv = not ignore_environment
+    pythonwarnings = readenv and os.getenv('PYTHONWARNINGS')
+    if pythonwarnings:
+        warnoptions.extend(pythonwarnings.split(','))
     if warnoptions:
-        sys.warnoptions.append(warnoptions)
+        sys.warnoptions[:] = warnoptions
         from warnings import _processoptions
         _processoptions(sys.warnoptions)
 
             signal.signal(signal.SIGXFSZ, signal.SIG_IGN)
 
     def inspect_requested():
-        # We get an interactive prompt in one of the following two cases:
+        # We get an interactive prompt in one of the following three cases:
         #
-        #     * go_interactive=True, either from the "-i" option or
-        #       from the fact that we printed the banner;
+        #     * interactive=True, from the "-i" option
+        # or
+        #     * inspect=True and stdin is a tty
         # or
         #     * PYTHONINSPECT is set and stdin is a tty.
         #
-        return (go_interactive or
-                (os.getenv('PYTHONINSPECT') and sys.stdin.isatty()))
+        return (interactive or
+                ((inspect or (readenv and os.getenv('PYTHONINSPECT')))
+                 and sys.stdin.isatty()))
 
     success = True
 
     try:
-        if run_command:
+        if run_command != 0:
             # handle the "-c" command
+            # Put '' on sys.path
+            sys.path.insert(0, '')
+
             def run_it():
-                exec cmd in mainmodule.__dict__
+                exec run_command in mainmodule.__dict__
             success = run_toplevel(run_it)
         elif run_module:
             # handle the "-m" command
         elif run_stdin:
             # handle the case where no command/filename/module is specified
             # on the command-line.
-            if go_interactive or sys.stdin.isatty():
+
+            # update sys.path *after* loading site.py, in case there is a
+            # "site.py" file in the script's directory. Only run this if we're
+            # executing the interactive prompt, if we're running a script we
+            # put it's directory on sys.path
+            sys.path.insert(0, '')
+
+            if interactive or sys.stdin.isatty():
                 # If stdin is a tty or if "-i" is specified, we print
                 # a banner and run $PYTHONSTARTUP.
                 print_banner()
-                python_startup = os.getenv('PYTHONSTARTUP')
+                python_startup = readenv and os.getenv('PYTHONSTARTUP')
                 if python_startup:
                     try:
-                        startup = open(python_startup).read()
-                    except IOError:
-                        pass
+                        f = open(python_startup)
+                        startup = f.read()
+                        f.close()
+                    except IOError, e:
+                        print >> sys.stderr, "Could not open PYTHONSTARTUP"
+                        print >> sys.stderr, "IOError:", e
                     else:
                         def run_it():
                             co_python_startup = compile(startup,
                             exec co_python_startup in mainmodule.__dict__
                         run_toplevel(run_it)
                 # Then we need a prompt.
-                go_interactive = True
+                inspect = True
             else:
                 # If not interactive, just read and execute stdin normally.
                 def run_it():
             # on the command-line.
             import installation
             if not sys.argv[0].endswith(".py") and sys.argv[0].find("/") == -1:
+                # scan sys.path for commands submodules
+                # only look for base commands in __builtin__ and those not yet parsed
                 argv = sys.argv[:]
                 argv.insert(0,"")
                 installation.commands.execute(argv)
                 success = True
             else:
-                # scan sys.path for commands submodules
-                # only look for base commands in __builtin__ and those not yet parsed
                 mainmodule.__file__ = sys.argv[0]
                 scriptdir = resolvedirof(sys.argv[0])
                 sys.path.insert(0, scriptdir)
                 success = run_toplevel(execfile, sys.argv[0], mainmodule.__dict__)
 
-        # start a prompt if requested
+    except SystemExit, e:
+        status = e.code
         if inspect_requested():
+            display_exception()
+    else:
+        status = not success
+
+    # start a prompt if requested
+    if inspect_requested():
+        inteactive = False
+        try:
             from _pypy_interact import interactive_console
             success = run_toplevel(interactive_console, mainmodule)
-    except SystemExit, e:
-        return e.code
-    else:
-        return not success
+        except SystemExit, e:
+            status = e.code
+        else:
+            status = not success
+
+    return status
 
 def resolvedirof(filename):
     try:
            '"license" for more information.')
 
 def entry_point(executable, argv, nanos):
-    executable = setup_initial_paths(executable, nanos)
+    setup_sys_executable(executable, nanos)
     try:
         cmdline = parse_command_line(argv)
     except CommandLineError, e:
         print_error(str(e))
         return 2
-    if cmdline is None:
-        return 0
-    else:
-        return run_command_line(**cmdline)
+    except SystemExit, e:
+        return e.code or 0
+    setup_initial_paths(executable,**cmdline)
+    return run_command_line(**cmdline)
 
 
 if __name__ == '__main__':
     # obscure! try removing the following line, see how it crashes, and
     # guess why...
     ImStillAroundDontForgetMe = sys.modules['__main__']
-    sys.ps1 = '>>>> '
-    sys.ps2 = '.... '
 
     # debugging only
     def pypy_initial_path(s):
         except OSError:
             return None
 
-    # debugging only
-    def pypy_structure_exists(paths):
-        from pypy.module.sys.state import structure_exists
-        try:
-            return structure_exists(paths.split(":"))
-        except OSError:
-            return None
-
     # stick the current sys.path into $PYTHONPATH, so that CPython still
     # finds its own extension modules :-/
     import os
     os.environ['PYTHONPATH'] = ':'.join(sys.path)
+    reset = []
+    if 'PYTHONINSPECT_' in os.environ:
+        reset.append(('PYTHONINSPECT', os.environ.get('PYTHONINSPECT', '')))
+        os.environ['PYTHONINSPECT'] = os.environ['PYTHONINSPECT_']
+
+    # no one should change to which lists sys.argv and sys.path are bound
+    old_argv = sys.argv
+    old_path = sys.path
 
     from pypy.module.sys.version import PYPY_VERSION
     sys.pypy_version_info = PYPY_VERSION
     sys.pypy_initial_path = pypy_initial_path
-    sys.pypy_structure_exists = pypy_structure_exists
     os = nanos.os_module_for_testing
-    sys.exit(entry_point(sys.argv[0], sys.argv[1:], os))
-    #sys.exit(entry_point('app_main.py', sys.argv[1:]))
+    try:
+        sys.exit(int(entry_point(sys.argv[0], sys.argv[1:], os)))
+    finally:
+        # restore the normal prompt (which was changed by _pypy_interact), in
+        # case we are dropping to CPython's prompt
+        sys.ps1 = '>>> '
+        sys.ps2 = '... '
+        import os; os.environ.update(reset)
+        assert old_argv is sys.argv
+        assert old_path is sys.path

pypy/translator/goal/targetcommands.py

     w_call_finish_gateway = space.wrap(gateway.interp2app(call_finish))
     w_call_startup_gateway = space.wrap(gateway.interp2app(call_startup))
     w_os = setup_nanos(space)
+    withjit = space.config.objspace.usemodules.pypyjit
 
     def entry_point(argv):
         space.timer.start("Entrypoint")
+        if withjit:
+            from pypy.jit.backend.hlinfo import highleveljitinfo
+            highleveljitinfo.sys_executable = argv[0]
+
         #debug("entry point starting") 
         #for arg in argv: 
         #    debug(" argv -> " + arg)
             ##    con.interact()
             except OperationError, e:
                 debug("OperationError:")
-                debug(" operror-type: " + e.w_type.getname(space, '?'))
+                debug(" operror-type: " + e.w_type.getname(space))
                 debug(" operror-value: " + space.str_w(space.str(e.get_w_value(space))))
                 return 1
         finally:
                 space.timer.stop("space.finish")
             except OperationError, e:
                 debug("OperationError:")
-                debug(" operror-type: " + e.w_type.getname(space, '?'))
+                debug(" operror-type: " + e.w_type.getname(space))
                 debug(" operror-value: " + space.str_w(space.str(e.get_w_value(space))))
                 return 1
         space.timer.stop("Entrypoint")
         if config.objspace.allworkingmodules:
             from pypy.config.pypyoption import enable_allworkingmodules
             enable_allworkingmodules(config)
+        if config.objspace.translationmodules:
+            from pypy.config.pypyoption import enable_translationmodules
+            enable_translationmodules(config)
 
         if config.translation.type_system == 'ootype':
             config.objspace.usemodules.suggest(rbench=True)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.