本文整理汇总了Python中pip._internal.req.constructors.install_req_from_line方法的典型用法代码示例。如果您正苦于以下问题:Python constructors.install_req_from_line方法的具体用法?Python constructors.install_req_from_line怎么用?Python constructors.install_req_from_line使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pip._internal.req.constructors
的用法示例。
在下文中一共展示了constructors.install_req_from_line方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_required_modules
# 需要导入模块: from pip._internal.req import constructors [as 别名]
# 或者: from pip._internal.req.constructors import install_req_from_line [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: run
# 需要导入模块: from pip._internal.req import constructors [as 别名]
# 或者: from pip._internal.req.constructors import install_req_from_line [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()
示例3: run
# 需要导入模块: from pip._internal.req import constructors [as 别名]
# 或者: from pip._internal.req.constructors import install_req_from_line [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()
示例4: make_install_requirement
# 需要导入模块: from pip._internal.req import constructors [as 别名]
# 或者: from pip._internal.req.constructors import install_req_from_line [as 别名]
def make_install_requirement(name, version, extras, constraint=False):
# If no extras are specified, the extras string is blank
extras_string = ""
if extras:
# Sort extras for stability
extras_string = "[{}]".format(",".join(sorted(extras)))
return install_req_from_line(
str("{}{}=={}".format(name, extras_string, version)), constraint=constraint
)
示例5: ignorer
# 需要导入模块: from pip._internal.req import constructors [as 别名]
# 或者: from pip._internal.req.constructors import install_req_from_line [as 别名]
def ignorer(ignore_cfg):
if not ignore_cfg:
return lambda candidate: False
def f(candidate, ignore_cfg=ignore_cfg):
for ignore in ignore_cfg:
try:
from pip._internal.req.constructors import (
install_req_from_line,
)
candidate_path = install_req_from_line( # pragma: no cover
candidate.requirement,
).name
except (ImportError, AttributeError):
try:
candidate_path = candidate.name
except AttributeError:
candidate_path = candidate
if fnmatch.fnmatch(candidate_path, ignore):
return True
elif fnmatch.fnmatch(os.path.relpath(candidate_path), ignore):
return True
return False
return f
示例6: run
# 需要导入模块: from pip._internal.req import constructors [as 别名]
# 或者: from pip._internal.req.constructors import install_req_from_line [as 别名]
def run(self, options, args):
"""update install options with caching values"""
if options.prune:
previously_installed = pip_get_installed()
index_urls = [options.index_url] + options.extra_index_urls
with pipfaster_download_cacher(index_urls):
requirement_set = super(FasterInstallCommand, self).run(
options, args,
)
required = requirement_set.requirements.values()
# With extra_index_urls we don't know where the wheel is from
if not options.extra_index_urls:
cache_installed_wheels(options.index_url, requirement_set.successfully_downloaded)
if not options.ignore_dependencies:
# transitive requirements, previously installed, are also required
# this has a side-effect of finding any missing / conflicting requirements
required = trace_requirements(required)
if not options.prune:
return requirement_set
extraneous = (
reqnames(previously_installed) -
reqnames(required) -
# the stage1 bootstrap packages
reqnames(trace_requirements([install_req_from_line('venv-update')])) -
# See #186
frozenset(('pkg-resources',))
)
if extraneous:
extraneous = sorted(extraneous)
pip(('uninstall', '--yes') + tuple(extraneous))
# TODO: Cleanup: remove stale values from the cache and wheelhouse that have not been accessed in a week.
# TODO: a pip_faster.patch module
示例7: _iter_dependencies
# 需要导入模块: from pip._internal.req import constructors [as 别名]
# 或者: from pip._internal.req.constructors import install_req_from_line [as 别名]
def _iter_dependencies(self, ireq):
"""
Given a pinned, url, or editable InstallRequirement, collects all the
secondary dependencies for them, either by looking them up in a local
cache, or by reaching out to the repository.
Editable requirements will never be looked up, as they may have
changed at any time.
"""
# Pip does not resolve dependencies of constraints. We skip handling
# constraints here as well to prevent the cache from being polluted.
# Constraints that are later determined to be dependencies will be
# marked as non-constraints in later rounds by
# `combine_install_requirements`, and will be properly resolved.
# See https://github.com/pypa/pip/
# blob/6896dfcd831330c13e076a74624d95fa55ff53f4/src/pip/_internal/
# legacy_resolve.py#L325
if ireq.constraint:
return
if ireq.editable or is_url_requirement(ireq):
for dependency in self.repository.get_dependencies(ireq):
yield dependency
return
elif not is_pinned_requirement(ireq):
raise TypeError(
"Expected pinned or editable requirement, got {}".format(ireq)
)
# Now, either get the dependencies from the dependency cache (for
# speed), or reach out to the external repository to
# download and inspect the package version and get dependencies
# from there
if ireq not in self.dependency_cache:
log.debug(
"{} not in cache, need to check index".format(format_requirement(ireq)),
fg="yellow",
)
dependencies = self.repository.get_dependencies(ireq)
self.dependency_cache[ireq] = sorted(str(ireq.req) for ireq in dependencies)
# Example: ['Werkzeug>=0.9', 'Jinja2>=2.4']
dependency_strings = self.dependency_cache[ireq]
log.debug(
"{:25} requires {}".format(
format_requirement(ireq),
", ".join(sorted(dependency_strings, key=lambda s: s.lower())) or "-",
)
)
for dependency_string in dependency_strings:
yield install_req_from_line(
dependency_string, constraint=ireq.constraint, comes_from=ireq
)
示例8: find_missing_reqs
# 需要导入模块: from pip._internal.req import constructors [as 别名]
# 或者: from pip._internal.req.constructors import install_req_from_line [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]