def _check_plugin_version(plugin_module, plugin_name): if hasattr(plugin_module, "pyb_version") and plugin_module.pyb_version: required_pyb_version = SpecifierSet(plugin_module.pyb_version, True) if not required_pyb_version.contains(PYB_VERSION): raise IncompatiblePluginException(plugin_name, required_pyb_version, PYB_VERSION)
def version_satisfies_spec(spec, version): if not spec: return True if not version: return False if not isinstance(spec, SpecifierSet): spec = SpecifierSet(spec) if not isinstance(version, Version): version = Version(version) return spec.contains(version)
def contains_version(version: str, version_specifier: str) -> bool: specifier = SpecifierSet(version_specifier) return specifier.contains(version)
def _iter_found_candidates( self, ireqs: Sequence[InstallRequirement], specifier: SpecifierSet, hashes: Hashes, prefers_installed: bool, incompatible_ids: Set[int], ) -> Iterable[Candidate]: if not ireqs: return () # The InstallRequirement implementation requires us to give it a # "template". Here we just choose the first requirement to represent # all of them. # Hopefully the Project model can correct this mismatch in the future. template = ireqs[0] assert template.req, "Candidates found on index must be PEP 508" name = canonicalize_name(template.req.name) extras = frozenset() # type: FrozenSet[str] for ireq in ireqs: assert ireq.req, "Candidates found on index must be PEP 508" specifier &= ireq.req.specifier hashes &= ireq.hashes(trust_internet=False) extras |= frozenset(ireq.extras) # Get the installed version, if it matches, unless the user # specified `--force-reinstall`, when we want the version from # the index instead. installed_candidate = None if not self._force_reinstall and name in self._installed_dists: installed_dist = self._installed_dists[name] if specifier.contains(installed_dist.version, prereleases=True): installed_candidate = self._make_candidate_from_dist( dist=installed_dist, extras=extras, template=template, ) def iter_index_candidate_infos(): # type: () -> Iterator[IndexCandidateInfo] result = self._finder.find_best_candidate( project_name=name, specifier=specifier, hashes=hashes, ) icans = list(result.iter_applicable()) # PEP 592: Yanked releases must be ignored unless only yanked # releases can satisfy the version range. So if this is false, # all yanked icans need to be skipped. all_yanked = all(ican.link.is_yanked for ican in icans) # PackageFinder returns earlier versions first, so we reverse. for ican in reversed(icans): if not all_yanked and ican.link.is_yanked: continue func = functools.partial( self._make_candidate_from_link, link=ican.link, extras=extras, template=template, name=name, version=ican.version, ) yield ican.version, func return FoundCandidates( iter_index_candidate_infos, installed_candidate, prefers_installed, incompatible_ids, )