本文整理匯總了Python中pip._internal.req.parse_requirements方法的典型用法代碼示例。如果您正苦於以下問題:Python req.parse_requirements方法的具體用法?Python req.parse_requirements怎麽用?Python req.parse_requirements使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pip._internal.req
的用法示例。
在下文中一共展示了req.parse_requirements方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: read_requirements
# 需要導入模塊: from pip._internal import req [as 別名]
# 或者: from pip._internal.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
示例2: find_python_pip
# 需要導入模塊: from pip._internal import req [as 別名]
# 或者: from pip._internal.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])
示例3: get_requirements
# 需要導入模塊: from pip._internal import req [as 別名]
# 或者: from pip._internal.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
示例4: get_requirements
# 需要導入模塊: from pip._internal import req [as 別名]
# 或者: from pip._internal.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]
示例5: run
# 需要導入模塊: from pip._internal import req [as 別名]
# 或者: from pip._internal.req import parse_requirements [as 別名]
def run(self, options, args):
with self._build_session(options) as session:
reqs_to_uninstall = {}
for name in args:
req = InstallRequirement.from_line(
name, isolated=options.isolated_mode,
)
if req.name:
reqs_to_uninstall[canonicalize_name(req.name)] = req
for filename in options.requirements:
for req in parse_requirements(
filename,
options=options,
session=session):
if req.name:
reqs_to_uninstall[canonicalize_name(req.name)] = req
if not reqs_to_uninstall:
raise InstallationError(
'You must give at least one requirement to %(name)s (see '
'"pip help %(name)s")' % dict(name=self.name)
)
for req in reqs_to_uninstall.values():
uninstall_pathset = req.uninstall(
auto_confirm=options.yes, verbose=self.verbosity > 0,
)
if uninstall_pathset:
uninstall_pathset.commit()
示例6: run
# 需要導入模塊: from pip._internal import req [as 別名]
# 或者: from pip._internal.req import parse_requirements [as 別名]
def run(self, options, args):
with self._build_session(options) as session:
reqs_to_uninstall = {}
for name in args:
req = install_req_from_line(
name, isolated=options.isolated_mode,
)
if req.name:
reqs_to_uninstall[canonicalize_name(req.name)] = req
for filename in options.requirements:
for req in parse_requirements(
filename,
options=options,
session=session):
if req.name:
reqs_to_uninstall[canonicalize_name(req.name)] = req
if not reqs_to_uninstall:
raise InstallationError(
'You must give at least one requirement to %(name)s (see '
'"pip help %(name)s")' % dict(name=self.name)
)
protect_pip_from_modification_on_windows(
modifying_pip="pip" in reqs_to_uninstall
)
for req in reqs_to_uninstall.values():
uninstall_pathset = req.uninstall(
auto_confirm=options.yes, verbose=self.verbosity > 0,
)
if uninstall_pathset:
uninstall_pathset.commit()
示例7: run
# 需要導入模塊: from pip._internal import req [as 別名]
# 或者: from pip._internal.req import parse_requirements [as 別名]
def run(self, options, args):
session = self.get_default_session(options)
reqs_to_uninstall = {}
for name in args:
req = install_req_from_line(
name, isolated=options.isolated_mode,
)
if req.name:
reqs_to_uninstall[canonicalize_name(req.name)] = req
for filename in options.requirements:
for req in parse_requirements(
filename,
options=options,
session=session):
if req.name:
reqs_to_uninstall[canonicalize_name(req.name)] = req
if not reqs_to_uninstall:
raise InstallationError(
'You must give at least one requirement to %(name)s (see '
'"pip help %(name)s")' % dict(name=self.name)
)
protect_pip_from_modification_on_windows(
modifying_pip="pip" in reqs_to_uninstall
)
for req in reqs_to_uninstall.values():
uninstall_pathset = req.uninstall(
auto_confirm=options.yes, verbose=self.verbosity > 0,
)
if uninstall_pathset:
uninstall_pathset.commit()
示例8: _requirements
# 需要導入模塊: from pip._internal import req [as 別名]
# 或者: from pip._internal.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 = []
示例9: run
# 需要導入模塊: from pip._internal import req [as 別名]
# 或者: from pip._internal.req import parse_requirements [as 別名]
def run(self, options, args):
with self._build_session(options) as session:
reqs_to_uninstall = {}
for name in args:
req = InstallRequirement.from_line(
name, isolated=options.isolated_mode,
)
if req.name:
reqs_to_uninstall[canonicalize_name(req.name)] = req
for filename in options.requirements:
for req in parse_requirements(
filename,
options=options,
session=session):
if req.name:
reqs_to_uninstall[canonicalize_name(req.name)] = req
if not reqs_to_uninstall:
raise InstallationError(
'You must give at least one requirement to %(name)s (see '
'"pip help %(name)s")' % dict(name=self.name)
)
protect_pip_from_modification_on_windows(
modifying_pip="pip" in reqs_to_uninstall
)
for req in reqs_to_uninstall.values():
uninstall_pathset = req.uninstall(
auto_confirm=options.yes, verbose=self.verbosity > 0,
)
if uninstall_pathset:
uninstall_pathset.commit()
示例10: requirements
# 需要導入模塊: from pip._internal import req [as 別名]
# 或者: from pip._internal.req import parse_requirements [as 別名]
def requirements(filename):
reqs = parse_requirements(filename, session=False)
return [str(r.req) for r in reqs]
示例11: run
# 需要導入模塊: from pip._internal import req [as 別名]
# 或者: from pip._internal.req import parse_requirements [as 別名]
def run(self, options, args):
session = self.get_default_session(options)
reqs_to_uninstall = {}
for name in args:
req = install_req_from_line(
name, isolated=options.isolated_mode,
)
if req.name:
reqs_to_uninstall[canonicalize_name(req.name)] = req
for filename in options.requirements:
for parsed_req in parse_requirements(
filename,
options=options,
session=session):
req = install_req_from_parsed_requirement(
parsed_req,
isolated=options.isolated_mode
)
if req.name:
reqs_to_uninstall[canonicalize_name(req.name)] = req
if not reqs_to_uninstall:
raise InstallationError(
'You must give at least one requirement to {self.name} (see '
'"pip help {self.name}")'.format(**locals())
)
protect_pip_from_modification_on_windows(
modifying_pip="pip" in reqs_to_uninstall
)
for req in reqs_to_uninstall.values():
uninstall_pathset = req.uninstall(
auto_confirm=options.yes, verbose=self.verbosity > 0,
)
if uninstall_pathset:
uninstall_pathset.commit()
示例12: parse_requirements
# 需要導入模塊: from pip._internal import req [as 別名]
# 或者: from pip._internal.req import parse_requirements [as 別名]
def parse_requirements(
filename, session, finder=None, options=None, constraint=False, isolated=False
):
for parsed_req in _parse_requirements(
filename, session, finder=finder, options=options, constraint=constraint
):
yield install_req_from_parsed_requirement(parsed_req, isolated=isolated)
示例13: install_requires
# 需要導入模塊: from pip._internal import req [as 別名]
# 或者: from pip._internal.req import parse_requirements [as 別名]
def install_requires():
file = WORK_DIR / "requirements.txt"
install_reqs = parse_requirements(str(file), session='sync')
return [str(ir.req) for ir in install_reqs]
示例14: load_requirements
# 需要導入模塊: from pip._internal import req [as 別名]
# 或者: from pip._internal.req import parse_requirements [as 別名]
def load_requirements(fname):
reqs = parse_requirements(fname, session="test")
return [str(ir.req) for ir in reqs]