check.py 1.6 KB

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