check.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import logging
  2. from optparse import Values
  3. from typing import Any, 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, args):
  17. # type: (Values, List[Any]) -> int
  18. package_set, parsing_probs = create_package_set_from_installed()
  19. missing, conflicting = check_package_set(package_set)
  20. for project_name in missing:
  21. version = package_set[project_name].version
  22. for dependency in missing[project_name]:
  23. write_output(
  24. "%s %s requires %s, which is not installed.",
  25. project_name, version, dependency[0],
  26. )
  27. for project_name in conflicting:
  28. version = package_set[project_name].version
  29. for dep_name, dep_version, req in conflicting[project_name]:
  30. write_output(
  31. "%s %s has requirement %s, but you have %s %s.",
  32. project_name, version, req, dep_name, dep_version,
  33. )
  34. if missing or conflicting or parsing_probs:
  35. return ERROR
  36. else:
  37. write_output("No broken requirements found.")
  38. return SUCCESS