本文整理汇总了Python中pip._internal.models.candidate.InstallationCandidate方法的典型用法代码示例。如果您正苦于以下问题:Python candidate.InstallationCandidate方法的具体用法?Python candidate.InstallationCandidate怎么用?Python candidate.InstallationCandidate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pip._internal.models.candidate
的用法示例。
在下文中一共展示了candidate.InstallationCandidate方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: from_specifier
# 需要导入模块: from pip._internal.models import candidate [as 别名]
# 或者: from pip._internal.models.candidate import InstallationCandidate [as 别名]
def from_specifier(
cls,
candidates, # type: List[InstallationCandidate]
specifier, # type: specifiers.BaseSpecifier
prereleases, # type: Optional[bool]
evaluator, # type: CandidateEvaluator
):
# type: (...) -> FoundCandidates
versions = {
str(v) for v in specifier.filter(
# We turn the version object into a str here because otherwise
# when we're debundled but setuptools isn't, Python will see
# packaging.version.Version and
# pkg_resources._vendor.packaging.version.Version as different
# types. This way we'll use a str as a common data interchange
# format. If we stop using the pkg_resources provided specifier
# and start using our own, we can drop the cast to str().
(str(c.version) for c in candidates),
prereleases=prereleases,
)
}
return cls(candidates, versions, evaluator)
示例2: __init__
# 需要导入模块: from pip._internal.models import candidate [as 别名]
# 或者: from pip._internal.models.candidate import InstallationCandidate [as 别名]
def __init__(
self,
candidates, # type: List[InstallationCandidate]
applicable_candidates, # type: List[InstallationCandidate]
best_candidate, # type: Optional[InstallationCandidate]
):
# type: (...) -> None
"""
:param candidates: A sequence of all available candidates found.
:param applicable_candidates: The applicable candidates.
:param best_candidate: The most preferred candidate found, or None
if no applicable candidates were found.
"""
assert set(applicable_candidates) <= set(candidates)
if best_candidate is None:
assert not applicable_candidates
else:
assert best_candidate in applicable_candidates
self._applicable_candidates = applicable_candidates
self._candidates = candidates
self.best_candidate = best_candidate
示例3: compute_best_candidate
# 需要导入模块: from pip._internal.models import candidate [as 别名]
# 或者: from pip._internal.models.candidate import InstallationCandidate [as 别名]
def compute_best_candidate(
self,
candidates, # type: List[InstallationCandidate]
):
# type: (...) -> BestCandidateResult
"""
Compute and return a `BestCandidateResult` instance.
"""
applicable_candidates = self.get_applicable_candidates(candidates)
best_candidate = self.sort_best_candidate(applicable_candidates)
return BestCandidateResult(
candidates,
applicable_candidates=applicable_candidates,
best_candidate=best_candidate,
)
示例4: get_install_candidate
# 需要导入模块: from pip._internal.models import candidate [as 别名]
# 或者: from pip._internal.models.candidate import InstallationCandidate [as 别名]
def get_install_candidate(self, link_evaluator, link):
# type: (LinkEvaluator, Link) -> Optional[InstallationCandidate]
"""
If the link is a candidate for install, convert it to an
InstallationCandidate and return it. Otherwise, return None.
"""
is_candidate, result = link_evaluator.evaluate_link(link)
if not is_candidate:
if result:
self._log_skipped_link(link, reason=result)
return None
return InstallationCandidate(
name=link_evaluator.project_name,
link=link,
# Convert the Text result to str since InstallationCandidate
# accepts str.
version=str(result),
)
示例5: process_project_url
# 需要导入模块: from pip._internal.models import candidate [as 别名]
# 或者: from pip._internal.models.candidate import InstallationCandidate [as 别名]
def process_project_url(self, project_url, link_evaluator):
# type: (Link, LinkEvaluator) -> List[InstallationCandidate]
logger.debug(
'Fetching project page and analyzing links: %s', project_url,
)
html_page = self._link_collector.fetch_page(project_url)
if html_page is None:
return []
page_links = list(parse_links(html_page))
with indent_log():
package_links = self.evaluate_links(
link_evaluator,
links=page_links,
)
return package_links
示例6: get_install_candidate
# 需要导入模块: from pip._internal.models import candidate [as 别名]
# 或者: from pip._internal.models.candidate import InstallationCandidate [as 别名]
def get_install_candidate(self, link_evaluator, link):
# type: (LinkEvaluator, Link) -> Optional[InstallationCandidate]
"""
If the link is a candidate for install, convert it to an
InstallationCandidate and return it. Otherwise, return None.
"""
is_candidate, result = link_evaluator.evaluate_link(link)
if not is_candidate:
if result:
self._log_skipped_link(link, reason=result)
return None
return InstallationCandidate(
project=link_evaluator.project_name,
link=link,
# Convert the Text result to str since InstallationCandidate
# accepts str.
version=str(result),
)
示例7: make_found_candidates
# 需要导入模块: from pip._internal.models import candidate [as 别名]
# 或者: from pip._internal.models.candidate import InstallationCandidate [as 别名]
def make_found_candidates(
self,
candidates, # type: List[InstallationCandidate]
):
# type: (...) -> FoundCandidates
"""
Create and return a `FoundCandidates` instance.
:param specifier: An optional object implementing `filter`
(e.g. `packaging.specifiers.SpecifierSet`) to filter applicable
versions.
"""
applicable_candidates = self.get_applicable_candidates(candidates)
return FoundCandidates(
candidates,
applicable_candidates=applicable_candidates,
evaluator=self,
)
示例8: _sort_key
# 需要导入模块: from pip._internal.models import candidate [as 别名]
# 或者: from pip._internal.models.candidate import InstallationCandidate [as 别名]
def _sort_key(self, candidate):
# type: (InstallationCandidate) -> CandidateSortingKey
"""
Function used to generate link sort key for link tuples.
The greater the return value, the more preferred it is.
If not finding wheels, then sorted by version only.
If finding wheels, then the sort order is by version, then:
1. existing installs
2. wheels ordered via Wheel.support_index_min(self._valid_tags)
3. source archives
If prefer_binary was set, then all wheels are sorted above sources.
Note: it was considered to embed this logic into the Link
comparison operators, but then different sdist links
with the same version, would have to be considered equal
"""
support_num = len(self._valid_tags)
build_tag = tuple() # type: BuildTag
binary_preference = 0
if candidate.location.is_wheel:
# can raise InvalidWheelFilename
wheel = Wheel(candidate.location.filename)
if not wheel.supported(self._valid_tags):
raise UnsupportedWheel(
"%s is not a supported wheel for this platform. It "
"can't be sorted." % wheel.filename
)
if self._prefer_binary:
binary_preference = 1
pri = -(wheel.support_index_min(self._valid_tags))
if wheel.build_tag is not None:
match = re.match(r'^(\d+)(.*)$', wheel.build_tag)
build_tag_groups = match.groups()
build_tag = (int(build_tag_groups[0]), build_tag_groups[1])
else: # sdist
pri = -(support_num)
return (binary_preference, candidate.version, build_tag, pri)
示例9: get_best_candidate
# 需要导入模块: from pip._internal.models import candidate [as 别名]
# 或者: from pip._internal.models.candidate import InstallationCandidate [as 别名]
def get_best_candidate(self, candidates):
# type: (List[InstallationCandidate]) -> InstallationCandidate
"""
Return the best candidate per the instance's sort order, or None if
no candidates are given.
"""
if not candidates:
return None
return max(candidates, key=self._sort_key)
示例10: __init__
# 需要导入模块: from pip._internal.models import candidate [as 别名]
# 或者: from pip._internal.models.candidate import InstallationCandidate [as 别名]
def __init__(
self,
candidates, # type: List[InstallationCandidate]
versions, # type: Set[str]
evaluator, # type: CandidateEvaluator
):
# type: (...) -> None
self._candidates = candidates
self._evaluator = evaluator
self._versions = versions
示例11: iter_all
# 需要导入模块: from pip._internal.models import candidate [as 别名]
# 或者: from pip._internal.models.candidate import InstallationCandidate [as 别名]
def iter_all(self):
# type: () -> Iterable[InstallationCandidate]
"""Iterate through all candidates.
"""
return iter(self._candidates)
示例12: get_best
# 需要导入模块: from pip._internal.models import candidate [as 别名]
# 或者: from pip._internal.models.candidate import InstallationCandidate [as 别名]
def get_best(self):
# type: () -> Optional[InstallationCandidate]
"""Return the best candidate available, or None if no applicable
candidates are found.
"""
candidates = list(self.iter_applicable())
return self._evaluator.get_best_candidate(candidates)
示例13: _package_versions
# 需要导入模块: from pip._internal.models import candidate [as 别名]
# 或者: from pip._internal.models.candidate import InstallationCandidate [as 别名]
def _package_versions(
self,
links, # type: Iterable[Link]
search # type: Search
):
# type: (...) -> List[Optional[InstallationCandidate]]
result = []
for link in self._sort_links(links):
v = self._link_package_versions(link, search)
if v is not None:
result.append(v)
return result
示例14: iter_applicable
# 需要导入模块: from pip._internal.models import candidate [as 别名]
# 或者: from pip._internal.models.candidate import InstallationCandidate [as 别名]
def iter_applicable(self):
# type: () -> Iterable[InstallationCandidate]
"""Iterate through candidates matching the versions associated with
this instance.
"""
# Again, converting version to str to deal with debundling.
return (c for c in self.iter_all() if str(c.version) in self._versions)