コード例 #1
0
    def add_dist_location(self, dist, name=None):
        """Add a distribution by its location on disk.

        :param dist: The path to the distribution to add.
        :keyword name: (optional) The name of the distribution, should the dist directory alone be
          ambiguous.  Packages contained within site-packages directories may require specifying
          ``name``.
        :raises PEXBuilder.InvalidDistribution: When the path does not contain a matching distribution.

        PEX supports packed and unpacked .whl and .egg distributions, as well as any distribution
        supported by setuptools/pkg_resources.
        """
        self._ensure_unfrozen("Adding a distribution")
        dist_path = dist
        if os.path.isfile(dist_path) and dist_path.endswith(".whl"):
            dist_path = os.path.join(safe_mkdtemp(), os.path.basename(dist))
            get_pip().spawn_install_wheel(
                wheel=dist,
                install_dir=dist_path,
                target=DistributionTarget.for_interpreter(self.interpreter),
            ).wait()

        dist = DistributionHelper.distribution_from_path(dist_path)
        self.add_distribution(dist, dist_name=name)
        self.add_requirement(dist.as_requirement())
コード例 #2
0
ファイル: pex.py プロジェクト: cosmicexplorer/pex
    def _activate(self):
        # type: () -> Iterable[Distribution]

        # set up the local .pex environment
        pex_info = self.pex_info()
        target = DistributionTarget.for_interpreter(self._interpreter)
        self._envs.append(PEXEnvironment(self._pex, pex_info, target=target))
        # N.B. by this point, `pex_info.pex_path` will contain a single pex path
        # merged from pex_path in `PEX-INFO` and `PEX_PATH` set in the environment.
        # `PEX_PATH` entries written into `PEX-INFO` take precedence over those set
        # in the environment.
        if pex_info.pex_path:
            # set up other environments as specified in pex_path
            for pex_path in filter(None, pex_info.pex_path.split(os.pathsep)):
                pex_info = PexInfo.from_pex(pex_path)
                pex_info.update(self._pex_info_overrides)
                self._envs.append(PEXEnvironment(pex_path, pex_info, target=target))

        # activate all of them
        activated_dists = []  # type: List[Distribution]
        for env in self._envs:
            activated_dists.extend(env.activate())

        # Ensure that pkg_resources is not imported until at least every pex environment
        # (i.e. PEX_PATH) has been merged into the environment
        PEXEnvironment._declare_namespace_packages(activated_dists)
        return activated_dists
コード例 #3
0
 def _add_dist_wheel_file(self, path, dist_name):
     with temporary_dir() as install_dir:
         get_pip().spawn_install_wheel(
             wheel=path,
             install_dir=install_dir,
             target=DistributionTarget.for_interpreter(self.interpreter),
         ).wait()
         return self._add_dist_dir(install_dir, dist_name)
コード例 #4
0
ファイル: testing.py プロジェクト: tdyas/pex
def make_bdist(name='my_project', version='0.0.0', zip_safe=True, interpreter=None, **kwargs):
  with built_wheel(name=name,
                   version=version,
                   zip_safe=zip_safe,
                   interpreter=interpreter,
                   **kwargs) as dist_location:

    install_dir = os.path.join(safe_mkdtemp(), os.path.basename(dist_location))
    get_pip().spawn_install_wheel(
      wheel=dist_location,
      install_dir=install_dir,
      target=DistributionTarget.for_interpreter(interpreter)
    ).wait()
    yield DistributionHelper.distribution_from_path(install_dir)
コード例 #5
0
ファイル: resolver.py プロジェクト: tdyas/pex
    def iter_targets():
        if not interpreters and not parsed_platforms:
            # No specified targets, so just build for the current interpreter (on the current platform).
            yield DistributionTarget.current()
            return

        if interpreters:
            for interpreter in interpreters:
                # Build for the specified local interpreters (on the current platform).
                yield DistributionTarget.for_interpreter(interpreter)

        if parsed_platforms:
            for platform in parsed_platforms:
                if platform is not None or not interpreters:
                    # 1. Build for specific platforms.
                    # 2. Build for the current platform (None) only if not done already (ie: no intepreters
                    #    were specified).
                    yield DistributionTarget.for_platform(platform)
コード例 #6
0
def make_bdist(
    name="my_project",  # type: str
    version="0.0.0",  # type: str
    zip_safe=True,  # type: bool
    interpreter=None,  # type: Optional[PythonInterpreter]
    **kwargs  # type: Any
):
    # type: (...) -> Iterator[Distribution]
    with built_wheel(
        name=name, version=version, zip_safe=zip_safe, interpreter=interpreter, **kwargs
    ) as dist_location:

        install_dir = os.path.join(safe_mkdtemp(), os.path.basename(dist_location))
        get_pip().spawn_install_wheel(
            wheel=dist_location,
            install_dir=install_dir,
            target=DistributionTarget.for_interpreter(interpreter),
        ).wait()
        dist = DistributionHelper.distribution_from_path(install_dir)
        assert dist is not None
        yield dist
コード例 #7
0
 def _loaded_envs(self):
     # type: () -> Iterable[PEXEnvironment]
     if self._envs is None:
         # set up the local .pex environment
         pex_info = self.pex_info()
         target = DistributionTarget.for_interpreter(self._interpreter)
         envs = [PEXEnvironment(self._pex, pex_info, target=target)]
         # N.B. by this point, `pex_info.pex_path` will contain a single pex path
         # merged from pex_path in `PEX-INFO` and `PEX_PATH` set in the environment.
         # `PEX_PATH` entries written into `PEX-INFO` take precedence over those set
         # in the environment.
         if pex_info.pex_path:
             # set up other environments as specified in pex_path
             for pex_path in filter(None,
                                    pex_info.pex_path.split(os.pathsep)):
                 pex_info = PexInfo.from_pex(pex_path)
                 pex_info.update(self._pex_info_overrides)
                 envs.append(
                     PEXEnvironment(pex_path, pex_info, target=target))
         self._envs = tuple(envs)
     return self._envs
コード例 #8
0
ファイル: test_environment.py プロジェクト: jjhelmus/pex
def cpython_35_environment(python_35_interpreter):
    return PEXEnvironment(
        pex="",
        pex_info=PexInfo.default(python_35_interpreter),
        target=DistributionTarget.for_interpreter(python_35_interpreter),
    )