本文整理汇总了Python中packaging.requirements.InvalidRequirement方法的典型用法代码示例。如果您正苦于以下问题:Python requirements.InvalidRequirement方法的具体用法?Python requirements.InvalidRequirement怎么用?Python requirements.InvalidRequirement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类packaging.requirements
的用法示例。
在下文中一共展示了requirements.InvalidRequirement方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse
# 需要导入模块: from packaging import requirements [as 别名]
# 或者: from packaging.requirements import InvalidRequirement [as 别名]
def parse(cls, line):
"""
:param line:
:return:
"""
try:
# setuptools requires a space before the comment. If this isn't the case, add it.
if "\t#" in line:
parsed, = setuptools_parse_requirements_backport(line.replace("\t#", "\t #"))
else:
parsed, = setuptools_parse_requirements_backport(line)
except InvalidRequirement:
return None
dep = Dependency(
name=parsed.name,
specs=parsed.specifier,
line=line,
extras=parsed.extras,
dependency_type=filetypes.requirements_txt
)
return dep
示例2: _is_same_dep
# 需要导入模块: from packaging import requirements [as 别名]
# 或者: from packaging.requirements import InvalidRequirement [as 别名]
def _is_same_dep(cls, dep1, dep2):
"""Definitions are the same if they refer to the same package, even if versions differ."""
dep1_name = canonicalize_name(requirements.Requirement(dep1).name)
try:
dep2_name = canonicalize_name(requirements.Requirement(dep2).name)
except requirements.InvalidRequirement:
# we couldn't parse a version, probably a URL
return False
return dep1_name == dep2_name
示例3: ensure_requires_satisfied
# 需要导入模块: from packaging import requirements [as 别名]
# 或者: from packaging.requirements import InvalidRequirement [as 别名]
def ensure_requires_satisfied(config, requires, min_version):
missing_requirements = []
failed_to_parse = False
deps = []
exists = set()
for require in requires + [min_version]:
# noinspection PyBroadException
try:
package = requirements.Requirement(require)
# check if the package even applies
if package.marker and not package.marker.evaluate({"extra": ""}):
continue
package_name = canonicalize_name(package.name)
if package_name not in exists:
deps.append(DepConfig(require, None))
exists.add(package_name)
dist = importlib_metadata.distribution(package.name)
if not package.specifier.contains(dist.version, prereleases=True):
raise MissingDependency(package)
except requirements.InvalidRequirement as exception:
failed_to_parse = True
error("failed to parse {!r}".format(exception))
except Exception as exception:
verbosity1("could not satisfy requires {!r}".format(exception))
missing_requirements.append(str(requirements.Requirement(require)))
if failed_to_parse:
raise tox.exception.BadRequirement()
if WITHIN_PROVISION and missing_requirements:
msg = "break infinite loop provisioning within {} missing {}"
raise tox.exception.Error(msg.format(sys.executable, missing_requirements))
config.run_provision = bool(len(missing_requirements))
return deps
示例4: _convert_deps
# 需要导入模块: from packaging import requirements [as 别名]
# 或者: from packaging.requirements import InvalidRequirement [as 别名]
def _convert_deps(*, deps, name, version, extra):
# filter result
result = []
for dep in deps:
try:
req = Requirement(dep)
except InvalidRequirement as e:
msg = 'cannot parse requirement: {} from {} {}'
try:
# try to parse with dropped out markers
req = Requirement(dep.split(';')[0])
except InvalidRequirement:
raise ValueError(msg.format(dep, name, version)) from e
else:
logger.warning('cannot parse marker', extra=dict(
requirement=dep,
source_name=name,
source_version=version,
))
try:
dep_extras = req.marker and Markers(req.marker).get_strings('extra')
except ValueError: # unsupported operation for version marker python_version: in
dep_extras = set()
# it's not extra and we want not extra too
if not dep_extras and extra is None:
result.append(req)
continue
# it's extra, but we want not the extra
# or it's not the extra, but we want extra.
if not dep_extras or extra is None:
continue
# it's extra and we want this extra
for dep_extra in dep_extras:
if dep_extra == extra:
result.append(req)
break
return tuple(result)
示例5: _make_req
# 需要导入模块: from packaging import requirements [as 别名]
# 或者: from packaging.requirements import InvalidRequirement [as 别名]
def _make_req(test_id, i, name, req_str):
try:
return Requirement(req_str)
except InvalidRequirement as e:
raise MalformedYAML(test_id, "{} has invalid requirement {!r}", name, req_str)
示例6: _validate_plugins
# 需要导入模块: from packaging import requirements [as 别名]
# 或者: from packaging.requirements import InvalidRequirement [as 别名]
def _validate_plugins(self) -> None:
required_plugins = sorted(self.getini("required_plugins"))
if not required_plugins:
return
# Imported lazily to improve start-up time.
from packaging.version import Version
from packaging.requirements import InvalidRequirement, Requirement
plugin_info = self.pluginmanager.list_plugin_distinfo()
plugin_dist_info = {dist.project_name: dist.version for _, dist in plugin_info}
missing_plugins = []
for required_plugin in required_plugins:
spec = None
try:
spec = Requirement(required_plugin)
except InvalidRequirement:
missing_plugins.append(required_plugin)
continue
if spec.name not in plugin_dist_info:
missing_plugins.append(required_plugin)
elif Version(plugin_dist_info[spec.name]) not in spec.specifier:
missing_plugins.append(required_plugin)
if missing_plugins:
fail(
"Missing required plugins: {}".format(", ".join(missing_plugins)),
pytrace=False,
)
示例7: parse_info
# 需要导入模块: from packaging import requirements [as 别名]
# 或者: from packaging.requirements import InvalidRequirement [as 别名]
def parse_info(cls, content: str, root=None, urls: Dict[str, str] = None) -> RootDependency:
if urls is None:
urls = dict()
info = Parser().parsestr(content)
root = RootDependency(
raw_name=cls._get(info, 'Name'),
version=cls._get(info, 'Version') or '0.0.0',
description=cls._get(info, 'Summary'),
license=cls._get(info, 'License'),
keywords=cls._get(info, 'Keywords').split(','),
classifiers=cls._get_list(info, 'Classifier'),
platforms=cls._get_list(info, 'Platform'),
)
# links
fields = (
(HOMEPAGE_FIELD, 'Home-Page'),
(DOWNLOAD_FIELD, 'Download-URL'),
)
for key, name in fields:
link = cls._get(info, name)
if link:
root.links[key] = link
for link in cls._get_list(info, 'Project-URL'):
key, url = link.split(', ')
root.links[key.lower()] = url
# authors
for name in ('author', 'maintainer'):
author = cls._get(info, name)
if author:
root.authors += (
Author(name=author, mail=cls._get(info, name + '_email')),
)
# dependencies
deps = []
for req in cls._get_list(info, 'Requires-Dist'):
try:
req = PackagingRequirement(req)
except InvalidRequirement:
cls.logger.warning('invalid requirement', extra=dict(
requirement=req,
package_name=root.name,
package_version=root.version,
))
continue
deps.extend(DependencyMaker.from_requirement(
source=root,
req=req,
url=urls.get(req.name),
))
root.attach_dependencies(deps)
return root