本文整理汇总了Python中pip._internal.req.req_file.parse_requirements方法的典型用法代码示例。如果您正苦于以下问题:Python req_file.parse_requirements方法的具体用法?Python req_file.parse_requirements怎么用?Python req_file.parse_requirements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pip._internal.req.req_file
的用法示例。
在下文中一共展示了req_file.parse_requirements方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_required_modules
# 需要导入模块: from pip._internal.req import req_file [as 别名]
# 或者: from pip._internal.req.req_file import parse_requirements [as 别名]
def find_required_modules(options, requirements_filename: str):
explicit = set()
for requirement in parse_requirements(requirements_filename,
session=PipSession()):
try:
requirement_name = requirement.name
# The type of "requirement" changed between pip versions.
# We exclude the "except" from coverage so that on any pip version we
# can report 100% coverage.
except AttributeError: # pragma: no cover
from pip._internal.req.constructors import install_req_from_line
requirement_name = install_req_from_line(
requirement.requirement,
).name
if options.ignore_reqs(requirement):
log.debug('ignoring requirement: %s', requirement_name)
else:
log.debug('found requirement: %s', requirement_name)
explicit.add(canonicalize_name(requirement_name))
return explicit
示例2: parse_requirement_file
# 需要导入模块: from pip._internal.req import req_file [as 别名]
# 或者: from pip._internal.req.req_file import parse_requirements [as 别名]
def parse_requirement_file(filename):
from pip._internal.req.constructors import install_req_from_parsed_requirement
finder = get_finder([])
ireqs = [
install_req_from_parsed_requirement(pr)
for pr in parse_requirements(filename, finder.session, finder)
]
return ireqs, finder
示例3: get_requirements
# 需要导入模块: from pip._internal.req import req_file [as 别名]
# 或者: from pip._internal.req.req_file import parse_requirements [as 别名]
def get_requirements(requirement):
"""Parse a requirement file
:param requirement: path to requirement file
:returns: list of InstallRequirement
:rtype: list[InstallRequirements]
"""
session = PipSession()
return parse_requirements(requirement, session=session)
示例4: fetch_requirements
# 需要导入模块: from pip._internal.req import req_file [as 别名]
# 或者: from pip._internal.req.req_file import parse_requirements [as 别名]
def fetch_requirements(requirements_file_path):
"""
Return a list of requirements and links by parsing the provided requirements file.
"""
links = []
reqs = []
for req in parse_requirements(requirements_file_path, session=False):
# Note: req.url was used before 9.0.0 and req.link is used in all the recent versions
link = getattr(req, 'link', getattr(req, 'url', None))
if link:
links.append(str(link))
reqs.append(str(req.req))
return (reqs, links)
示例5: load_requirements
# 需要导入模块: from pip._internal.req import req_file [as 别名]
# 或者: from pip._internal.req.req_file import parse_requirements [as 别名]
def load_requirements(file_path):
return tuple((r for r in parse_requirements(file_path, session=False)))
示例6: parse_requirements
# 需要导入模块: from pip._internal.req import req_file [as 别名]
# 或者: from pip._internal.req.req_file import parse_requirements [as 别名]
def parse_requirements(path):
from pip._internal.req import req_file
return req_file.parse_requirements(path, session="unused")
示例7: is_requirements
# 需要导入模块: from pip._internal.req import req_file [as 别名]
# 或者: from pip._internal.req.req_file import parse_requirements [as 别名]
def is_requirements(path):
if not util.is_text_file(path):
return False
try:
list(parse_requirements(path))
except Exception:
return False
else:
return True
示例8: populate_requirement_set
# 需要导入模块: from pip._internal.req import req_file [as 别名]
# 或者: from pip._internal.req.req_file import parse_requirements [as 别名]
def populate_requirement_set(requirement_set, args, options, finder,
session, name, wheel_cache):
"""
Marshal cmd line args into a requirement set.
"""
# NOTE: As a side-effect, options.require_hashes and
# requirement_set.require_hashes may be updated
for filename in options.constraints:
for req_to_add in parse_requirements(
filename,
constraint=True, finder=finder, options=options,
session=session, wheel_cache=wheel_cache):
req_to_add.is_direct = True
requirement_set.add_requirement(req_to_add)
for req in args:
req_to_add = InstallRequirement.from_line(
req, None, isolated=options.isolated_mode,
wheel_cache=wheel_cache
)
req_to_add.is_direct = True
requirement_set.add_requirement(req_to_add)
for req in options.editables:
req_to_add = InstallRequirement.from_editable(
req,
isolated=options.isolated_mode,
wheel_cache=wheel_cache
)
req_to_add.is_direct = True
requirement_set.add_requirement(req_to_add)
for filename in options.requirements:
for req_to_add in parse_requirements(
filename,
finder=finder, options=options, session=session,
wheel_cache=wheel_cache):
req_to_add.is_direct = True
requirement_set.add_requirement(req_to_add)
# If --require-hashes was a line in a requirements file, tell
# RequirementSet about it:
requirement_set.require_hashes = options.require_hashes
if not (args or options.editables or options.requirements):
opts = {'name': name}
if options.find_links:
raise CommandError(
'You must give at least one requirement to %(name)s '
'(maybe you meant "pip %(name)s %(links)s"?)' %
dict(opts, links=' '.join(options.find_links)))
else:
raise CommandError(
'You must give at least one requirement to %(name)s '
'(see "pip help %(name)s")' % opts)
示例9: populate_requirement_set
# 需要导入模块: from pip._internal.req import req_file [as 别名]
# 或者: from pip._internal.req.req_file import parse_requirements [as 别名]
def populate_requirement_set(requirement_set, args, options, finder,
session, name, wheel_cache):
"""
Marshal cmd line args into a requirement set.
"""
# NOTE: As a side-effect, options.require_hashes and
# requirement_set.require_hashes may be updated
for filename in options.constraints:
for req_to_add in parse_requirements(
filename,
constraint=True, finder=finder, options=options,
session=session, wheel_cache=wheel_cache):
req_to_add.is_direct = True
requirement_set.add_requirement(req_to_add)
for req in args:
req_to_add = install_req_from_line(
req, None, isolated=options.isolated_mode,
wheel_cache=wheel_cache
)
req_to_add.is_direct = True
requirement_set.add_requirement(req_to_add)
for req in options.editables:
req_to_add = install_req_from_editable(
req,
isolated=options.isolated_mode,
wheel_cache=wheel_cache
)
req_to_add.is_direct = True
requirement_set.add_requirement(req_to_add)
for filename in options.requirements:
for req_to_add in parse_requirements(
filename,
finder=finder, options=options, session=session,
wheel_cache=wheel_cache):
req_to_add.is_direct = True
requirement_set.add_requirement(req_to_add)
# If --require-hashes was a line in a requirements file, tell
# RequirementSet about it:
requirement_set.require_hashes = options.require_hashes
if not (args or options.editables or options.requirements):
opts = {'name': name}
if options.find_links:
raise CommandError(
'You must give at least one requirement to %(name)s '
'(maybe you meant "pip %(name)s %(links)s"?)' %
dict(opts, links=' '.join(options.find_links)))
else:
raise CommandError(
'You must give at least one requirement to %(name)s '
'(see "pip help %(name)s")' % opts)
示例10: find_missing_reqs
# 需要导入模块: from pip._internal.req import req_file [as 别名]
# 或者: from pip._internal.req.req_file import parse_requirements [as 别名]
def find_missing_reqs(options, requirements_filename):
# 1. find files used by imports in the code (as best we can without
# executing)
used_modules = common.find_imported_modules(options)
# 2. find which packages provide which files
installed_files = {}
all_pkgs = (pkg.project_name for pkg in get_installed_distributions())
for package in search_packages_info(all_pkgs):
log.debug('installed package: %s (at %s)', package['name'],
package['location'])
for package_file in package.get('files', []) or []:
path = os.path.realpath(
os.path.join(package['location'], package_file),
)
installed_files[path] = package['name']
package_path = common.is_package_file(path)
if package_path:
# we've seen a package file so add the bare package directory
# to the installed list as well as we might want to look up
# a package by its directory path later
installed_files[package_path] = package['name']
# 3. match imported modules against those packages
used = collections.defaultdict(list)
for modname, info in used_modules.items():
# probably standard library if it's not in the files list
if info.filename in installed_files:
used_name = canonicalize_name(installed_files[info.filename])
log.debug('used module: %s (from package %s)', modname,
installed_files[info.filename])
used[used_name].append(info)
else:
log.debug(
'used module: %s (from file %s, assuming stdlib or local)',
modname, info.filename)
# 4. compare with requirements.txt
explicit = set()
for requirement in parse_requirements(
requirements_filename,
session=PipSession(),
):
try:
requirement_name = requirement.name
# The type of "requirement" changed between pip versions.
# We exclude the "except" from coverage so that on any pip version we
# can report 100% coverage.
except AttributeError: # pragma: no cover
from pip._internal.req.constructors import install_req_from_line
requirement_name = install_req_from_line(
requirement.requirement,
).name
log.debug('found requirement: %s', requirement_name)
explicit.add(canonicalize_name(requirement_name))
return [(name, used[name]) for name in used if name not in explicit]