2014-08-31 01:52:28 +02:00
|
|
|
from __future__ import absolute_import
|
2014-01-12 01:50:11 +01:00
|
|
|
|
2017-12-16 14:02:52 +01:00
|
|
|
import logging
|
|
|
|
|
2014-01-12 19:29:59 +01:00
|
|
|
from .req_install import InstallRequirement
|
2017-08-16 18:57:11 +02:00
|
|
|
from .req_set import RequirementSet
|
2014-01-12 19:29:59 +01:00
|
|
|
from .req_file import parse_requirements
|
2017-12-16 14:02:52 +01:00
|
|
|
from pip._internal.utils.logging import indent_log
|
2018-12-17 12:13:00 +01:00
|
|
|
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
|
2017-12-16 14:02:52 +01:00
|
|
|
|
2018-12-17 12:13:00 +01:00
|
|
|
if MYPY_CHECK_RUNNING:
|
2019-02-23 14:27:52 +01:00
|
|
|
from typing import Any, List, Sequence
|
2014-01-12 19:05:11 +01:00
|
|
|
|
2014-01-27 15:07:10 +01:00
|
|
|
__all__ = [
|
2017-08-16 18:57:11 +02:00
|
|
|
"RequirementSet", "InstallRequirement",
|
2017-12-16 14:29:52 +01:00
|
|
|
"parse_requirements", "install_given_reqs",
|
2014-01-27 15:07:10 +01:00
|
|
|
]
|
2017-12-16 14:02:52 +01:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2017-12-16 14:29:52 +01:00
|
|
|
|
2018-12-17 12:13:00 +01:00
|
|
|
def install_given_reqs(
|
|
|
|
to_install, # type: List[InstallRequirement]
|
|
|
|
install_options, # type: List[str]
|
|
|
|
global_options=(), # type: Sequence[str]
|
2018-12-19 17:39:35 +01:00
|
|
|
*args, # type: Any
|
|
|
|
**kwargs # type: Any
|
2018-12-17 12:13:00 +01:00
|
|
|
):
|
|
|
|
# type: (...) -> List[InstallRequirement]
|
2017-12-16 14:02:52 +01:00
|
|
|
"""
|
|
|
|
Install everything in the given list.
|
|
|
|
|
|
|
|
(to be called after having downloaded and unpacked the packages)
|
|
|
|
"""
|
|
|
|
|
|
|
|
if to_install:
|
|
|
|
logger.info(
|
|
|
|
'Installing collected packages: %s',
|
|
|
|
', '.join([req.name for req in to_install]),
|
|
|
|
)
|
|
|
|
|
|
|
|
with indent_log():
|
|
|
|
for requirement in to_install:
|
|
|
|
if requirement.conflicts_with:
|
|
|
|
logger.info(
|
|
|
|
'Found existing installation: %s',
|
|
|
|
requirement.conflicts_with,
|
|
|
|
)
|
|
|
|
with indent_log():
|
|
|
|
uninstalled_pathset = requirement.uninstall(
|
|
|
|
auto_confirm=True
|
|
|
|
)
|
|
|
|
try:
|
|
|
|
requirement.install(
|
|
|
|
install_options,
|
|
|
|
global_options,
|
|
|
|
*args,
|
|
|
|
**kwargs
|
|
|
|
)
|
2018-06-25 13:51:41 +02:00
|
|
|
except Exception:
|
2017-12-16 14:02:52 +01:00
|
|
|
should_rollback = (
|
|
|
|
requirement.conflicts_with and
|
|
|
|
not requirement.install_succeeded
|
|
|
|
)
|
|
|
|
# if install did not succeed, rollback previous uninstall
|
|
|
|
if should_rollback:
|
|
|
|
uninstalled_pathset.rollback()
|
|
|
|
raise
|
|
|
|
else:
|
|
|
|
should_commit = (
|
|
|
|
requirement.conflicts_with and
|
|
|
|
requirement.install_succeeded
|
|
|
|
)
|
|
|
|
if should_commit:
|
|
|
|
uninstalled_pathset.commit()
|
|
|
|
requirement.remove_temporary_source()
|
|
|
|
|
|
|
|
return to_install
|