Skip to content

Commit

Permalink
Check dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
q0w committed Jun 2, 2022
1 parent 90cf29b commit cf65b19
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/pip/_internal/commands/check.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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."""

Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/pip/_internal/operations/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cf65b19

Please sign in to comment.