from __future__ import absolute_import import collections import logging from pip._internal.utils.logging import indent_log from pip._internal.utils.typing import MYPY_CHECK_RUNNING from .req_file import parse_requirements from .req_install import InstallRequirement from .req_set import RequirementSet if MYPY_CHECK_RUNNING: from typing import Iterator, List, Optional, Sequence, Tuple __all__ = [ "RequirementSet", "InstallRequirement", "parse_requirements", "install_given_reqs", ] logger = logging.getLogger(__name__) class InstallationResult(object): def __init__(self, name): # type: (str) -> None self.name = name def __repr__(self): # type: () -> str return "InstallationResult(name={!r})".format(self.name) def _validate_requirements( requirements, # type: List[InstallRequirement] ): # type: (...) -> Iterator[Tuple[str, InstallRequirement]] for req in requirements: assert req.name, "invalid to-be-installed requirement: {}".format(req) yield req.name, req def install_given_reqs( requirements, # type: List[InstallRequirement] install_options, # type: List[str] global_options, # type: Sequence[str] root, # type: Optional[str] home, # type: Optional[str] prefix, # type: Optional[str] warn_script_location, # type: bool use_user_site, # type: bool pycompile, # type: bool ): # type: (...) -> List[InstallationResult] """ Install everything in the given list. (to be called after having downloaded and unpacked the packages) """ to_install = collections.OrderedDict(_validate_requirements(requirements)) if to_install: logger.info( 'Installing collected packages: %s', ', '.join(to_install.keys()), ) installed = [] with indent_log(): for req_name, requirement in to_install.items(): if requirement.should_reinstall: logger.info('Attempting uninstall: %s', req_name) with indent_log(): uninstalled_pathset = requirement.uninstall( auto_confirm=True ) else: uninstalled_pathset = None try: requirement.install( install_options, global_options, root=root, home=home, prefix=prefix, warn_script_location=warn_script_location, use_user_site=use_user_site, pycompile=pycompile, ) except Exception: # if install did not succeed, rollback previous uninstall if uninstalled_pathset and not requirement.install_succeeded: uninstalled_pathset.rollback() raise else: if uninstalled_pathset and requirement.install_succeeded: uninstalled_pathset.commit() installed.append(InstallationResult(req_name)) return installed
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
__pycache__ | Folder | 0755 |
|
|
.constructors.pyo.40009 | File | 13.67 KB | 0644 |
|
__init__.py | File | 3.06 KB | 0644 |
|
__init__.pyc | File | 3.09 KB | 0644 |
|
__init__.pyo | File | 3 KB | 0644 |
|
constructors.py | File | 16 KB | 0644 |
|
constructors.pyc | File | 13.67 KB | 0644 |
|
constructors.pyo | File | 13.67 KB | 0644 |
|
req_file.py | File | 18.99 KB | 0644 |
|
req_file.pyc | File | 16.17 KB | 0644 |
|
req_file.pyo | File | 16.08 KB | 0644 |
|
req_install.py | File | 32.88 KB | 0644 |
|
req_install.pyc | File | 25.84 KB | 0644 |
|
req_install.pyo | File | 24.94 KB | 0644 |
|
req_set.py | File | 7.7 KB | 0644 |
|
req_set.pyc | File | 7.04 KB | 0644 |
|
req_set.pyo | File | 6.89 KB | 0644 |
|
req_tracker.py | File | 4.58 KB | 0644 |
|
req_tracker.pyc | File | 5.22 KB | 0644 |
|
req_tracker.pyo | File | 5.09 KB | 0644 |
|
req_uninstall.py | File | 23.15 KB | 0644 |
|
req_uninstall.pyc | File | 21.78 KB | 0644 |
|
req_uninstall.pyo | File | 21.65 KB | 0644 |
|