2013-06-19 14:13:06 +02:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from pip.basecommand import Command
|
2016-11-04 15:55:15 +01:00
|
|
|
from pip.operations.check import check_requirements
|
|
|
|
from pip.utils import get_installed_distributions
|
2013-06-19 14:13:06 +02:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class CheckCommand(Command):
|
|
|
|
"""Verify installed packages have compatible dependencies."""
|
|
|
|
name = 'check'
|
|
|
|
usage = """
|
|
|
|
%prog [options]"""
|
|
|
|
summary = 'Verify installed packages have compatible dependencies.'
|
|
|
|
|
|
|
|
def run(self, options, args):
|
2016-11-04 15:55:15 +01:00
|
|
|
dists = get_installed_distributions(local_only=False, skip=())
|
|
|
|
missing_reqs_dict, incompatible_reqs_dict = check_requirements(dists)
|
2013-06-19 14:13:06 +02:00
|
|
|
|
2016-11-04 15:55:15 +01:00
|
|
|
for dist in dists:
|
2016-11-04 15:36:03 +01:00
|
|
|
for requirement in missing_reqs_dict.get(dist.key, []):
|
2013-06-19 14:13:06 +02:00
|
|
|
logger.info(
|
|
|
|
"%s %s requires %s, which is not installed.",
|
|
|
|
dist.project_name, dist.version, requirement.project_name)
|
|
|
|
|
2016-11-04 15:36:03 +01:00
|
|
|
for requirement, actual in incompatible_reqs_dict.get(
|
|
|
|
dist.key, []):
|
2013-06-19 14:13:06 +02:00
|
|
|
logger.info(
|
|
|
|
"%s %s has requirement %s, but you have %s %s.",
|
|
|
|
dist.project_name, dist.version, requirement,
|
|
|
|
actual.project_name, actual.version)
|
|
|
|
|
|
|
|
if missing_reqs_dict or incompatible_reqs_dict:
|
|
|
|
return 1
|
2016-06-26 16:20:09 +02:00
|
|
|
else:
|
|
|
|
logger.info("No broken requirements found.")
|