From cf65b19904ab5284b1bc49c050c36e48fe81fd7f Mon Sep 17 00:00:00 2001 From: q0w <43147888+q0w@users.noreply.github.com> Date: Thu, 2 Jun 2022 20:45:50 +0300 Subject: [PATCH] Check dependencies --- src/pip/_internal/commands/check.py | 16 ++++++++++++---- src/pip/_internal/operations/check.py | 3 +++ tests/functional/test_check.py | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/pip/_internal/commands/check.py b/src/pip/_internal/commands/check.py index 93746abd7e4..133e50b6944 100644 --- a/src/pip/_internal/commands/check.py +++ b/src/pip/_internal/commands/check.py @@ -1,5 +1,5 @@ import logging -from optparse import Values +from optparse import Option, OptionParser, Values from typing import Callable, List, Optional from pip._internal.cli.base_command import Command @@ -13,6 +13,13 @@ logger = logging.getLogger(__name__) +def _handle_ignore_packages( + option: Option, opt_str: str, value: str, parser: OptionParser +) -> None: + assert option.dest is not None + setattr(parser.values, option.dest, set(value.split(","))) + + class CheckCommand(Command): """Verify installed packages have compatible dependencies.""" @@ -22,10 +29,11 @@ class CheckCommand(Command): def add_options(self) -> None: self.cmd_opts.add_option( "--ignore-packages", - action="append", - metavar="PACKAGE", + action="callback", + callback=_handle_ignore_packages, + metavar="package", + type="str", dest="ignore_packages", - default=[], help="Ignore packages.", ) self.parser.insert_option_group(0, self.cmd_opts) diff --git a/src/pip/_internal/operations/check.py b/src/pip/_internal/operations/check.py index fb3ac8b9c9e..f75e1c8ee93 100644 --- a/src/pip/_internal/operations/check.py +++ b/src/pip/_internal/operations/check.py @@ -71,6 +71,9 @@ def check_package_set( for req in package_detail.dependencies: name = canonicalize_name(req.name) + if should_ignore and should_ignore(name): + continue + # Check if it's missing if name not in package_set: missed = True diff --git a/tests/functional/test_check.py b/tests/functional/test_check.py index 13fea7b8c17..3deca0f62c4 100644 --- a/tests/functional/test_check.py +++ b/tests/functional/test_check.py @@ -323,7 +323,7 @@ def test_check_ignore_packages(script: PipTestEnvironment) -> None: result = script.pip("install", "--no-index", package_a_path, "--no-deps") assert "Successfully installed package-A-1.0" in result.stdout, str(result) - result = script.pip("check", "--ignore-packages=package-a") + result = script.pip("check", "--ignore-packages=missing") expected_lines = ("No broken requirements found.",) assert matches_expected_lines(result.stdout, expected_lines) assert result.returncode == 0