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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. __all__ = [
  8. "RequirementSet", "InstallRequirement",
  9. "parse_requirements", "install_given_reqs",
  10. ]
  11. logger = logging.getLogger(__name__)
  12. def install_given_reqs(to_install, install_options, global_options=(),
  13. *args, **kwargs):
  14. """
  15. Install everything in the given list.
  16. (to be called after having downloaded and unpacked the packages)
  17. """
  18. if to_install:
  19. logger.info(
  20. 'Installing collected packages: %s',
  21. ', '.join([req.name for req in to_install]),
  22. )
  23. with indent_log():
  24. for requirement in to_install:
  25. if requirement.conflicts_with:
  26. logger.info(
  27. 'Found existing installation: %s',
  28. requirement.conflicts_with,
  29. )
  30. with indent_log():
  31. uninstalled_pathset = requirement.uninstall(
  32. auto_confirm=True
  33. )
  34. try:
  35. requirement.install(
  36. install_options,
  37. global_options,
  38. *args,
  39. **kwargs
  40. )
  41. except:
  42. should_rollback = (
  43. requirement.conflicts_with and
  44. not requirement.install_succeeded
  45. )
  46. # if install did not succeed, rollback previous uninstall
  47. if should_rollback:
  48. uninstalled_pathset.rollback()
  49. raise
  50. else:
  51. should_commit = (
  52. requirement.conflicts_with and
  53. requirement.install_succeeded
  54. )
  55. if should_commit:
  56. uninstalled_pathset.commit()
  57. requirement.remove_temporary_source()
  58. return to_install