本文整理匯總了Python中pip._vendor.packaging.specifiers.SpecifierSet方法的典型用法代碼示例。如果您正苦於以下問題:Python specifiers.SpecifierSet方法的具體用法?Python specifiers.SpecifierSet怎麽用?Python specifiers.SpecifierSet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pip._vendor.packaging.specifiers
的用法示例。
在下文中一共展示了specifiers.SpecifierSet方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: check_requires_python
# 需要導入模塊: from pip._vendor.packaging import specifiers [as 別名]
# 或者: from pip._vendor.packaging.specifiers import SpecifierSet [as 別名]
def check_requires_python(requires_python):
"""
Check if the python version in use match the `requires_python` specifier.
Returns `True` if the version of python in use matches the requirement.
Returns `False` if the version of python in use does not matches the
requirement.
Raises an InvalidSpecifier if `requires_python` have an invalid format.
"""
if requires_python is None:
# The package provides no information
return True
requires_python_specifier = specifiers.SpecifierSet(requires_python)
# We only use major.minor.micro
python_version = version.parse('.'.join(map(str, sys.version_info[:3])))
return python_version in requires_python_specifier
示例2: is_superset
# 需要導入模塊: from pip._vendor.packaging import specifiers [as 別名]
# 或者: from pip._vendor.packaging.specifiers import SpecifierSet [as 別名]
def is_superset(self, other: Union[str, SpecifierSet]) -> bool:
if self.is_impossible:
return False
if self.is_allow_all:
return True
other = type(self)(str(other))
if other._upper_bound[0] >= self.MAX_MAJOR_VERSION:
# XXX: narrow down the upper bound to ``MAX_MAJOR_VERSION``
# So that `>=3.6,<4.0` is considered a superset of `>=3.7`, see issues/66
other._upper_bound = (self.MAX_MAJOR_VERSION, 0, 0)
if (
self._lower_bound > other._lower_bound
or self._upper_bound < other._upper_bound
):
return False
valid_excludes = set(
_restrict_versions_to_range(
self._excludes, other._lower_bound, other._upper_bound
)
)
return valid_excludes <= set(other._excludes)
示例3: is_subset
# 需要導入模塊: from pip._vendor.packaging import specifiers [as 別名]
# 或者: from pip._vendor.packaging.specifiers import SpecifierSet [as 別名]
def is_subset(self, other: Union[str, SpecifierSet]) -> bool:
if self.is_impossible:
return False
other = type(self)(str(other))
if other._upper_bound[0] >= self.MAX_MAJOR_VERSION:
other._upper_bound = self.MAX_VERSION
if other.is_allow_all:
return True
if (
self._lower_bound < other._lower_bound
or self._upper_bound > other._upper_bound
):
return False
valid_excludes = set(
_restrict_versions_to_range(
other._excludes, self._lower_bound, self._upper_bound
)
)
return valid_excludes <= set(self._excludes)
示例4: find_candidates
# 需要導入模塊: from pip._vendor.packaging import specifiers [as 別名]
# 或者: from pip._vendor.packaging.specifiers import SpecifierSet [as 別名]
def find_candidates(
self,
project_name, # type: str
specifier=None, # type: Optional[specifiers.BaseSpecifier]
):
"""Find matches for the given project and specifier.
If given, `specifier` should implement `filter` to allow version
filtering (e.g. ``packaging.specifiers.SpecifierSet``).
Returns a `FoundCandidates` instance.
"""
if specifier is None:
specifier = specifiers.SpecifierSet()
return FoundCandidates.from_specifier(
self.find_all_candidates(project_name),
specifier=specifier,
prereleases=(self.allow_all_prereleases or None),
evaluator=self.candidate_evaluator,
)
示例5: check_requires_python
# 需要導入模塊: from pip._vendor.packaging import specifiers [as 別名]
# 或者: from pip._vendor.packaging.specifiers import SpecifierSet [as 別名]
def check_requires_python(requires_python):
# type: (Optional[str]) -> bool
"""
Check if the python version in use match the `requires_python` specifier.
Returns `True` if the version of python in use matches the requirement.
Returns `False` if the version of python in use does not matches the
requirement.
Raises an InvalidSpecifier if `requires_python` have an invalid format.
"""
if requires_python is None:
# The package provides no information
return True
requires_python_specifier = specifiers.SpecifierSet(requires_python)
# We only use major.minor.micro
python_version = version.parse('.'.join(map(str, sys.version_info[:3])))
return python_version in requires_python_specifier
示例6: check_requires_python
# 需要導入模塊: from pip._vendor.packaging import specifiers [as 別名]
# 或者: from pip._vendor.packaging.specifiers import SpecifierSet [as 別名]
def check_requires_python(requires_python, version_info):
# type: (Optional[str], Tuple[int, ...]) -> bool
"""
Check if the given Python version matches a "Requires-Python" specifier.
:param version_info: A 3-tuple of ints representing a Python
major-minor-micro version to check (e.g. `sys.version_info[:3]`).
:return: `True` if the given Python version satisfies the requirement.
Otherwise, return `False`.
:raises InvalidSpecifier: If `requires_python` has an invalid format.
"""
if requires_python is None:
# The package provides no information
return True
requires_python_specifier = specifiers.SpecifierSet(requires_python)
python_version = version.parse('.'.join(map(str, version_info)))
return python_version in requires_python_specifier
示例7: find_best_candidate
# 需要導入模塊: from pip._vendor.packaging import specifiers [as 別名]
# 或者: from pip._vendor.packaging.specifiers import SpecifierSet [as 別名]
def find_best_candidate(
self,
project_name, # type: str
specifier=None, # type: Optional[specifiers.BaseSpecifier]
hashes=None, # type: Optional[Hashes]
):
# type: (...) -> BestCandidateResult
"""Find matches for the given project and specifier.
:param specifier: An optional object implementing `filter`
(e.g. `packaging.specifiers.SpecifierSet`) to filter applicable
versions.
:return: A `BestCandidateResult` instance.
"""
candidates = self.find_all_candidates(project_name)
candidate_evaluator = self.make_candidate_evaluator(
project_name=project_name,
specifier=specifier,
hashes=hashes,
)
return candidate_evaluator.compute_best_candidate(candidates)