check.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import logging
  2. from optparse import Values
  3. from typing import List
  4. from pip._internal.cli.base_command import Command
  5. from pip._internal.cli.status_codes import ERROR, SUCCESS
  6. from pip._internal.metadata import get_default_environment
  7. from pip._internal.operations.check import (
  8. check_package_set,
  9. check_unsupported,
  10. create_package_set_from_installed,
  11. )
  12. from pip._internal.utils.compatibility_tags import get_supported
  13. from pip._internal.utils.misc import write_output
  14. logger = logging.getLogger(__name__)
  15. class CheckCommand(Command):
  16. """Verify installed packages have compatible dependencies."""
  17. ignore_require_venv = True
  18. usage = """
  19. %prog [options]"""
  20. def run(self, options: Values, args: List[str]) -> int:
  21. package_set, parsing_probs = create_package_set_from_installed()
  22. missing, conflicting = check_package_set(package_set)
  23. unsupported = list(
  24. check_unsupported(
  25. get_default_environment().iter_installed_distributions(),
  26. get_supported(),
  27. )
  28. )
  29. for project_name in missing:
  30. version = package_set[project_name].version
  31. for dependency in missing[project_name]:
  32. write_output(
  33. "%s %s requires %s, which is not installed.",
  34. project_name,
  35. version,
  36. dependency[0],
  37. )
  38. for project_name in conflicting:
  39. version = package_set[project_name].version
  40. for dep_name, dep_version, req in conflicting[project_name]:
  41. write_output(
  42. "%s %s has requirement %s, but you have %s %s.",
  43. project_name,
  44. version,
  45. req,
  46. dep_name,
  47. dep_version,
  48. )
  49. for package in unsupported:
  50. write_output(
  51. "%s %s is not supported on this platform",
  52. package.raw_name,
  53. package.version,
  54. )
  55. if missing or conflicting or parsing_probs or unsupported:
  56. return ERROR
  57. else:
  58. write_output("No broken requirements found.")
  59. return SUCCESS