当前位置: 首页>>代码示例>>Python>>正文


Python PythonInterpreter.from_binary方法代码示例

本文整理汇总了Python中pex.interpreter.PythonInterpreter.from_binary方法的典型用法代码示例。如果您正苦于以下问题:Python PythonInterpreter.from_binary方法的具体用法?Python PythonInterpreter.from_binary怎么用?Python PythonInterpreter.from_binary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pex.interpreter.PythonInterpreter的用法示例。


在下文中一共展示了PythonInterpreter.from_binary方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: find_compatible_interpreters

# 需要导入模块: from pex.interpreter import PythonInterpreter [as 别名]
# 或者: from pex.interpreter.PythonInterpreter import from_binary [as 别名]
def find_compatible_interpreters(pex_python_path=None, compatibility_constraints=None):
  """Find all compatible interpreters on the system within the supplied constraints and use
     PEX_PYTHON_PATH if it is set. If not, fall back to interpreters on $PATH.
  """
  if pex_python_path:
    interpreters = []
    for binary in pex_python_path.split(os.pathsep):
      try:
        interpreters.append(PythonInterpreter.from_binary(binary))
      except Executor.ExecutionError:
        print("Python interpreter %s in PEX_PYTHON_PATH failed to load properly." % binary,
          file=sys.stderr)
    if not interpreters:
      die('PEX_PYTHON_PATH was defined, but no valid interpreters could be identified. Exiting.')
  else:
    # We may have been invoked with a specific interpreter not on the $PATH, make sure our
    # sys.executable is included as a candidate in this case.
    interpreters = OrderedSet([PythonInterpreter.get()])

    # Add all qualifying interpreters found in $PATH.
    interpreters.update(PythonInterpreter.all())

  return list(
    matched_interpreters(interpreters, compatibility_constraints)
    if compatibility_constraints
    else interpreters
  )
开发者ID:jsirois,项目名称:pex,代码行数:29,代码来源:pex_bootstrapper.py

示例2: to_python_interpreter

# 需要导入模块: from pex.interpreter import PythonInterpreter [as 别名]
# 或者: from pex.interpreter.PythonInterpreter import from_binary [as 别名]
 def to_python_interpreter(full_path_or_basename):
   if os.path.exists(full_path_or_basename):
     return PythonInterpreter.from_binary(full_path_or_basename)
   else:
     interpreter = PythonInterpreter.from_env(full_path_or_basename)
     if interpreter is None:
       die('Failed to find interpreter: %s' % full_path_or_basename)
     return interpreter
开发者ID:jsirois,项目名称:pex,代码行数:10,代码来源:pex.py

示例3: _validate_good_interpreter_path_file

# 需要导入模块: from pex.interpreter import PythonInterpreter [as 别名]
# 或者: from pex.interpreter.PythonInterpreter import from_binary [as 别名]
 def _validate_good_interpreter_path_file(path):
   with open(path, 'r') as fp:
     lines = fp.readlines()
     binary = lines[0].strip()
     try:
       interpreter = PythonInterpreter.from_binary(binary)
       return True if interpreter else False
     except Executor.ExecutableNotFound:
       return False
开发者ID:cosmicexplorer,项目名称:pants,代码行数:11,代码来源:test_interpreter_selection_integration.py

示例4: _interpreter_from_path

# 需要导入模块: from pex.interpreter import PythonInterpreter [as 别名]
# 或者: from pex.interpreter.PythonInterpreter import from_binary [as 别名]
 def _interpreter_from_path(self, path, filters):
   try:
     executable = os.readlink(os.path.join(path, 'python'))
   except OSError:
     return None
   interpreter = PythonInterpreter.from_binary(executable, include_site_extras=False)
   if self._matches(interpreter, filters):
     return self._resolve(interpreter)
   return None
开发者ID:foursquare,项目名称:pants,代码行数:11,代码来源:interpreter_cache.py

示例5: _get_interpreter

