How to use the pex.interpreter.PythonInterpreter.from_binary function in pex

To help you get started, we’ve selected a few pex examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pantsbuild / pex / tests / test_interpreter.py View on Github external
def test_interpreter_caching(self, test_interpreter1, test_interpreter2):
    py_interpreter1 = interpreter.PythonInterpreter.from_binary(test_interpreter1)
    py_interpreter2 = interpreter.PythonInterpreter.from_binary(test_interpreter2)
    assert py_interpreter1 is not py_interpreter2
    assert py_interpreter2.identity.version == self.TEST_INTERPRETER2_VERSION_TUPLE

    py_interpreter3 = interpreter.PythonInterpreter.from_binary(test_interpreter1)
    assert py_interpreter1 is py_interpreter3
github pantsbuild / pants / tests / python / pants_test / backend / python / tasks / test_interpreter_selection_integration.py View on Github external
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
github pantsbuild / pex / tests / test_installer.py View on Github external
def wheel_installer(*mixins):
  bare_interpreter = PythonInterpreter.from_binary(ensure_python_interpreter(PY36))
  with make_installer(installer_impl=OrderableInstaller,
                      interpreter=bare_interpreter,
                      mixins=list(mixins)) as installer:
    yield installer
github pantsbuild / pex / tests / test_resolver.py View on Github external
def test_resolve_current_and_foreign_platforms(p537_resolve_cache):
  foreign_platform = 'macosx-10.13-x86_64-cp-37-m' if IS_LINUX else 'manylinux1_x86_64-cp-37-m'
  resolve_current_and_foreign = functools.partial(resolve_p537_wheel_names,
                                                  cache=p537_resolve_cache,
                                                  platforms=['current', foreign_platform])

  assert 2 == len(resolve_current_and_foreign())

  other_python_version = PY36 if PY_VER == (3, 5) else PY35
  other_python = PythonInterpreter.from_binary(ensure_python_interpreter(other_python_version))
  current_python = PythonInterpreter.get()

  assert 2 == len(resolve_current_and_foreign(interpreters=[current_python]))
  assert 2 == len(resolve_current_and_foreign(interpreters=[other_python]))
  assert 2 == len(resolve_current_and_foreign(interpreters=[current_python, current_python]))

  # Here we have 2 local interpreters, satisfying current, but with different platforms and thus
  # different dists and then the foreign platform for 3 total dists.
  assert 3 == len(resolve_current_and_foreign(interpreters=[current_python, other_python]))
github facebook / buck / src / com / facebook / buck / features / python / make_pex.py View on Github external
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)

    # 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.
    if not options.python:
        options.python = sys.executable
        identity = PythonIdentity.get()
    elif not options.python_version:
        # Note: this is expensive (~500ms). prefer passing --python-version when possible.
        identity = PythonInterpreter.from_binary(options.python).identity
    else:
        # Convert "CPython 2.7" to "CPython 2 7 0"
        python_version = options.python_version.replace(".", " ").split()
        if len(python_version) == 3:
            python_version.append("0")
        identity = PythonIdentity.from_id_string(" ".join(python_version))

    interpreter = PythonInterpreter(options.python, identity, extras={})

    pex_builder = PEXBuilder(
        path=output if options.directory else None, interpreter=interpreter
    )

    if options.python_shebang is not None:
        pex_builder.set_shebang(options.python_shebang)
github pantsbuild / pex / pex / bin / pex.py View on Github external
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
github pantsbuild / pex / pex / pex_bootstrapper.py View on Github external
def try_create(try_path):
    try:
      return PythonInterpreter.from_binary(try_path)
    except Executor.ExecutionError:
      return None
github apache / incubator-heron / third_party / pex / _pex.py View on Github external
poptions.find_links = options.find_links
        poptions.pypi = options.pypi
        poptions.python = options.python
        poptions.zip_safe = options.zip_safe
        poptions.disable_cache = options.disable_cache


        #print("pex options: %s" % poptions)
        os.environ["PATH"] = ".:%s:/bin:/usr/bin" % poptions.python

        # The version of pkg_resources.py (from setuptools) on some distros is too old for PEX. So
        # we keep a recent version in and force it into the process by constructing a custom
        # PythonInterpreter instance using it.
        interpreter = PythonInterpreter(
            poptions.python,
            PythonInterpreter.from_binary(options.python).identity,
            extras={
                # TODO: Fix this to resolve automatically
                ('setuptools', '18.0.1'): 'third_party/pex/setuptools-18.0.1-py2.py3-none-any.whl',
                ('wheel', '0.23.0'): 'third_party/pex/wheel-0.23.0-py2.7.egg'
            })

        # resolve setuptools
        interpreter = resolve_or_die(interpreter, SETUPTOOLS_REQUIREMENT, poptions)

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

        # Add prebuilt libraries listed in the manifest.
        reqs = manifest.get('requirements', {}).keys()
        #if len(reqs) > 0: