예제 #1
0
 def _find_candidates(self, requirement: Requirement) -> Iterable[Candidate]:
     sources = self.get_filtered_sources(requirement)
     with self.environment.get_finder(sources, True) as finder, allow_all_wheels():
         cans = [
             Candidate.from_installation_candidate(c, requirement)
             for c in finder.find_all_candidates(requirement.project_name)
         ]
     if not cans:
         raise CandidateNotFound(
             f"Unable to find candidates for {requirement.project_name}. There may "
             "exist some issues with the package name or network condition."
         )
     return cans
예제 #2
0
    def obtain(self, allow_all: bool = False) -> None:
        """Fetch the link of the candidate and unpack to local if necessary.

        :param allow_all: If true, don't validate the wheel tag nor hashes
        """
        ireq = self.ireq
        if self.wheel:
            if self._wheel_compatible(self.wheel, allow_all):
                return
        elif ireq.source_dir:
            return

        if not allow_all and self.candidate.hashes:
            ireq.hash_options = convert_hashes(self.candidate.hashes)
        with self.environment.get_finder(
                ignore_requires_python=True) as finder:
            if (not ireq.link or ireq.link.is_wheel and
                    not self._wheel_compatible(ireq.link.filename, allow_all)):
                ireq.link = self.wheel = None  # reset the incompatible wheel
                with allow_all_wheels(allow_all):
                    ireq.link = populate_link(finder, ireq, False)
                if not ireq.link:
                    raise CandidateNotFound("No candidate is found for %s",
                                            self)
                if not ireq.original_link:
                    ireq.original_link = ireq.link
            if allow_all and not self.req.editable:
                cached = self._get_cached_wheel()
                if cached:
                    self.wheel = cached.file_path
                    return
            downloader = pip_shims.Downloader(finder.session,
                                              "off")  # type: ignore
            self._populate_source_dir()
            if not ireq.link.is_existing_dir():
                assert ireq.source_dir
                downloaded = pip_shims.unpack_url(  # type: ignore
                    ireq.link,
                    ireq.source_dir,
                    downloader,
                    hashes=ireq.hashes(False),
                )
                if ireq.link.is_wheel:
                    assert downloaded
                    self.wheel = downloaded.path
                    return