2013-06-19 14:13:06 +02:00
|
|
|
import logging
|
|
|
|
|
2018-07-30 06:02:47 +02:00
|
|
|
from pip._internal.cli.base_command import Command
|
2020-04-04 11:31:17 +02:00
|
|
|
from pip._internal.cli.status_codes import ERROR, SUCCESS
|
2017-10-28 17:24:19 +02:00
|
|
|
from pip._internal.operations.check import (
|
2019-07-22 06:45:27 +02:00
|
|
|
check_package_set,
|
|
|
|
create_package_set_from_installed,
|
2017-10-28 17:24:19 +02:00
|
|
|
)
|
2019-08-23 02:29:22 +02:00
|
|
|
from pip._internal.utils.misc import write_output
|
2020-04-04 11:31:17 +02:00
|
|
|
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
|
2013-06-19 14:13:06 +02:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2020-04-04 11:31:17 +02:00
|
|
|
if MYPY_CHECK_RUNNING:
|
|
|
|
from optparse import Values
|
2020-09-23 15:08:01 +02:00
|
|
|
from typing import Any, List
|
2020-04-04 11:31:17 +02:00
|
|
|
|
2013-06-19 14:13:06 +02:00
|
|
|
|
|
|
|
class CheckCommand(Command):
|
|
|
|
"""Verify installed packages have compatible dependencies."""
|
2019-07-10 09:36:33 +02:00
|
|
|
|
2013-06-19 14:13:06 +02:00
|
|
|
usage = """
|
|
|
|
%prog [options]"""
|
|
|
|
|
|
|
|
def run(self, options, args):
|
2020-04-04 11:31:17 +02:00
|
|
|
# type: (Values, List[Any]) -> int
|
|
|
|
|
2018-10-02 12:38:16 +02:00
|
|
|
package_set, parsing_probs = create_package_set_from_installed()
|
2017-10-28 17:24:19 +02:00
|
|
|
missing, conflicting = check_package_set(package_set)
|
|
|
|
|
|
|
|
for project_name in missing:
|
2018-01-24 13:28:07 +01:00
|
|
|
version = package_set[project_name].version
|
2017-10-28 17:24:19 +02:00
|
|
|
for dependency in missing[project_name]:
|
2019-08-23 02:29:22 +02:00
|
|
|
write_output(
|
2013-06-19 14:13:06 +02:00
|
|
|
"%s %s requires %s, which is not installed.",
|
2017-10-28 19:22:13 +02:00
|
|
|
project_name, version, dependency[0],
|
2017-12-25 10:53:27 +01:00
|
|
|
)
|
2013-06-19 14:13:06 +02:00
|
|
|
|
2017-10-28 17:24:19 +02:00
|
|
|
for project_name in conflicting:
|
2018-01-24 13:28:07 +01:00
|
|
|
version = package_set[project_name].version
|
2017-10-28 17:24:19 +02:00
|
|
|
for dep_name, dep_version, req in conflicting[project_name]:
|
2019-08-23 02:29:22 +02:00
|
|
|
write_output(
|
2013-06-19 14:13:06 +02:00
|
|
|
"%s %s has requirement %s, but you have %s %s.",
|
2017-10-28 17:24:19 +02:00
|
|
|
project_name, version, req, dep_name, dep_version,
|
2017-12-25 10:53:27 +01:00
|
|
|
)
|
2013-06-19 14:13:06 +02:00
|
|
|
|
2018-10-02 12:38:16 +02:00
|
|
|
if missing or conflicting or parsing_probs:
|
2020-04-04 11:31:17 +02:00
|
|
|
return ERROR
|
2016-06-26 16:20:09 +02:00
|
|
|
else:
|
2019-08-23 02:29:22 +02:00
|
|
|
write_output("No broken requirements found.")
|
2020-04-04 11:31:17 +02:00
|
|
|
return SUCCESS
|