示例#1
0
 def _find_candidates(self, requirement: Requirement) -> Iterable[Candidate]:
     sources = self.get_filtered_sources(requirement)
     with self.environment.get_finder(sources) as finder, allow_all_wheels():
         return [
             Candidate.from_installation_candidate(c, requirement, self.environment)
             for c in finder.find_all_candidates(requirement.project_name)
         ]
示例#2
0
def editables_candidate(environment: Environment) -> Candidate | None:
    """Return a candidate for `editables` package"""
    with environment.get_finder() as finder:
        best_match = finder.find_best_candidate("editables")
        if best_match.best_candidate is None:
            return None
        return Candidate.from_installation_candidate(
            best_match.best_candidate, parse_requirement("editables"),
            environment)
示例#3
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
示例#4
0
    def find_candidates(
        self,
        requirement: Requirement,
        requires_python: PySpecSet = PySpecSet(),
        allow_prereleases: Optional[bool] = None,
        allow_all: bool = False,
    ) -> Iterable[Candidate]:
        sources = self.get_filtered_sources(requirement)
        # `allow_prereleases` is None means leave it to specifier to decide whether to
        # include prereleases
        if allow_prereleases is None:
            allow_prereleases = requirement.allow_prereleases

        with self.environment.get_finder(sources) as finder, allow_all_wheels():
            cans = [
                Candidate.from_installation_candidate(c, requirement, self.environment)
                for c in finder.find_all_candidates(requirement.project_name)
            ]
        sorted_cans = sorted(
            (
                c
                for c in cans
                if requirement.specifier.contains(c.version, allow_prereleases)
                and (allow_all or requires_python.is_subset(c.requires_python))
            ),
            key=lambda c: (c.version, c.link.is_wheel),
            reverse=True,
        )

        if not sorted_cans and allow_prereleases is None:
            # No non-pre-releases is found, force pre-releases now
            sorted_cans = sorted(
                (
                    c
                    for c in cans
                    if requirement.specifier.contains(c.version, True)
                    and (allow_all or requires_python.is_subset(c.requires_python))
                ),
                key=lambda c: c.version,
                reverse=True,
            )
        return sorted_cans