# 需要导入模块: from pex.interpreter import PythonInterpreter [as 别名]
# 或者: from pex.interpreter.PythonInterpreter import from_binary [as 别名]
 def _get_interpreter(interpreter_path_file):
   with open(interpreter_path_file, 'r') as infile:
     lines = infile.readlines()
     binary = lines[0].strip()
     interpreter = PythonInterpreter.from_binary(binary, include_site_extras=False)
     for line in lines[1:]:
       dist_name, dist_version, location = line.strip().split('\t')
       interpreter = interpreter.with_extra(dist_name, dist_version, location)
     return interpreter
开发者ID:foursquare,项目名称:pants,代码行数:11,代码来源:select_interpreter.py

示例6: fake_interpreter

# 需要导入模块: from pex.interpreter import PythonInterpreter [as 别名]
# 或者: from pex.interpreter.PythonInterpreter import from_binary [as 别名]
    def fake_interpreter(id_str):
      interpreter_dir = safe_mkdtemp()
      binary = os.path.join(interpreter_dir, 'binary')
      with open(binary, 'w') as fp:
        fp.write(dedent("""
        #!{}
        from __future__ import print_function

        print({!r})
        """.format(PythonInterpreter.get().binary, id_str)).strip())
      chmod_plus_x(binary)
      return PythonInterpreter.from_binary(binary)
开发者ID:baroquebobcat,项目名称:pants,代码行数:14,代码来源:test_select_interpreter.py

示例7: create_bare_interpreter

# 需要导入模块: from pex.interpreter import PythonInterpreter [as 别名]
# 或者: from pex.interpreter.PythonInterpreter import from_binary [as 别名]
def create_bare_interpreter(binary_path):
  """Creates an interpreter for python binary at the given path.

  The interpreter is bare in that it has no extras associated with it.

  :returns: A bare python interpreter with no extras.
  :rtype: :class:`pex.interpreter.PythonInterpreter`
  """
  # TODO(John Sirois): Replace with a more direct PythonInterpreter construction API call when
  # https://github.com/pantsbuild/pex/issues/510 is fixed.
  interpreter_with_extras = PythonInterpreter.from_binary(binary_path)
  return PythonInterpreter(binary_path, interpreter_with_extras.identity, extras=None)
开发者ID:baroquebobcat,项目名称:pants,代码行数:14,代码来源:pex_util.py

示例8: interpreter_from_options

# 需要导入模块: from pex.interpreter import PythonInterpreter [as 别名]
# 或者: from pex.interpreter.PythonInterpreter import from_binary [as 别名]
def interpreter_from_options(options):
  interpreter = None
  if options.python:
    if os.path.exists(options.python):
      interpreter = PythonInterpreter.from_binary(options.python)
    else:
      interpreter = PythonInterpreter.from_env(options.python)
    if interpreter is None:
      die('Failed to find interpreter: %s' % options.python)
  else:
    interpreter = PythonInterpreter.get()
  return interpreter
开发者ID:Yasumoto,项目名称:pex,代码行数:14,代码来源:pex.py

示例9: _interpreter_from_relpath

# 需要导入模块: from pex.interpreter import PythonInterpreter [as 别名]
# 或者: from pex.interpreter.PythonInterpreter import from_binary [as 别名]
 def _interpreter_from_relpath(self, path, filters=()):
   path = os.path.join(self._cache_dir, path)
   try:
     executable = os.readlink(os.path.join(path, 'python'))
     if not os.path.exists(executable):
       self._purge_interpreter(path)
       return None
   except OSError:
     return None
   interpreter = PythonInterpreter.from_binary(executable)
   if self._matches(interpreter, filters=filters):
     return interpreter
   return None
开发者ID:cosmicexplorer,项目名称:pants,代码行数:15,代码来源:interpreter_cache.py

示例10: _get_interpreter

# 需要导入模块: from pex.interpreter import PythonInterpreter [as 别名]
# 或者: from pex.interpreter.PythonInterpreter import from_binary [as 别名]
 def _get_interpreter(self, interpreter_path_file, targets):
   if os.path.exists(interpreter_path_file):
     with open(interpreter_path_file, 'r') as infile:
       binary = infile.read().strip()
     try:
       return PythonInterpreter.from_binary(binary)
     except Executor.ExecutableNotFound:
       # TODO(John Sirois): Trap a more appropriate exception once available:
       #  https://github.com/pantsbuild/pex/issues/672
       self.context.log.info('Stale interpreter reference detected: {}, removing reference and '
                             'selecting a new interpreter.'.format(binary))
       os.remove(interpreter_path_file)
   return self._select_interpreter(interpreter_path_file, targets)
