check.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import logging
  2. from pip._internal.cli.base_command import Command
  3. from pip._internal.cli.status_codes import ERROR, SUCCESS
  4. from pip._internal.operations.check import (
  5. check_package_set,
  6. create_package_set_from_installed,
  7. )
  8. from pip._internal.utils.misc import write_output
  9. from pip._internal.utils.typing import MYPY_CHECK_RUNNING
  10. logger = logging.getLogger(__name__)
  11. if MYPY_CHECK_RUNNING:
  12. from typing import List, Any
  13. from optparse import Values
  14. class CheckCommand(Command):
  15. """Verify installed packages have compatible dependencies."""
  16. usage = """
  17. %prog [options]"""
  18. def run(self, options, args):
  19. # type: (Values, List[Any]) -> int
  20. package_set, parsing_probs = create_package_set_from_installed()
  21. missing, conflicting = check_package_set(package_set)
  22. for project_name in missing:
  23. version = package_set[project_name].version
  24. for dependency in missing[project_name]:
  25. write_output(
  26. "%s %s requires %s, which is not installed.",
  27. project_name, version, dependency[0],
  28. )
  29. for project_name in conflicting:
  30. version = package_set[project_name].version
  31. for dep_name, dep_version, req in conflicting[project_name]:
  32. write_output(
  33. "%s %s has requirement %s, but you have %s %s.",
  34. project_name, version, req, dep_name, dep_version,
  35. )
  36. if missing or conflicting or parsing_probs:
  37. return ERROR
  38. else:
  39. write_output("No broken requirements found.")
  40. return SUCCESS