check.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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: Values, args: List[Any]) -> 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, version, dependency[0],
  25. )
  26. for project_name in conflicting:
  27. version = package_set[project_name].version
  28. for dep_name, dep_version, req in conflicting[project_name]:
  29. write_output(
  30. "%s %s has requirement %s, but you have %s %s.",
  31. project_name, version, req, dep_name, dep_version,
  32. )
  33. if missing or conflicting or parsing_probs:
  34. return ERROR
  35. else:
  36. write_output("No broken requirements found.")
  37. return SUCCESS