开发者ID:cosmicexplorer,项目名称:pants,代码行数:15,代码来源:select_interpreter.py

示例11: _select_pex_python_interpreter

# 需要导入模块: from pex.interpreter import PythonInterpreter [as 别名]
# 或者: from pex.interpreter.PythonInterpreter import from_binary [as 别名]
def _select_pex_python_interpreter(target_python, compatibility_constraints=None):
  target = find_in_path(target_python)

  if not target:
    die('Failed to find interpreter specified by PEX_PYTHON: %s' % target)
  if compatibility_constraints:
    pi = PythonInterpreter.from_binary(target)
    if not list(matched_interpreters([pi], compatibility_constraints)):
      die('Interpreter specified by PEX_PYTHON (%s) is not compatible with specified '
          'interpreter constraints: %s' % (target, str(compatibility_constraints)))
  if not os.path.exists(target):
    die('Target interpreter specified by PEX_PYTHON %s does not exist. Exiting.' % target)
  return target
开发者ID:jsirois,项目名称:pex,代码行数:15,代码来源:pex_bootstrapper.py

示例12: _establish_interpreter

# 需要导入模块: from pex.interpreter import PythonInterpreter [as 别名]
# 或者: from pex.interpreter.PythonInterpreter import from_binary [as 别名]
def _establish_interpreter(args):
    if args.python:
        if os.path.exists(args.python):
            interpreter = PythonInterpreter.from_binary(args.python)
        else:
            interpreter = PythonInterpreter.from_env(args.python)
        if interpreter is None:
            die('Failed to find interpreter: %s' % args.python)
    else:
        interpreter = PythonInterpreter.get()

    with TRACER.timed('Setting up interpreter %s' % interpreter.binary, V=2):
        resolve = functools.partial(resolve_interpreter, args.interpreter_cache_dir, args.repos)

        # resolve setuptools
        interpreter = resolve(interpreter, SETUPTOOLS_REQUIREMENT)

        # possibly resolve wheel
        if interpreter and args.use_wheel:
            interpreter = resolve(interpreter, WHEEL_REQUIREMENT)

        return interpreter
开发者ID:GregBowyer,项目名称:spex,代码行数:24,代码来源:spex.py

示例13: interpreter_from_options

# 需要导入模块: from pex.interpreter import PythonInterpreter [as 别名]
# 或者: from pex.interpreter.PythonInterpreter import from_binary [as 别名]
def interpreter_from_options(options):
    interpreter = None

    if options.python:
        if os.path.exists(options.python):
            interpreter = PythonInterpreter.from_binary(options.python)
        else:
            interpreter = PythonInterpreter.from_env(options.python)
        if interpreter is None:
            die("Failed to find interpreter: %s" % options.python)
    else:
        interpreter = PythonInterpreter.get()

    with TRACER.timed("Setting up interpreter %s" % interpreter.binary, V=2):
        resolve = functools.partial(resolve_interpreter, options.interpreter_cache_dir, options.repos)

        # resolve setuptools
        interpreter = resolve(interpreter, SETUPTOOLS_REQUIREMENT)

        # possibly resolve wheel
        if interpreter and options.use_wheel:
            interpreter = resolve(interpreter, WHEEL_REQUIREMENT)

        return interpreter
开发者ID:twitter,项目名称:heron,代码行数:26,代码来源:pex.py

示例14: get_interpreter

# 需要导入模块: from pex.interpreter import PythonInterpreter [as 别名]
# 或者: from pex.interpreter.PythonInterpreter import from_binary [as 别名]
def get_interpreter(python_interpreter, interpreter_cache_dir, repos, use_wheel):
  interpreter = None

  if python_interpreter:
    if os.path.exists(python_interpreter):
      interpreter = PythonInterpreter.from_binary(python_interpreter)
    else:
      interpreter = PythonInterpreter.from_env(python_interpreter)
    if interpreter is None:
      die('Failed to find interpreter: %s' % python_interpreter)
  else:
    interpreter = PythonInterpreter.get()

  with TRACER.timed('Setting up interpreter %s' % interpreter.binary, V=2):
    resolve = functools.partial(resolve_interpreter, interpreter_cache_dir, repos)

    # resolve setuptools
    interpreter = resolve(interpreter, SETUPTOOLS_REQUIREMENT)

    # possibly resolve wheel
    if interpreter and use_wheel:
      interpreter = resolve(interpreter, WHEEL_REQUIREMENT)

    return interpreter
