You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

__init__.py 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. from __future__ import absolute_import
  2. import logging
  3. from .req_install import InstallRequirement
  4. from .req_set import RequirementSet
  5. from .req_file import parse_requirements
  6. from pip._internal.utils.logging import indent_log
  7. from pip._internal.utils.typing import MYPY_CHECK_RUNNING
  8. if MYPY_CHECK_RUNNING:
  9. from typing import List, Sequence # noqa: F401
  10. __all__ = [
  11. "RequirementSet", "InstallRequirement",
  12. "parse_requirements", "install_given_reqs",
  13. ]
  14. logger = logging.getLogger(__name__)
  15. def install_given_reqs(
  16. to_install, # type: List[InstallRequirement]
  17. install_options, # type: List[str]
  18. global_options=(), # type: Sequence[str]
  19. *args, **kwargs
  20. ):
  21. # type: (...) -> List[InstallRequirement]
  22. """
  23. Install everything in the given list.
  24. (to be called after having downloaded and unpacked the packages)
  25. """
  26. if to_install:
  27. logger.info(
  28. 'Installing collected packages: %s',
  29. ', '.join([req.name for req in to_install]),
  30. )
  31. with indent_log():
  32. for requirement in to_install:
  33. if requirement.conflicts_with:
  34. logger.info(
  35. 'Found existing installation: %s',
  36. requirement.conflicts_with,
  37. )
  38. with indent_log():
  39. uninstalled_pathset = requirement.uninstall(
  40. auto_confirm=True
  41. )
  42. try:
  43. requirement.install(
  44. install_options,
  45. global_options,
  46. *args,
  47. **kwargs
  48. )
  49. except Exception:
  50. should_rollback = (
  51. requirement.conflicts_with and
  52. not requirement.install_succeeded
  53. )
  54. # if install did not succeed, rollback previous uninstall
  55. if should_rollback:
  56. uninstalled_pathset.rollback()
  57. raise
  58. else:
  59. should_commit = (
  60. requirement.conflicts_with and
  61. requirement.install_succeeded
  62. )
  63. if should_commit:
  64. uninstalled_pathset.commit()
  65. requirement.remove_temporary_source()
  66. return to_install