def setup_initial_paths(executable, nanos): # a substituted os if we are translated global os os = nanos AUTOSUBPATH = 'share' + os.sep + 'pypy-%d.%d' # 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) # set up a sys.path that depends on the local machine autosubpath = AUTOSUBPATH % sys.pypy_version_info[:2] 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: newpath = sys.pypy_initial_path(os.path.join(dirname, autosubpath)) if newpath is None: search = dirname # walk to the parent directory continue break # found! path = os.getenv('PYTHONPATH') if path: newpath = path.split(os.pathsep) + newpath newpath.insert(0, '') # remove duplicates _seen = {} del sys.path[:] for dir in newpath: if dir not in _seen: sys.path.append(dir) _seen[dir] = True return executable
def setup_initial_paths(executable, nanos): # a substituted os if we are translated global os os = nanos AUTOSUBPATH = 'share' + os.sep + 'pypy-%d.%d' # 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) # set up a sys.path that depends on the local machine autosubpath = AUTOSUBPATH % sys.pypy_version_info[:2] 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: newpath = sys.pypy_initial_path(os.path.join(dirname, autosubpath)) if newpath is None: search = dirname # walk to the parent directory continue break # found! path = os.getenv('PYTHONPATH') if path: newpath = path.split(os.pathsep) + newpath newpath.insert(0, '') # remove duplicates _seen = {} sys.path = [] for dir in newpath: if dir not in _seen: sys.path.append(dir) _seen[dir] = True return executable
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. debug: WARNING: 'sys.prefix' will not be set. debug: WARNING: Make sure the pypy binary is kept inside its tree of files. debug: WARNING: It is ok to create a symlink to it from somewhere else.""" 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 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. debug: WARNING: 'sys.prefix' will not be set. debug: WARNING: Make sure the pypy binary is kept inside its tree of files. debug: WARNING: It is ok to create a symlink to it from somewhere else.""" 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 entry_point(executable, argv): # 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 os.sep not in executable: 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) # set up a sys.path that depends on the local machine autosubpath = AUTOSUBPATH % sys.pypy_version_info[:2] 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') break newpath = sys.pypy_initial_path(dirname) if newpath is None: newpath = sys.pypy_initial_path(os.path.join(dirname, autosubpath)) if newpath is None: search = dirname # walk to the parent directory continue sys.path = newpath # found! break go_interactive = False run_command = False import_site = True i = 0 run_module = False run_stdin = False while i < len(argv): arg = argv[i] if not arg.startswith('-'): break if arg == '-i': go_interactive = True elif arg == '-c': if i+1 >= len(argv): print_error('Argument expected for the -c option') return 2 run_command = True break elif arg == '-u': set_unbuffered_io() elif arg == '-O': pass elif arg == '--version': print sys.version return 0 elif arg == '--info': print_info() return 0 elif arg == '-h' or arg == '--help': print_help() return 0 elif arg == '-S': import_site = False elif arg == '-': run_stdin = True break # not an option but a file name representing stdin elif arg == '-m': i += 1 if i >= len(argv): print_error('Argument expected for the -m option') return 2 run_module = True break elif arg == '--': i += 1 break # terminates option list else: print_error('unrecognized option %r' % (arg,)) return 2 i += 1 sys.argv = argv[i:] if not sys.argv: sys.argv.append('') run_stdin = True # 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) mainmodule = type(sys)('__main__') sys.modules['__main__'] = mainmodule if import_site: try: import site except: print >> sys.stderr, "'import site' failed" # set up the Ctrl-C => KeyboardInterrupt signal handler, if the # signal module is available try: import signal except ImportError: pass else: signal.signal(signal.SIGINT, signal.default_int_handler) if hasattr(signal, "SIGPIPE"): signal.signal(signal.SIGPIPE, signal.SIG_IGN) def is_interactive(): return go_interactive or os.getenv('PYTHONINSPECT') success = True try: if run_command: cmd = sys.argv.pop(1) def run_it(): exec cmd in mainmodule.__dict__ success = run_toplevel(run_it) elif run_module: def run_it(): import runpy runpy.run_module(sys.argv[0], None, '__main__', True) success = run_toplevel(run_it) elif run_stdin: if is_interactive() or sys.stdin.isatty(): print_banner() python_startup = os.getenv('PYTHONSTARTUP') if python_startup: try: startup = open(python_startup).read() except IOError: pass else: def run_it(): co_python_startup = compile(startup, python_startup, 'exec') exec co_python_startup in mainmodule.__dict__ run_toplevel(run_it) go_interactive = True else: def run_it(): co_stdin = compile(sys.stdin.read(), '<stdin>', 'exec') exec co_stdin in mainmodule.__dict__ mainmodule.__file__ = '<stdin>' success = run_toplevel(run_it) else: mainmodule.__file__ = sys.argv[0] scriptdir = resolvedirof(sys.argv[0]) sys.path.insert(0, scriptdir) success = run_toplevel(execfile, sys.argv[0], mainmodule.__dict__) if is_interactive(): try: import _curses import termios from pyrepl.python_reader import main from pyrepl import cmdrepl #import pdb #pdb.Pdb = cmdrepl.replize(pdb.Pdb, 1) except ImportError: success = run_toplevel(interactive_console, mainmodule) else: main(print_banner=False) success = True except SystemExit, e: return e.code
def entry_point(executable, argv, nanos): # a substituted os if we are translated global os os = nanos AUTOSUBPATH = 'share' + os.sep + 'pypy-%d.%d' # 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) # set up a sys.path that depends on the local machine autosubpath = AUTOSUBPATH % sys.pypy_version_info[:2] 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') break newpath = sys.pypy_initial_path(dirname) if newpath is None: newpath = sys.pypy_initial_path(os.path.join(dirname, autosubpath)) if newpath is None: search = dirname # walk to the parent directory continue sys.path = newpath # found! break go_interactive = False run_command = False import_site = True i = 0 run_module = False run_stdin = False oldstyle_classes = False while i < len(argv): arg = argv[i] if not arg.startswith('-'): break if arg == '-i': go_interactive = True elif arg == '-c': if i+1 >= len(argv): print_error('Argument expected for the -c option') return 2 run_command = True break elif arg == '-u': set_unbuffered_io() elif arg == '-O': pass elif arg == '--version': print sys.version return 0 elif arg == '--info': print_info() return 0 elif arg == '-h' or arg == '--help': print_help() return 0 elif arg == '-S': import_site = False elif arg == '-': run_stdin = True break # not an option but a file name representing stdin elif arg == '-m': i += 1 if i >= len(argv): print_error('Argument expected for the -m option') return 2 run_module = True break elif arg in ('-k', '--oldstyle'): oldstyle_classes = True elif arg == '--': i += 1 break # terminates option list else: print_error('unrecognized option %r' % (arg,)) return 2 i += 1 sys.argv = argv[i:] if not sys.argv: sys.argv.append('') run_stdin = True # 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) mainmodule = type(sys)('__main__') sys.modules['__main__'] = mainmodule if oldstyle_classes: import __builtin__ __builtin__.__metaclass__ = __builtin__._classobj if import_site: try: import site except: print >> sys.stderr, "'import site' failed" # set up the Ctrl-C => KeyboardInterrupt signal handler, if the # signal module is available try: import signal except ImportError: pass else: signal.signal(signal.SIGINT, signal.default_int_handler) if hasattr(signal, "SIGPIPE"): signal.signal(signal.SIGPIPE, signal.SIG_IGN) def is_interactive(): return go_interactive or os.getenv('PYTHONINSPECT') success = True try: if run_command: cmd = sys.argv.pop(1) def run_it(): exec cmd in mainmodule.__dict__ success = run_toplevel(run_it) elif run_module: def run_it(): import runpy runpy.run_module(sys.argv[0], None, '__main__', True) success = run_toplevel(run_it) elif run_stdin: if is_interactive() or sys.stdin.isatty(): print_banner() python_startup = os.getenv('PYTHONSTARTUP') if python_startup: try: startup = open(python_startup).read() except IOError: pass else: def run_it(): co_python_startup = compile(startup, python_startup, 'exec') exec co_python_startup in mainmodule.__dict__ run_toplevel(run_it) go_interactive = True else: def run_it(): co_stdin = compile(sys.stdin.read(), '<stdin>', 'exec') exec co_stdin in mainmodule.__dict__ mainmodule.__file__ = '<stdin>' success = run_toplevel(run_it) else: mainmodule.__file__ = sys.argv[0] scriptdir = resolvedirof(sys.argv[0]) sys.path.insert(0, scriptdir) success = run_toplevel(execfile, sys.argv[0], mainmodule.__dict__) if is_interactive(): try: import _curses import termios from pyrepl.python_reader import main from pyrepl import cmdrepl #import pdb #pdb.Pdb = cmdrepl.replize(pdb.Pdb, 1) except ImportError: success = run_toplevel(interactive_console, mainmodule) else: main(print_banner=False, clear_main=False) success = True except SystemExit, e: return e.code
def entry_point(executable, argv, nanos): # a substituted os if we are translated global os os = nanos AUTOSUBPATH = 'share' + os.sep + 'pypy-%d.%d' # 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) # set up a sys.path that depends on the local machine autosubpath = AUTOSUBPATH % sys.pypy_version_info[:2] 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: newpath = sys.pypy_initial_path(os.path.join(dirname, autosubpath)) if newpath is None: search = dirname # walk to the parent directory continue break # found! path = os.getenv('PYTHONPATH') if path: newpath = path.split(os.pathsep) + newpath newpath.insert(0, '') # remove duplicates _seen = {} sys.path = [] for dir in newpath: if dir not in _seen: sys.path.append(dir) _seen[dir] = True del newpath, _seen go_interactive = False run_command = False import_site = True i = 0 run_module = False run_stdin = False unbuffered = False while i < len(argv): arg = argv[i] if not arg.startswith('-'): break if arg == '-i': go_interactive = True elif arg == '-c': if i + 1 >= len(argv): print_error('Argument expected for the -c option') return 2 run_command = True break elif arg == '-u': unbuffered = True elif arg == '-O': pass elif arg == '--version': print sys.version return 0 elif arg == '--info': print_info() return 0 elif arg == '-h' or arg == '--help': print_help() return 0 elif arg == '-S': import_site = False elif arg == '-': run_stdin = True break # not an option but a file name representing stdin elif arg == '-m': i += 1 if i >= len(argv): print_error('Argument expected for the -m option') return 2 run_module = True break elif arg == '--': i += 1 break # terminates option list else: print_error('unrecognized option %r' % (arg, )) return 2 i += 1 sys.argv = argv[i:] if not sys.argv: sys.argv.append('') run_stdin = True # 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) if unbuffered: set_unbuffered_io() elif not sys.stdout.isatty(): set_fully_buffered_io() mainmodule = type(sys)('__main__') sys.modules['__main__'] = mainmodule if import_site: try: import site except: print >> sys.stderr, "'import site' failed" # set up the Ctrl-C => KeyboardInterrupt signal handler, if the # signal module is available try: import signal except ImportError: pass else: signal.signal(signal.SIGINT, signal.default_int_handler) if hasattr(signal, "SIGPIPE"): signal.signal(signal.SIGPIPE, signal.SIG_IGN) if hasattr(signal, 'SIGXFZ'): signal.signal(signal.SIGXFZ, signal.SIG_IGN) if hasattr(signal, 'SIGXFSZ'): signal.signal(signal.SIGXFSZ, signal.SIG_IGN) def inspect_requested(): # We get an interactive prompt in one of the following two cases: # # * go_interactive=True, either from the "-i" option or # from the fact that we printed the banner; # or # * PYTHONINSPECT is set and stdin is a tty. # return (go_interactive or (os.getenv('PYTHONINSPECT') and sys.stdin.isatty())) success = True try: if run_command: # handle the "-c" command cmd = sys.argv.pop(1) def run_it(): exec cmd in mainmodule.__dict__ success = run_toplevel(run_it) elif run_module: # handle the "-m" command def run_it(): import runpy runpy.run_module(sys.argv[0], None, '__main__', True) success = run_toplevel(run_it) elif run_stdin: # handle the case where no command/filename/module is specified # on the command-line. if go_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') if python_startup: try: startup = open(python_startup).read() except IOError: pass else: def run_it(): co_python_startup = compile( startup, python_startup, 'exec') exec co_python_startup in mainmodule.__dict__ run_toplevel(run_it) # Then we need a prompt. go_interactive = True else: # If not interactive, just read and execute stdin normally. def run_it(): co_stdin = compile(sys.stdin.read(), '<stdin>', 'exec') exec co_stdin in mainmodule.__dict__ mainmodule.__file__ = '<stdin>' success = run_toplevel(run_it) else: # handle the common case where a filename is specified # on the command-line. 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 if inspect_requested(): from _pypy_interact import interactive_console success = run_toplevel(interactive_console, mainmodule) except SystemExit, e: return e.code