Esempio n. 1
0
    def prepare_editable_requirement(
            self,
            req,  # type: InstallRequirement
            require_hashes,  # type: bool
            use_user_site,  # type: bool
            finder,  # type: PackageFinder
    ):
        # type: (...) -> AbstractDistribution
        """Prepare an editable requirement"""
        assert req.editable, "cannot prepare a non-editable req as editable"

        logger.info("Obtaining %s", req)

        with indent_log():
            if require_hashes:
                raise InstallationError(
                    "The editable requirement %s cannot be installed when "
                    "requiring hashes, because there is no single file to "
                    "hash." % req)
            req.ensure_has_source_dir(self.src_dir)
            req.update_editable(not self._download_should_save)

            abstract_dist = make_distribution_for_install_requirement(req)
            with self.req_tracker.track(req):
                abstract_dist.prepare_distribution_metadata(
                    finder,
                    self.build_isolation,
                )

            if self._download_should_save:
                req.archive(self.download_dir)
            req.check_if_exists(use_user_site)

        return abstract_dist
Esempio n. 2
0
def _get_prepared_distribution(req, req_tracker, finder, build_isolation):
    """Prepare a distribution for installation.
    """
    abstract_dist = make_distribution_for_install_requirement(req)
    with req_tracker.track(req):
        abstract_dist.prepare_distribution_metadata(finder, build_isolation)
    return abstract_dist
Esempio n. 3
0
def _simulate_installation_of(to_install, package_set):

    # type: (List[InstallRequirement], PackageSet) -> Set[str]
    """Computes the version of packages after installing to_install.

    """

    # Keep track of packages that were installed

    installed = set()

    # Modify it as installing requirement_set would (assuming no errors)

    for inst_req in to_install:

        abstract_dist = make_distribution_for_install_requirement(inst_req)

        dist = abstract_dist.get_pkg_resources_distribution()

        assert dist is not None

        name = canonicalize_name(dist.key)

        package_set[name] = PackageDetails(dist.version, dist.requires())

        installed.add(name)

    return installed
def _get_prepared_distribution(
    req: InstallRequirement,
    req_tracker: RequirementTracker,
    finder: PackageFinder,
    build_isolation: bool,
) -> BaseDistribution:
    """Prepare a distribution for installation."""
    abstract_dist = make_distribution_for_install_requirement(req)
    with req_tracker.track(req):
        abstract_dist.prepare_distribution_metadata(finder, build_isolation)
    return abstract_dist.get_metadata_distribution()
def _get_prepared_distribution(
        req,  # type: InstallRequirement
        req_tracker,  # type: RequirementTracker
        finder,  # type: PackageFinder
        build_isolation,  # type: bool
):
    # type: (...) -> Distribution
    """Prepare a distribution for installation."""
    abstract_dist = make_distribution_for_install_requirement(req)
    with req_tracker.track(req):
        abstract_dist.prepare_distribution_metadata(finder, build_isolation)
    return abstract_dist.get_pkg_resources_distribution()
Esempio n. 6
0
def _simulate_installation_of(to_install, package_set):
    # type: (List[InstallRequirement], PackageSet) -> Set[str]
    """Computes the version of packages after installing to_install.
    """

    # Keep track of packages that were installed
    installed = set()

    # Modify it as installing requirement_set would (assuming no errors)
    for inst_req in to_install:
        abstract_dist = make_distribution_for_install_requirement(inst_req)
        dist = abstract_dist.get_pkg_resources_distribution()
Esempio n. 7
0
def _simulate_installation_of(to_install: List[InstallRequirement],
                              package_set: PackageSet) -> Set[NormalizedName]:
    """Computes the version of packages after installing to_install."""
    # Keep track of packages that were installed
    installed = set()

    # Modify it as installing requirement_set would (assuming no errors)
    for inst_req in to_install:
        abstract_dist = make_distribution_for_install_requirement(inst_req)
        dist = abstract_dist.get_metadata_distribution()
        name = dist.canonical_name
        package_set[name] = PackageDetails(dist.version,
                                           list(dist.iter_dependencies()))

        installed.add(name)

    return installed
