本文整理汇总了Python中pip.req方法的典型用法代码示例。如果您正苦于以下问题:Python pip.req方法的具体用法?Python pip.req怎么用?Python pip.req使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pip
的用法示例。
在下文中一共展示了pip.req方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import pip [as 别名]
# 或者: from pip import req [as 别名]
def __init__(self, req, argv, finder):
"""Download a requirement, compare its hashes, and return a subclass
of DownloadedReq depending on its state.
:arg req: The InstallRequirement I am based on
:arg argv: The args, starting after the subcommand
"""
self._req = req
self._argv = argv
self._finder = finder
# We use a separate temp dir for each requirement so requirements
# (from different indices) that happen to have the same archive names
# don't overwrite each other, leading to a security hole in which the
# latter is a hash mismatch, the former has already passed the
# comparison, and the latter gets installed.
self._temp_path = mkdtemp(prefix='peep-')
# Think of DownloadedReq as a one-shot state machine. It's an abstract
# class that ratchets forward to being one of its own subclasses,
# depending on its package status. Then it doesn't move again.
self.__class__ = self._class()
示例2: downloaded_reqs_from_path
# 需要导入模块: import pip [as 别名]
# 或者: from pip import req [as 别名]
def downloaded_reqs_from_path(path, argv):
"""Return a list of DownloadedReqs representing the requirements parsed
out of a given requirements file.
:arg path: The path to the requirements file
:arg argv: The commandline args, starting after the subcommand
"""
finder = package_finder(argv)
def downloaded_reqs(parsed_reqs):
"""Just avoid repeating this list comp."""
return [DownloadedReq(req, argv, finder) for req in parsed_reqs]
try:
return downloaded_reqs(parse_requirements(
path, options=EmptyOptions(), finder=finder))
except TypeError:
# session is a required kwarg as of pip 6.0 and will raise
# a TypeError if missing. It needs to be a PipSession instance,
# but in older versions we can't import it from pip.download
# (nor do we need it at all) so we only import it in this except block
from pip.download import PipSession
return downloaded_reqs(parse_requirements(
path, options=EmptyOptions(), session=PipSession(), finder=finder))
示例3: merge_source_requirements
# 需要导入模块: import pip [as 别名]
# 或者: from pip import req [as 别名]
def merge_source_requirements(sources):
"""
Read requirements source files and merge it's content.
"""
projects = set()
merged_requirements = []
for infile_path in (locate_file(p, must_exist=True) for p in sources):
for req in load_requirements(infile_path):
# Requirements starting with project name "project ..."
if req.req:
# Skip already added project name
if req.name in projects:
continue
projects.add(req.name)
merged_requirements.append(req)
# Requirements lines like "vcs+proto://url"
elif req.link:
merged_requirements.append(req)
else:
raise RuntimeError('Unexpected requirement {0}'.format(req))
return merged_requirements
示例4: run
# 需要导入模块: import pip [as 别名]
# 或者: from pip import req [as 别名]
def run(self, options, args):
with self._build_session(options) as session:
format_control = pip.index.FormatControl(set(), set())
wheel_cache = WheelCache(options.cache_dir, format_control)
requirement_set = RequirementSet(
build_dir=None,
src_dir=None,
download_dir=None,
isolated=options.isolated_mode,
session=session,
wheel_cache=wheel_cache,
)
for name in args:
requirement_set.add_requirement(
InstallRequirement.from_line(
name, isolated=options.isolated_mode,
wheel_cache=wheel_cache
)
)
for filename in options.requirements:
for req in parse_requirements(
filename,
options=options,
session=session,
wheel_cache=wheel_cache):
requirement_set.add_requirement(req)
if not requirement_set.has_requirements:
raise InstallationError(
'You must give at least one requirement to %(name)s (see '
'"pip help %(name)s")' % dict(name=self.name)
)
requirement_set.uninstall(auto_confirm=options.yes)
示例5: _project_name
# 需要导入模块: import pip [as 别名]
# 或者: from pip import req [as 别名]
def _project_name(self):
"""Return the inner Requirement's "unsafe name".
Raise ValueError if there is no name.
"""
name = getattr(self._req.req, 'project_name', '')
if name:
return name
raise ValueError('Requirement has no project_name.')
示例6: get_requirements
# 需要导入模块: import pip [as 别名]
# 或者: from pip import req [as 别名]
def get_requirements(cls, file='requirements.txt'):
from pip.req import parse_requirements
return list(parse_requirements(file))
# Setup initial loggers
示例7: fetch_requirements
# 需要导入模块: import pip [as 别名]
# 或者: from pip import req [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)
示例8: get_install_requirements
# 需要导入模块: import pip [as 别名]
# 或者: from pip import req [as 别名]
def get_install_requirements(path):
content = open(os.path.join(os.path.dirname(__file__), path)).read()
return [
req
for req in content.split("\n")
if req != '' and not req.startswith('#')
]
# Get version from __init__.py file
示例9: __init__
# 需要导入模块: import pip [as 别名]
# 或者: from pip import req [as 别名]
def __init__(self, req):
self.req = req