check.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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.operations.check import (
  7. check_package_set,
  8. create_package_set_from_installed,
  9. warn_legacy_versions_and_specifiers,
  10. )
  11. from pip._internal.utils.misc import write_output
  12. logger = logging.getLogger(__name__)
  13. class CheckCommand(Command):
  14. """Verify installed packages have compatible dependencies."""
  15. usage = """
  16. %prog [options]"""
  17. def run(self, options: Values, args: List[str]) -> int:
  18. package_set, parsing_probs = create_package_set_from_installed()
  19. warn_legacy_versions_and_specifiers(package_set)
  20. missing, conflicting = check_package_set(package_set)
  21. for project_name in missing:
  22. version = package_set[project_name].version
  23. for dependency in missing[project_name]:
  24. write_output(
  25. "%s %s requires %s, which is not installed.",
  26. project_name,
  27. version,
  28. dependency[0],
  29. )
  30. for project_name in conflicting:
  31. version = package_set[project_name].version
  32. for dep_name, dep_version, req in conflicting[project_name]:
  33. write_output(
  34. "%s %s has requirement %s, but you have %s %s.",
  35. project_name,
  36. version,
  37. req,
  38. dep_name,
  39. dep_version,
  40. )
  41. if missing or conflicting or parsing_probs:
  42. return ERROR
  43. else:
  44. write_output("No broken requirements found.")
  45. return SUCCESS