Esempio n. 8
0
    def prepare_linked_requirement(
            self,
            req,  # type: InstallRequirement
            session,  # type: PipSession
            finder,  # type: PackageFinder
            upgrade_allowed,  # type: bool
            require_hashes,  # type: bool
    ):
        # type: (...) -> AbstractDistribution
        """Prepare a requirement that would be obtained from req.link"""
        # TODO: Breakup into smaller functions
        if req.link and req.link.scheme == "file":
            path = url_to_path(req.link.url)
            logger.info("Processing %s", display_path(path))
        else:
            logger.info("Collecting %s", req)

        with indent_log():
            # @@ if filesystem packages are not marked
            # editable in a req, a non deterministic error
            # occurs when the script attempts to unpack the
            # build directory
            req.ensure_has_source_dir(self.build_dir)
            # If a checkout exists, it's unwise to keep going.  version
            # inconsistencies are logged later, but do not fail the
            # installation.
            # FIXME: this won't upgrade when there's an existing
            # package unpacked in `req.source_dir`
            # package unpacked in `req.source_dir`
            if os.path.exists(os.path.join(req.source_dir, "setup.py")):
                raise PreviousBuildDirError(
                    "pip can't proceed with requirements '%s' due to a"
                    " pre-existing build directory (%s). This is "
                    "likely due to a previous installation that failed"
                    ". pip is being responsible and not assuming it "
                    "can delete this. Please delete it and try again." %
                    (req, req.source_dir))
            req.populate_link(finder, upgrade_allowed, require_hashes)

            # We can't hit this spot and have populate_link return None.
            # req.satisfied_by is None here (because we're
            # guarded) and upgrade has no impact except when satisfied_by
            # is not None.
            # Then inside find_requirement existing_applicable -> False
            # If no new versions are found, DistributionNotFound is raised,
            # otherwise a result is guaranteed.
            assert req.link
            link = req.link

            # Now that we have the real link, we can tell what kind of
            # requirements we have and raise some more informative errors
            # than otherwise. (For example, we can raise VcsHashUnsupported
            # for a VCS URL rather than HashMissing.)
            if require_hashes:
                # We could check these first 2 conditions inside
                # unpack_url and save repetition of conditions, but then
                # we would report less-useful error messages for
                # unhashable requirements, complaining that there's no
                # hash provided.
                if is_vcs_url(link):
                    raise VcsHashUnsupported()
                elif is_file_url(link) and is_dir_url(link):
                    raise DirectoryUrlHashUnsupported()
                if not req.original_link and not req.is_pinned:
                    # Unpinned packages are asking for trouble when a new
                    # version is uploaded. This isn't a security check, but
                    # it saves users a surprising hash mismatch in the
                    # future.
                    #
                    # file:/// URLs aren't pinnable, so don't complain
                    # about them not being pinned.
                    raise HashUnpinned()

            hashes = req.hashes(trust_internet=not require_hashes)
            if require_hashes and not hashes:
                # Known-good hashes are missing for this requirement, so
                # shim it with a facade object that will provoke hash
                # computation and then raise a HashMissing exception
                # showing the user what the hash should be.
                hashes = MissingHashes()

            try:
                download_dir = self.download_dir
                # We always delete unpacked sdists after pip ran.
                autodelete_unpacked = True
                if req.link.is_wheel and self.wheel_download_dir:
                    # when doing 'pip wheel` we download wheels to a
                    # dedicated dir.
                    download_dir = self.wheel_download_dir
                if req.link.is_wheel:
                    if download_dir:
                        # When downloading, we only unpack wheels to get
                        # metadata.
                        autodelete_unpacked = True
                    else:
                        # When installing a wheel, we use the unpacked
                        # wheel.
                        autodelete_unpacked = False
                unpack_url(
                    req.link,
                    req.source_dir,
                    download_dir,
                    autodelete_unpacked,
                    session=session,
                    hashes=hashes,
                    progress_bar=self.progress_bar,
                )
            except requests.HTTPError as exc:
                logger.critical(
                    "Could not install requirement %s because of error %s",
                    req,
                    exc,
                )
                raise InstallationError(
                    "Could not install requirement %s because of HTTP "
                    "error %s for URL %s" % (req, exc, req.link))
            abstract_dist = make_distribution_for_install_requirement(req)
            with self.req_tracker.track(req):
                abstract_dist.prepare_distribution_metadata(
                    finder,
                    self.build_isolation,
                )
            if self._download_should_save:
                # Make a .zip of the source_dir we already created.
                if not req.link.is_artifact:
                    req.archive(self.download_dir)
        return abstract_dist
Esempio n. 9
0
        )
    )


def _simulate_installation_of(to_install, package_set):
    # type: (List[InstallRequirement], PackageSet) -> Set[str]
    """Computes the version of packages after installing to_install.
    """

    # Keep track of packages that were installed
    installed = set()

    # Modify it as installing requirement_set would (assuming no errors)
    for inst_req in to_install:
<<<<<<< HEAD
        abstract_dist = make_distribution_for_install_requirement(inst_req)
        dist = abstract_dist.get_pkg_resources_distribution()

=======
        dist = make_abstract_dist(inst_req).dist()
>>>>>>> 71358189c5e72ee2ac9883b408a2f540a7f5745e
        name = canonicalize_name(dist.key)
        package_set[name] = PackageDetails(dist.version, dist.requires())

        installed.add(name)

    return installed


def _create_whitelist(would_be_installed, package_set):
    # type: (Set[str], PackageSet) -> Set[str]