Exemple #1
0
 def pypy_setup_home(ll_home, verbose):
     from pypy.module.sys.initpath import pypy_find_stdlib
     verbose = rffi.cast(lltype.Signed, verbose)
     if ll_home:
         home = rffi.charp2str(ll_home)
     else:
         home = pypydir
     w_path = pypy_find_stdlib(space, home)
     if space.is_none(w_path):
         if verbose:
             debug("Failed to find library based on pypy_find_stdlib")
         return rffi.cast(rffi.INT, 1)
     space.startup()
     space.call_function(w_pathsetter, w_path)
     # import site
     try:
         import_ = space.getattr(space.getbuiltinmodule('__builtin__'),
                                 space.wrap('__import__'))
         space.call_function(import_, space.wrap('site'))
         return rffi.cast(rffi.INT, 0)
     except OperationError, e:
         if verbose:
             debug("OperationError:")
             debug(" operror-type: " + e.w_type.getname(space))
             debug(" operror-value: " + space.str_w(space.str(e.get_w_value(space))))
         return rffi.cast(rffi.INT, -1)
 def pypy_setup_home(ll_home, verbose):
     from pypy.module.sys.initpath import pypy_find_stdlib
     verbose = rffi.cast(lltype.Signed, verbose)
     if ll_home:
         home1 = rffi.charp2str(ll_home)
         home = os.path.join(home1, 'x') # <- so that 'll_home' can be
                                         # directly the root directory
     else:
         home = home1 = pypydir
     w_path = pypy_find_stdlib(space, home)
     if space.is_none(w_path):
         if verbose:
             debug("pypy_setup_home: directories 'lib-python' and 'lib_pypy'"
                   " not found in '%s' or in any parent directory" % home1)
         return rffi.cast(rffi.INT, 1)
     space.startup()
     space.call_function(w_pathsetter, w_path)
     # import site
     try:
         space.setattr(space.getbuiltinmodule('sys'),
                       space.wrap('executable'),
                       space.wrap(home))
         import_ = space.getattr(space.getbuiltinmodule('__builtin__'),
                                 space.wrap('__import__'))
         space.call_function(import_, space.wrap('site'))
         return rffi.cast(rffi.INT, 0)
     except OperationError, e:
         if verbose:
             debug("OperationError:")
             debug(" operror-type: " + e.w_type.getname(space))
             debug(" operror-value: " + space.str_w(space.str(e.get_w_value(space))))
         return rffi.cast(rffi.INT, -1)
Exemple #3
0
 def pypy_setup_home(ll_home, verbose):
     from pypy.module.sys.initpath import pypy_find_stdlib
     verbose = rffi.cast(lltype.Signed, verbose)
     if ll_home:
         home1 = rffi.charp2str(ll_home)
         home = os.path.join(home1, 'x') # <- so that 'll_home' can be
                                         # directly the root directory
     else:
         home = home1 = pypydir
     w_path = pypy_find_stdlib(space, home)
     if space.is_none(w_path):
         if verbose:
             debug("pypy_setup_home: directories 'lib-python' and 'lib_pypy'"
                   " not found in '%s' or in any parent directory" % home1)
         return rffi.cast(rffi.INT, 1)
     space.startup()
     space.appexec([w_path], """(path):
         import sys
         sys.path[:] = path
     """)
     # import site
     try:
         space.setattr(space.getbuiltinmodule('sys'),
                       space.wrap('executable'),
                       space.wrap(home))
         import_ = space.getattr(space.getbuiltinmodule('__builtin__'),
                                 space.wrap('__import__'))
         space.call_function(import_, space.wrap('site'))
         return rffi.cast(rffi.INT, 0)
     except OperationError, e:
         if verbose:
             debug("OperationError:")
             debug(" operror-type: " + e.w_type.getname(space))
             debug(" operror-value: " + space.str_w(space.str(e.get_w_value(space))))
         return rffi.cast(rffi.INT, -1)
 def pypy_setup_home(ll_home, verbose):
     from pypy.module.sys.initpath import pypy_find_stdlib
     verbose = rffi.cast(lltype.Signed, verbose)
     if ll_home:
         home = rffi.charp2str(ll_home)
     else:
         home = pypydir
     w_path = pypy_find_stdlib(space, home)
     if space.is_none(w_path):
         if verbose:
             debug("Failed to find library based on pypy_find_stdlib")
         return rffi.cast(rffi.INT, 1)
     space.startup()
     space.call_function(w_pathsetter, w_path)
     # import site
     try:
         space.setattr(space.getbuiltinmodule('sys'),
                       space.wrap('executable'), space.wrap(home))
         import_ = space.getattr(space.getbuiltinmodule('__builtin__'),
                                 space.wrap('__import__'))
         space.call_function(import_, space.wrap('site'))
         return rffi.cast(rffi.INT, 0)
     except OperationError, e:
         if verbose:
             debug("OperationError:")
             debug(" operror-type: " + e.w_type.getname(space))
             debug(" operror-value: " +
                   space.str_w(space.str(e.get_w_value(space))))
         return rffi.cast(rffi.INT, -1)
Exemple #5
0
 def pypy_setup_home(ll_home, verbose):
     from pypy.module.sys.initpath import pypy_find_stdlib
     verbose = rffi.cast(lltype.Signed, verbose)
     if ll_home and ord(ll_home[0]):
         home1 = rffi.charp2str(ll_home)
         home = os.path.join(home1, 'x')  # <- so that 'll_home' can be
         # directly the root directory
     else:
         home1 = "pypy's shared library location"
         home = '*'
     w_path = pypy_find_stdlib(space, home)
     if space.is_none(w_path):
         if verbose:
             debug(
                 "pypy_setup_home: directories 'lib-python' and 'lib_pypy'"
                 " not found in %s or in any parent directory" % home1)
         return rffi.cast(rffi.INT, 1)
     space.startup()
     must_leave = space.threadlocals.try_enter_thread(space)
     try:
         # initialize sys.{path,executable,stdin,stdout,stderr}
         # (in unbuffered mode, to avoid troubles) and import site
         space.appexec(
             [w_path, space.newfilename(home), w_initstdio],
             r"""(path, home, initstdio):
             import sys 
             # don't import anything more above this: sys.path is not set
             sys.path[:] = path
             sys.executable = home
             initstdio(unbuffered=True)
             import os   # don't move it to the first line of this function!
             _MACOSX = sys.platform == 'darwin'
             if _MACOSX:
                 # __PYVENV_LAUNCHER__, used by CPython on macOS, should be ignored
                 # since it (possibly) results in a wrong sys.prefix and
                 # sys.exec_prefix (and consequently sys.path).
                 old_pyvenv_launcher = os.environ.pop('__PYVENV_LAUNCHER__', None)
             try:
                 import site
             except Exception as e:
                 sys.stderr.write("'import site' failed:\n")
                 import traceback
                 traceback.print_exc()
             if _MACOSX and old_pyvenv_launcher:
                 os.environ['__PYVENV_LAUNCHER__'] = old_pyvenv_launcher
         """)
         return rffi.cast(rffi.INT, 0)
     except OperationError as e:
         if verbose:
             debug("OperationError:")
             debug(" operror-type: " + e.w_type.getname(space))
             debug(" operror-value: " +
                   space.text_w(space.str(e.get_w_value(space))))
         return rffi.cast(rffi.INT, -1)
     finally:
         if must_leave:
             space.threadlocals.leave_thread(space)
 def pypy_setup_home(ll_home, verbose):
     from pypy.module.sys.initpath import pypy_find_stdlib
     verbose = rffi.cast(lltype.Signed, verbose)
     if ll_home and ord(ll_home[0]):
         home1 = rffi.charp2str(ll_home)
         home = join(home1, 'x')  # <- so that 'll_home' can be
         # directly the root directory
     else:
         home1 = "pypy's shared library location"
         home = '*'
     w_path = pypy_find_stdlib(space, home)
     if space.is_none(w_path):
         if verbose:
             debug(
                 "pypy_setup_home: directories 'lib-python' and 'lib_pypy'"
                 " not found in %s or in any parent directory" % home1)
         return rffi.cast(rffi.INT, 1)
     space.startup()
     must_leave = space.threadlocals.try_enter_thread(space)
     try:
         # initialize sys.{path,executable,stdin,stdout,stderr}
         # (in unbuffered mode, to avoid troubles) and import site
         space.appexec([w_path, space.newtext(home), w_initstdio],
                       r"""(path, home, initstdio):
             import sys
             # don't import anything more above this: sys.path is not set
             sys.path[:] = path
             sys.executable = home
             initstdio(unbuffered=True)
             try:
                 import site
             except Exception as e:
                 sys.stderr.write("'import site' failed:\n")
                 import traceback
                 traceback.print_exc()
         """)
         return rffi.cast(rffi.INT, 0)
     except OperationError as e:
         if verbose:
             debug("OperationError:")
             debug(" operror-type: " + e.w_type.getname(space))
             debug(" operror-value: " +
                   space.text_w(space.str(e.get_w_value(space))))
         return rffi.cast(rffi.INT, -1)
     finally:
         if must_leave:
             space.threadlocals.leave_thread(space)
 def pypy_setup_home(ll_home, verbose):
     from pypy.module.sys.initpath import pypy_find_stdlib
     verbose = rffi.cast(lltype.Signed, verbose)
     if ll_home and ord(ll_home[0]):
         home1 = rffi.charp2str(ll_home)
         home = os.path.join(home1, 'x') # <- so that 'll_home' can be
                                         # directly the root directory
     else:
         home1 = "pypy's shared library location"
         home = '*'
     w_path = pypy_find_stdlib(space, home)
     if space.is_none(w_path):
         if verbose:
             debug("pypy_setup_home: directories 'lib-python' and 'lib_pypy'"
                   " not found in %s or in any parent directory" % home1)
         return rffi.cast(rffi.INT, 1)
     space.startup()
     must_leave = space.threadlocals.try_enter_thread(space)
     try:
         # initialize sys.{path,executable,stdin,stdout,stderr}
         # (in unbuffered mode, to avoid troubles) and import site
         space.appexec([w_path, space.wrap(home), w_initstdio],
         r"""(path, home, initstdio):
             import sys
             sys.path[:] = path
             sys.executable = home
             initstdio(unbuffered=True)
             try:
                 import site
             except Exception as e:
                 sys.stderr.write("'import site' failed:\n")
                 import traceback
                 traceback.print_exc()
         """)
         return rffi.cast(rffi.INT, 0)
     except OperationError as e:
         if verbose:
             debug("OperationError:")
             debug(" operror-type: " + e.w_type.getname(space))
             debug(" operror-value: " + space.str_w(space.str(e.get_w_value(space))))
         return rffi.cast(rffi.INT, -1)
     finally:
         if must_leave:
             space.threadlocals.leave_thread(space)