本文整理汇总了Python中pip.req.parse_requirements方法的典型用法代码示例。如果您正苦于以下问题:Python req.parse_requirements方法的具体用法?Python req.parse_requirements怎么用?Python req.parse_requirements使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pip.req
的用法示例。
在下文中一共展示了req.parse_requirements方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from pip import req [as 别名]
# 或者: from pip.req import parse_requirements [as 别名]
def run(self, options, args):
session = self._build_session(options)
requirement_set = RequirementSet(
build_dir=None,
src_dir=None,
download_dir=None,
session=session,
)
for name in args:
requirement_set.add_requirement(
InstallRequirement.from_line(name))
for filename in options.requirements:
for req in parse_requirements(filename,
options=options, session=session):
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)
示例2: read_requirements
# 需要导入模块: from pip import req [as 别名]
# 或者: from pip.req import parse_requirements [as 别名]
def read_requirements(req_file):
"""Reads a requirements file.
Args:
req_file (str): Filename of requirements file
"""
items = list(parse_requirements(req_file, session={}))
result = []
for item in items:
# Get line number from item
line_number = item.comes_from.split(req_file + ' (line ')[1][:-1]
if item.req:
item.req.marker = item.markers
result.append((item.req, line_number))
else:
result.append((item, line_number))
return result
示例3: downloaded_reqs_from_path
# 需要导入模块: from pip import req [as 别名]
# 或者: from pip.req import parse_requirements [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))
示例4: find_python_pip
# 需要导入模块: from pip import req [as 别名]
# 或者: from pip.req import parse_requirements [as 别名]
def find_python_pip(self, file_path):
for requirement in file_path:
if 'requirements.txt' in requirement:
reqs = parse_requirements(filename=requirement, session=False)
for r in reqs:
module_ = r.name
version_ = r.specifier
self._framework.append(module_)
self._result.update(
{
module_: {
'version': str(version_),
'format': 'python',
}
}
)
elif 'package.json' in requirement:
self.find_nodejs_npm([requirement])
示例5: get_requirements
# 需要导入模块: from pip import req [as 别名]
# 或者: from pip.req import parse_requirements [as 别名]
def get_requirements(requirements_file):
"""Use pip to parse requirements file."""
requirements = []
if path.isfile(requirements_file):
for req in parse_requirements(requirements_file, session="hack"):
try:
# check markers, such as
#
# rope_py3k ; python_version >= '3.0'
#
if req.match_markers():
requirements.append(str(req.req))
except AttributeError:
# pip >= 20.0.2
requirements.append(req.requirement)
return requirements
示例6: run
# 需要导入模块: from pip import req [as 别名]
# 或者: from pip.req import parse_requirements [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)
示例7: get_requirements
# 需要导入模块: from pip import req [as 别名]
# 或者: from pip.req import parse_requirements [as 别名]
def get_requirements(filename=None):
"""
Read requirements from 'requirements.txt'
:return: requirements
:rtype: list
"""
if filename is None:
filename = 'requirements.txt'
file = WORK_DIR / filename
install_reqs = parse_requirements(str(file), session='hack')
return [str(ir.req) for ir in install_reqs]
示例8: execute_setup
# 需要导入模块: from pip import req [as 别名]
# 或者: from pip.req import parse_requirements [as 别名]
def execute_setup():
"""
Setup function
"""
if sys.version_info < (2, 0) or sys.version_info >= (3, 0):
sys.exit("i3-xfce only supports python2. Please run setup.py with python2.")
install_reqs = parse_requirements("requirements.txt", session=False)
requirements = [str(ir.req) for ir in install_reqs]
setup(
name="i3-xfce",
version=versioneer.get_version(),
cmdclass=versioneer.get_cmdclass(),
packages=find_packages("src"),
package_dir={'':'src'},
include_package_data=True,
install_requires=requirements,
author="Alexandre ACEBEDO",
author_email="Alexandre ACEBEDO",
description="I3 installer for xfce4",
license="LGPLv3",
keywords="i3 xfce",
url="http://github.com/aacebedo/i3-xfce",
entry_points={'console_scripts':
['i3-xfce = i3xfce.core:main']}
)
示例9: test_PipVCSInstallRequirement
# 需要导入模块: from pip import req [as 别名]
# 或者: from pip.req import parse_requirements [as 别名]
def test_PipVCSInstallRequirement(self):
requirements_str = """
git+https://github.com/foo/bar
git+https://code.google.com/p/foo
git+git://code.google.com/p/foo#egg=bar
"""
expected = [
{
'type': 'vcs',
'key': 'https://github.com/foo/bar',
'repo_url': 'https://github.com/foo/bar',
'unsafe_name': None, 'extras': None, 'modules': None, 'packages': None, 'project_name': None,
'resolved': False, 'specs': None,
},
{
'type': 'vcs',
'key': 'https://code.google.com/p/foo',
'repo_url': 'https://code.google.com/p/foo',
'unsafe_name': None, 'extras': None, 'modules': None, 'packages': None, 'project_name': None,
'resolved': False, 'specs': None,
},
{
'type': 'vcs',
'key': 'bar(git://code.google.com/p/foo)',
'repo_url': 'git://code.google.com/p/foo',
'unsafe_name': 'bar',
'project_name': 'bar',
'specs': [], 'extras': (), 'modules': None, 'packages': None, 'resolved': False,
},
]
handle, requirements_file = tempfile.mkstemp()
with open(requirements_file, 'w') as f:
f.write(requirements_str)
pip_reqs = req.parse_requirements(requirements_file, session=pip.download.PipSession())
reqs = [PipURLInstallRequirement(r).to_dict() for r in pip_reqs]
os.fdopen(handle).close()
os.remove(requirements_file)
self.assertListEqual(expected, reqs)
示例10: _requirements
# 需要导入模块: from pip import req [as 别名]
# 或者: from pip.req import parse_requirements [as 别名]
def _requirements(self):
requirements_txt = os.path.join(self.target_directory, 'requirements.txt')
logger.debug(requirements_txt)
if os.path.isfile(requirements_txt):
requirements = parse_requirements(requirements_txt, session=False)
self.requirements = [req.name.strip().lower() for req in requirements]
logger.debug('requirements modules count: {count} ({modules})'.format(count=len(self.requirements),
modules=','.join(self.requirements)))
else:
logger.debug('requirements.txt not found!')
self.requirements = []
示例11: requirements
# 需要导入模块: from pip import req [as 别名]
# 或者: from pip.req import parse_requirements [as 别名]
def requirements(filename):
reqs = parse_requirements(filename, session=False)
return [str(r.req) for r in reqs]
示例12: requirements_from_file
# 需要导入模块: from pip import req [as 别名]
# 或者: from pip.req import parse_requirements [as 别名]
def requirements_from_file(filename):
requirements = []
for r in parse_requirements(filename, session='fake'):
if r.match_markers():
requirements.append(str(r.req))
return requirements
示例13: get_requirements
# 需要导入模块: from pip import req [as 别名]
# 或者: from pip.req import parse_requirements [as 别名]
def get_requirements():
reqs = parse_requirements('requirements.txt')
return [str(current.req) for current in reqs]
示例14: get_requirements
# 需要导入模块: from pip import req [as 别名]
# 或者: from pip.req import parse_requirements [as 别名]
def get_requirements(cls, file='requirements.txt'):
from pip.req import parse_requirements
return list(parse_requirements(file))
# Setup initial loggers