check.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import logging
  2. from pip._internal.basecommand import Command
  3. from pip._internal.operations.check import (
  4. check_package_set, create_package_set_from_installed,
  5. )
  6. from pip._internal.utils.misc import get_installed_distributions
  7. logger = logging.getLogger(__name__)
  8. class CheckCommand(Command):
  9. """Verify installed packages have compatible dependencies."""
  10. name = 'check'
  11. usage = """
  12. %prog [options]"""
  13. summary = 'Verify installed packages have compatible dependencies.'
  14. def run(self, options, args):
  15. package_set = create_package_set_from_installed()
  16. missing, conflicting = check_package_set(package_set)
  17. for project_name in missing:
  18. version = package_set[project_name].version
  19. for dependency in missing[project_name]:
  20. logger.info(
  21. "%s %s requires %s, which is not installed.",
  22. project_name, version, dependency[0],
  23. )
  24. for project_name in conflicting:
  25. version = package_set[project_name].version
  26. for dep_name, dep_version, req in conflicting[project_name]:
  27. logger.info(
  28. "%s %s has requirement %s, but you have %s %s.",
  29. project_name, version, req, dep_name, dep_version,
  30. )
  31. if missing or conflicting:
  32. return 1
  33. else:
  34. logger.info("No broken requirements found.")