예제 #1
0
def test_isolated_idempotent_inprocess():
    with temporary_pex_root():
        result1 = third_party.isolated()
        result2 = third_party.isolated()
        assert result1.pex_hash == result2.pex_hash
        assert os.path.realpath(result1.chroot_path) == os.path.realpath(
            result2.chroot_path)
예제 #2
0
파일: pip.py 프로젝트: joakimnordling/pex
    def create(
            cls,
            path,  # type: str
            interpreter=None,  # type: Optional[PythonInterpreter]
    ):
        # type: (...) -> Pip
        """Creates a pip tool with PEX isolation at path.

        :param path: The path to assemble the pip tool at.
        :param interpreter: The interpreter to run Pip with. The current interpreter by default.
        :return: The path of a PEX that can be used to execute Pip in isolation.
        """
        pip_interpreter = interpreter or PythonInterpreter.get()
        pip_pex_path = os.path.join(path, isolated().pex_hash)
        with atomic_directory(pip_pex_path, exclusive=True) as chroot:
            if not chroot.is_finalized:
                from pex.pex_builder import PEXBuilder

                isolated_pip_builder = PEXBuilder(path=chroot.work_dir)
                isolated_pip_builder.info.venv = True
                for dist_location in third_party.expose(
                    ["pip", "setuptools", "wheel"]):
                    isolated_pip_builder.add_dist_location(dist=dist_location)
                isolated_pip_builder.set_script("pip")
                isolated_pip_builder.freeze()
        pex_info = PexInfo.from_pex(pip_pex_path)
        pex_info.add_interpreter_constraint(
            str(pip_interpreter.identity.requirement))
        return cls(
            ensure_venv(
                PEX(pip_pex_path,
                    interpreter=pip_interpreter,
                    pex_info=pex_info)))
예제 #3
0
def test_isolated_idempotent_subprocess():
  with temporary_pex_root() as (_, env):
    devendored_chroot = os.path.realpath(third_party.isolated())
    stdout = subprocess.check_output(
      args=[sys.executable, '-c', 'from pex.third_party import isolated; print(isolated())'],
      env=env
    )
    assert devendored_chroot == os.path.realpath(stdout.decode('utf-8').strip())
예제 #4
0
def test_isolated_idempotent_subprocess():
    with temporary_pex_root() as (_, env):
        devendored_chroot = os.path.realpath(
            third_party.isolated().chroot_path)
        stdout = subprocess.check_output(
            args=[
                sys.executable,
                "-c",
                "from pex import third_party; print(third_party.isolated().chroot_path)",
            ],
            env=env,
        )
        assert devendored_chroot == os.path.realpath(
            stdout.decode("utf-8").strip())
예제 #5
0
  def bootstrap_script(self):
    return """
import sys
sys.path.insert(0, {root!r})

# Expose vendored mixin path_items (setuptools, wheel, etc.) directly to the package's setup.py.
from pex import third_party
third_party.install(root={root!r}, expose={mixins!r})

# Now execute the package's setup.py such that it sees itself as a setup.py executed via
# `python setup.py ...`
__file__ = 'setup.py'
sys.argv[0] = __file__
with open(__file__, 'rb') as fp:
  exec(fp.read())
""".format(root=third_party.isolated(), mixins=self.mixins)
예제 #6
0
    def create(cls, path):
        # type: (str) -> Pip
        """Creates a pip tool with PEX isolation at path.

        :param path: The path to build the pip tool pex at.
        """
        pip_pex_path = os.path.join(path, isolated().pex_hash)
        with atomic_directory(pip_pex_path, exclusive=True) as chroot:
            if chroot is not None:
                from pex.pex_builder import PEXBuilder

                isolated_pip_builder = PEXBuilder(path=chroot)
                pythonpath = third_party.expose(["pip", "setuptools", "wheel"])
                isolated_pip_environment = third_party.pkg_resources.Environment(
                    search_path=pythonpath
                )
                for dist_name in isolated_pip_environment:
                    for dist in isolated_pip_environment[dist_name]:
                        isolated_pip_builder.add_dist_location(dist=dist.location)
                with open(os.path.join(isolated_pip_builder.path(), "run_pip.py"), "w") as fp:
                    fp.write(
                        dedent(
                            """\
                            import os
                            import runpy
                            import sys
                            
                            
                            # Propagate un-vendored setuptools to pip for any legacy setup.py builds it needs to
                            # perform.
                            os.environ['__PEX_UNVENDORED__'] = '1'
                            os.environ['PYTHONPATH'] = os.pathsep.join(sys.path)
                            
                            runpy.run_module('pip', run_name='__main__')
                            """
                        )
                    )
                isolated_pip_builder.set_executable(fp.name)
                isolated_pip_builder.freeze()

        return cls(pip_pex_path)
예제 #7
0
def test_isolated_pex_root():
    with temporary_pex_root() as (pex_root, _):
        devendored_chroot = os.path.realpath(
            third_party.isolated().chroot_path)
        assert pex_root == os.path.commonprefix([pex_root, devendored_chroot])
예제 #8
0
def test_isolated_idempotent_inprocess():
  with temporary_pex_root():
    assert os.path.realpath(third_party.isolated()) == os.path.realpath(third_party.isolated())