开发者ID:sixninetynine,项目名称:pex,代码行数:26,代码来源:pex.py

示例15: main

# 需要导入模块: from pex.interpreter import PythonInterpreter [as 别名]
# 或者: from pex.interpreter.PythonInterpreter import from_binary [as 别名]
def main():
    parser = optparse.OptionParser(usage="usage: %prog [options] output")
    parser.add_option('--entry-point', default='__main__')
    parser.add_option('--no-zip-safe', action='store_false', dest='zip_safe', default=True)
    parser.add_option('--python', default=sys.executable)
    parser.add_option('--preload', action='append', default=[])
    options, args = parser.parse_args()
    if len(args) == 1:
        output = args[0]
    else:
        parser.error("'output' positional argument is required")
        return 1

    # The manifest is passed via stdin, as it can sometimes get too large
    # to be passed as a CLA.
    manifest = json.load(sys.stdin)

    # Setup a temp dir that the PEX builder will use as its scratch dir.
    tmp_dir = tempfile.mkdtemp()
    try:

        # The version of pkg_resources.py (from setuptools) on some distros is
        # too old for PEX.  So we keep a recent version in the buck repo and
        # force it into the process by constructing a custom PythonInterpreter
        # instance using it.
        interpreter = PythonInterpreter(
            options.python,
            PythonInterpreter.from_binary(options.python).identity,
            extras={})

        pex_builder = PEXBuilder(
            path=tmp_dir,
            interpreter=interpreter,
        )

        # Set whether this PEX as zip-safe, meaning everything will stayed zipped up
        # and we'll rely on python's zip-import mechanism to load modules from
        # the PEX.  This may not work in some situations (e.g. native
        # libraries, libraries that want to find resources via the FS).
        pex_builder.info.zip_safe = options.zip_safe

        # Set the starting point for this PEX.
        pex_builder.info.entry_point = options.entry_point

        # Copy in our version of `pkg_resources` & `_markerlib`.
        copy_package(pex_builder, 'pkg_resources', prefix=pex_builder.BOOTSTRAP_DIR)
        copy_package(pex_builder, '_markerlib', prefix=pex_builder.BOOTSTRAP_DIR)

        # Add the sources listed in the manifest.
        for dst, src in manifest['modules'].iteritems():
            # NOTE(agallagher): calls the `add_source` and `add_resource` below
            # hard-link the given source into the PEX temp dir.  Since OS X and
            # Linux behave different when hard-linking a source that is a
            # symbolic link (Linux does *not* follow symlinks), resolve any
            # layers of symlinks here to get consistent behavior.
            try:
                pex_builder.add_source(dereference_symlinks(src), dst)
            except OSError as e:
                raise Exception("Failed to add {}: {}".format(src, e))

        # Add resources listed in the manifest.
        for dst, src in manifest['resources'].iteritems():
            # NOTE(agallagher): see rationale above.
            pex_builder.add_resource(dereference_symlinks(src), dst)

        # Add prebuilt libraries listed in the manifest.
        for req in manifest.get('prebuiltLibraries', []):
            try:
                pex_builder.add_dist_location(req)
            except Exception as e:
                raise Exception("Failed to add {}: {}".format(req, e))

        # Add resources listed in the manifest.
        for dst, src in manifest['nativeLibraries'].iteritems():
            # NOTE(agallagher): see rationale above.
            pex_builder.add_resource(dereference_symlinks(src), dst)

        # Generate the PEX file.
        pex_builder.build(output)

    # Always try cleaning up the scratch dir, ignoring failures.
    finally:
        shutil.rmtree(tmp_dir, True)
开发者ID:JustNeedOneStepMore,项目名称:buck,代码行数:85,代码来源:make_pex.py


注:本文中的pex.interpreter.PythonInterpreter.from_binary方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。