Repository: fpgmaas/deptry (language: python)

Issue:
Remove deprecated `ignore_*` and `skip_*` options
`ignore_*` and `skip_*` options have been deprecated in [0.12.0](https://github.com/fpgmaas/deptry/releases/tag/0.12.0), with warnings about their deprecation and replacements. We could completely remove them in a new minor release, since we are still using 0.x versioning scheme.

This would effectively remove the following options:
- with replacements in `[tool.deptry]`:
  - `ignore_misplaced-dev` -> replaced with `ignore = ["DEP004"]`
  - `ignore_missing` -> replaced with `ignore = ["DEP001"]`
  - `ignore_obsolete` -> replaced with `ignore = ["DEP002"]`
  - `ignore_transitive` -> replaced with `ignore = ["DEP003"]`
  - `ignore_unused` -> replaced with `ignore = ["DEP002"]`
- with replacements in `[tool.deptry.per_rule_ignores]`:
  - `skip_misplaced_dev` -> replaced with `DEP004 = ["dep", ...]`
  - `skip_missing ` -> replaced with `DEP001 = ["dep", ...]`
  - `skip_obsolete` -> replaced with `DEP002 = ["dep", ...]`
  - `skip_transitive` -> replaced with `DEP003 = ["dep", ...]`
  - `skip_unused` -> replaced with `DEP002 = ["dep", ...]`

In order to facilitate the removal of those options, https://github.com/fpgmaas/deptry/pull/571 would be really nice to have, as without it, removed options that are still set in `[tool.poetry]` will be ignored instead of raising an error.


Discussion / hints:

Fix patch:
diff --git a/python/deptry/cli.py b/python/deptry/cli.py
index 0d395607..a4d206bc 100644
--- a/python/deptry/cli.py
+++ b/python/deptry/cli.py
@@ -11,11 +11,9 @@
 
 from deptry.config import read_configuration_from_pyproject_toml
 from deptry.core import Core
-from deptry.deprecate.ignore_flags import get_value_for_per_rule_ignores_argument
-from deptry.deprecate.skip_flags import get_value_for_ignore_argument
 
 if TYPE_CHECKING:
-    from collections.abc import MutableMapping, Sequence
+    from collections.abc import Mapping, MutableMapping, Sequence
 
 if sys.platform == "win32":
     from colorama import just_fix_windows_console
@@ -132,64 +130,6 @@ def display_deptry_version(ctx: click.Context, _param: click.Parameter, value: b
     is_flag=True,
     help="Disable ANSI characters in terminal output.",
 )
-@click.option("--skip-obsolete", is_flag=True, hidden=True)
-@click.option(
-    "--skip-unused",
-    is_flag=True,
-    help="To be deprecated.",
-    hidden=True,
-)
-@click.option(
-    "--skip-missing",
-    is_flag=True,
-    help="To be deprecated.",
-    hidden=True,
-)
-@click.option(
-    "--skip-transitive",
-    is_flag=True,
-    help="To be deprecated.",
-    hidden=True,
-)
-@click.option(
-    "--skip-misplaced-dev",
-    is_flag=True,
-    help="To be deprecated.",
-    hidden=True,
-)
-@click.option("--ignore-obsolete", "-io", help="To be deprecated.", type=COMMA_SEPARATED_TUPLE, default=(), hidden=True)
-@click.option(
-    "--ignore-unused",
-    "-iu",
-    type=COMMA_SEPARATED_TUPLE,
-    hidden=True,
-    help="To be deprecated.",
-    default=(),
-)
-@click.option(
-    "--ignore-missing",
-    "-im",
-    type=COMMA_SEPARATED_TUPLE,
-    hidden=True,
-    help="To be deprecated.",
-    default=(),
-)
-@click.option(
-    "--ignore-transitive",
-    "-it",
-    type=COMMA_SEPARATED_TUPLE,
-    hidden=True,
-    help="To be deprecated.",
-    default=(),
-)
-@click.option(
-    "--ignore-misplaced-dev",
-    "-id",
-    type=COMMA_SEPARATED_TUPLE,
-    hidden=True,
-    help="To be deprecated.",
-    default=(),
-)
 @click.option(
     "--ignore",
     "-i",
@@ -288,18 +228,8 @@ def deptry(
     root: tuple[Path, ...],
     config: Path,
     no_ansi: bool,
-    ignore_unused: tuple[str, ...],
-    ignore_obsolete: tuple[str, ...],
-    ignore_missing: tuple[str, ...],
-    ignore_transitive: tuple[str, ...],
-    ignore_misplaced_dev: tuple[str, ...],
-    skip_unused: bool,
-    skip_obsolete: bool,
-    skip_missing: bool,
-    skip_transitive: bool,
-    skip_misplaced_dev: bool,
     ignore: tuple[str, ...],
-    per_rule_ignores: MutableMapping[str, tuple[str, ...]],
+    per_rule_ignores: Mapping[str, tuple[str, ...]],
     exclude: tuple[str, ...],
     extend_exclude: tuple[str, ...],
     ignore_notebooks: bool,
@@ -322,22 +252,6 @@ def deptry(
         deptry src worker
 
     """
-    ignore = get_value_for_ignore_argument(
-        ignore,
-        skip_missing=skip_missing,
-        skip_obsolete=skip_obsolete,
-        skip_unused=skip_unused,
-        skip_transitive=skip_transitive,
-        skip_misplaced_dev=skip_misplaced_dev,
-    )
-    per_rule_ignores = get_value_for_per_rule_ignores_argument(
-        per_rule_ignores=per_rule_ignores,
-        ignore_missing=ignore_missing,
-        ignore_obsolete=ignore_obsolete,
-        ignore_unused=ignore_unused,
-        ignore_misplaced_dev=ignore_misplaced_dev,
-        ignore_transitive=ignore_transitive,
-    )
     Core(
         root=root,
         config=config,
diff --git a/python/deptry/deprecate/ignore_flags.py b/python/deptry/deprecate/ignore_flags.py
deleted file mode 100644
index 98a5ed48..00000000
--- a/python/deptry/deprecate/ignore_flags.py
+++ /dev/null
@@ -1,74 +0,0 @@
-from __future__ import annotations
-
-import logging
-from typing import TYPE_CHECKING
-
-from deptry.violations import (
-    DEP001MissingDependencyViolation,
-    DEP002UnusedDependencyViolation,
-    DEP003TransitiveDependencyViolation,
-    DEP004MisplacedDevDependencyViolation,
-)
-
-if TYPE_CHECKING:
-    from collections.abc import MutableMapping
-
-
-def generate_deprecation_warning(flag_name: str, issue_code: str, sequence: tuple[str, ...]) -> str:
-    sequence_as_list_string = "[" + ", ".join(f'"{x}"' for x in sequence) + "]"
-    return (
-        f"Warning: In an upcoming release, support for the `--{flag_name}` command-line option and the"
-        f" `{flag_name.replace('-', '_')}` configuration parameter will be discontinued. Instead, use"
-        f" `--per-rule-ignores {issue_code}={'|'.join(sequence)}` or add a line `{issue_code} ="
-        f" {sequence_as_list_string}` to the `[tool.deptry.per_rule_ignores]` section of the configuration file."
-    )
-
-
-def get_value_for_per_rule_ignores_argument(
-    per_rule_ignores: MutableMapping[str, tuple[str, ...]],
-    ignore_obsolete: tuple[str, ...],
-    ignore_unused: tuple[str, ...],
-    ignore_missing: tuple[str, ...],
-    ignore_transitive: tuple[str, ...],
-    ignore_misplaced_dev: tuple[str, ...],
-) -> MutableMapping[str, tuple[str, ...]]:
-    """
-    This function is designed to help with the transition from deprecated command-line flags to the new `--per-rule-ignores` flag.
-    The deprecated flags that are replaced by this new flag are:
-
-        - `--ignore-obsolete`
-        - `--ignore-unused`
-        - `--ignore-missing`
-        - `--ignore-transitive`
-        - `--ignore-misplaced-dev`
-
-    This function accepts the values for the deprecated flags and updates the `per_rule_ignores` mapping accordingly.
-
-    Raise a warning if one of the to-be-deprecated flags is used.
-    """
-    user_values = {
-        "ignore-missing": ignore_missing,
-        "ignore-unused": ignore_unused,
-        "ignore-obsolete": ignore_obsolete,
-        "ignore-transitive": ignore_transitive,
-        "ignore-misplaced-dev": ignore_misplaced_dev,
-    }
-
-    issue_codes = {
-        "ignore-missing": DEP001MissingDependencyViolation.error_code,
-        "ignore-unused": DEP002UnusedDependencyViolation.error_code,
-        "ignore-obsolete": DEP002UnusedDependencyViolation.error_code,
-        "ignore-transitive": DEP003TransitiveDependencyViolation.error_code,
-        "ignore-misplaced-dev": DEP004MisplacedDevDependencyViolation.error_code,
-    }
-
-    for flag, modules_or_dependencies_to_be_ignored in user_values.items():
-        if modules_or_dependencies_to_be_ignored:
-            code = issue_codes[flag]
-            logging.warning(generate_deprecation_warning(flag, code, modules_or_dependencies_to_be_ignored))
-            if code not in per_rule_ignores:
-                per_rule_ignores[code] = modules_or_dependencies_to_be_ignored
-            else:
-                per_rule_ignores[code] = tuple(set(per_rule_ignores[code]).union(modules_or_dependencies_to_be_ignored))
-
-    return per_rule_ignores
diff --git a/python/deptry/deprecate/skip_flags.py b/python/deptry/deprecate/skip_flags.py
deleted file mode 100644
index 1c3d0bc3..00000000
--- a/python/deptry/deprecate/skip_flags.py
+++ /dev/null
@@ -1,67 +0,0 @@
-from __future__ import annotations
-
-import logging
-
-from deptry.violations import (
-    DEP001MissingDependencyViolation,
-    DEP002UnusedDependencyViolation,
-    DEP003TransitiveDependencyViolation,
-    DEP004MisplacedDevDependencyViolation,
-)
-
-
-def generate_deprecation_warning(flag_name: str, issue_code: str) -> str:
-    return (
-        f"Warning: In an upcoming release, support for the `--{flag_name}` command-line option and the"
-        f" `{flag_name.replace('-', '_')}` configuration parameter will be discontinued. Instead, use `--ignore"
-        f" {issue_code}` or add a line `ignore = ['{issue_code}']` to the `[tool.deptry]` section of the configuration"
-        " file."
-    )
-
-
-def get_value_for_ignore_argument(
-    ignore: tuple[str, ...],
-    skip_obsolete: bool,
-    skip_unused: bool,
-    skip_missing: bool,
-    skip_transitive: bool,
-    skip_misplaced_dev: bool,
-) -> tuple[str, ...]:
-    """
-    This function is designed to help with the transition from deprecated command-line flags to the new `--ignore` flag.
-    The deprecated flags that are replaced by this new flag are:
-
-        - `--skip-obsolete`
-        - `--skip-unused`
-        - `--skip-missing`
-        - `--skip-transitive`
-        - `--skip-misplaced-dev`
-
-    This function accepts the values for the deprecated flags and updates the `ignore` parameter accordingly.
-
-    Raise a warning if one of the to-be-deprecated flags is used.
-    """
-    user_values = {
-        "skip-missing": skip_missing,
-        "skip-unused": skip_unused,
-        "skip-obsolete": skip_obsolete,
-        "skip-transitive": skip_transitive,
-        "skip-misplaced-dev": skip_misplaced_dev,
-    }
-
-    issue_codes = {
-        "skip-missing": DEP001MissingDependencyViolation.error_code,
-        "skip-unused": DEP002UnusedDependencyViolation.error_code,
-        "skip-obsolete": DEP002UnusedDependencyViolation.error_code,
-        "skip-transitive": DEP003TransitiveDependencyViolation.error_code,
-        "skip-misplaced-dev": DEP004MisplacedDevDependencyViolation.error_code,
-    }
-
-    for flag, should_skip in user_values.items():
-        if should_skip:
-            code = issue_codes[flag]
-            logging.warning(generate_deprecation_warning(flag, code))
-            if code not in ignore:
-                ignore += (code,)
-
-    return ignore


Test patch:
diff --git a/tests/data/project_with_future_deprecated_obsolete_argument/pyproject.toml b/tests/data/project_with_future_deprecated_obsolete_argument/pyproject.toml
index b42d1770..2854585f 100644
--- a/tests/data/project_with_future_deprecated_obsolete_argument/pyproject.toml
+++ b/tests/data/project_with_future_deprecated_obsolete_argument/pyproject.toml
@@ -16,5 +16,5 @@ pkginfo = "^1.8.3"
 [tool.poetry.dev-dependencies]
 black = "^22.6.0"
 
-[tool.deptry]
-ignore_obsolete = ["pkginfo"]
+[tool.deptry.per_rule_ignores]
+DEP002 = ["pkginfo"]
diff --git a/tests/data/project_with_multiple_source_directories/pyproject.toml b/tests/data/project_with_multiple_source_directories/pyproject.toml
index 8f3c4584..1aaf7524 100644
--- a/tests/data/project_with_multiple_source_directories/pyproject.toml
+++ b/tests/data/project_with_multiple_source_directories/pyproject.toml
@@ -10,5 +10,5 @@ dependencies = ["toml"]
 requires = ["setuptools>=61.0.0"]
 build-backend = "setuptools.build_meta"
 
-[tool.deptry]
-ignore_obsolete = ["pkginfo"]
+[tool.deptry.per_rule_ignores]
+DEP002 = ["pkginfo"]
diff --git a/tests/functional/cli/test_cli.py b/tests/functional/cli/test_cli.py
index 43be429e..79230f35 100644
--- a/tests/functional/cli/test_cli.py
+++ b/tests/functional/cli/test_cli.py
@@ -148,7 +148,7 @@ def test_cli_ignore_notebooks(poetry_venv_factory: PoetryVenvFactory) -> None:
 @pytest.mark.xdist_group(name=Project.EXAMPLE)
 def test_cli_ignore_flags(poetry_venv_factory: PoetryVenvFactory) -> None:
     with poetry_venv_factory(Project.EXAMPLE) as virtual_env:
-        result = virtual_env.run("deptry . --per-rule-ignores DEP002=isort|pkginfo|requests -im white -id black")
+        result = virtual_env.run("deptry . --per-rule-ignores DEP001=white,DEP002=isort|pkginfo|requests,DEP004=black")
 
         assert result.returncode == 0
 
diff --git a/tests/unit/deprecate/test_ignore_flags.py b/tests/unit/deprecate/test_ignore_flags.py
deleted file mode 100644
index 312706d1..00000000
--- a/tests/unit/deprecate/test_ignore_flags.py
+++ /dev/null
@@ -1,181 +0,0 @@
-from __future__ import annotations
-
-from typing import TYPE_CHECKING
-
-import pytest
-
-from deptry.deprecate.ignore_flags import generate_deprecation_warning, get_value_for_per_rule_ignores_argument
-
-if TYPE_CHECKING:
-    from collections.abc import MutableMapping
-
-
-def test_generate_deprecation_warning() -> None:
-    result = generate_deprecation_warning(flag_name="ignore-missing", issue_code="DEP002", sequence=("hi", "bye"))
-    assert (
-        result == "Warning: In an upcoming release, support for the `--ignore-missing` command-line option and the"
-        " `ignore_missing` configuration parameter will be discontinued. Instead, use `--per-rule-ignores"
-        ' DEP002=hi|bye` or add a line `DEP002 = ["hi", "bye"]` to the `[tool.deptry.per_rule_ignores]` section of the'
-        " configuration file."
-    )
-
-
-@pytest.mark.parametrize(
-    ("ignore_params", "expected_result", "flag_name", "issue_code"),
-    [
-        (
-            {
-                "ignore_obsolete": (),
-                "ignore_unused": (),
-                "ignore_missing": ("hello", "goodbye"),
-                "ignore_transitive": (),
-                "ignore_misplaced_dev": (),
-            },
-            {"DEP001": ("hello", "goodbye")},
-            "ignore-missing",
-            "DEP001",
-        ),
-        (
-            {
-                "ignore_obsolete": ("hello", "goodbye"),
-                "ignore_unused": (),
-                "ignore_missing": (),
-                "ignore_transitive": (),
-                "ignore_misplaced_dev": (),
-            },
-            {"DEP002": ("hello", "goodbye")},
-            "ignore-obsolete",
-            "DEP002",
-        ),
-        (
-            {
-                "ignore_obsolete": (),
-                "ignore_unused": ("hello", "goodbye"),
-                "ignore_missing": (),
-                "ignore_transitive": (),
-                "ignore_misplaced_dev": (),
-            },
-            {"DEP002": ("hello", "goodbye")},
-            "ignore-unused",
-            "DEP002",
-        ),
-        (
-            {
-                "ignore_obsolete": (),
-                "ignore_unused": (),
-                "ignore_missing": (),
-                "ignore_transitive": ("hello", "goodbye"),
-                "ignore_misplaced_dev": (),
-            },
-            {"DEP003": ("hello", "goodbye")},
-            "ignore-transitive",
-            "DEP003",
-        ),
-        (
-            {
-                "ignore_obsolete": (),
-                "ignore_unused": (),
-                "ignore_missing": (),
-                "ignore_transitive": (),
-                "ignore_misplaced_dev": ("hello", "goodbye"),
-            },
-            {"DEP004": ("hello", "goodbye")},
-            "ignore-misplaced-dev",
-            "DEP004",
-        ),
-    ],
-)
-def test_ignore_param(
-    caplog: pytest.LogCaptureFixture,
-    ignore_params: MutableMapping[str, tuple[str, ...]],
-    expected_result: MutableMapping[str, tuple[str, ...]],
-    flag_name: str,
-    issue_code: str,
-) -> None:
-    result = get_value_for_per_rule_ignores_argument(per_rule_ignores={}, **ignore_params)
-    assert result == expected_result
-    assert (
-        generate_deprecation_warning(flag_name=flag_name, issue_code=issue_code, sequence=("hello", "goodbye"))
-        in caplog.text
-    )
-
-
-@pytest.mark.parametrize(
-    ("ignore_params", "expected_result", "flag_name", "issue_code"),
-    [
-        (
-            {
-                "ignore_obsolete": (),
-                "ignore_unused": (),
-                "ignore_missing": ("hello", "goodbye"),
-                "ignore_transitive": (),
-                "ignore_misplaced_dev": (),
-            },
-            {"DEP001": ("goodbye", "hello", "package")},
-            "ignore-missing",
-            "DEP001",
-        ),
-        (
-            {
-                "ignore_obsolete": ("hello", "goodbye"),
-                "ignore_unused": (),
-                "ignore_missing": (),
-                "ignore_transitive": (),
-                "ignore_misplaced_dev": (),
-            },
-            {"DEP002": ("goodbye", "hello", "package")},
-            "ignore-obsolete",
-            "DEP002",
-        ),
-        (
-            {
-                "ignore_obsolete": (),
-                "ignore_unused": ("hello", "goodbye"),
-                "ignore_missing": (),
-                "ignore_transitive": (),
-                "ignore_misplaced_dev": (),
-            },
-            {"DEP002": ("goodbye", "hello", "package")},
-            "ignore-unused",
-            "DEP002",
-        ),
-        (
-            {
-                "ignore_obsolete": (),
-                "ignore_unused": (),
-                "ignore_missing": (),
-                "ignore_transitive": ("hello", "goodbye"),
-                "ignore_misplaced_dev": (),
-            },
-            {"DEP003": ("goodbye", "hello", "package")},
-            "ignore-transitive",
-            "DEP003",
-        ),
-        (
-            {
-                "ignore_obsolete": (),
-                "ignore_unused": (),
-                "ignore_missing": (),
-                "ignore_transitive": (),
-                "ignore_misplaced_dev": ("hello", "goodbye"),
-            },
-            {"DEP004": ("goodbye", "hello", "package")},
-            "ignore-misplaced-dev",
-            "DEP004",
-        ),
-    ],
-)
-def test_ignore_param_append(
-    caplog: pytest.LogCaptureFixture,
-    ignore_params: MutableMapping[str, tuple[str, ...]],
-    expected_result: MutableMapping[str, tuple[str, ...]],
-    flag_name: str,
-    issue_code: str,
-) -> None:
-    result = get_value_for_per_rule_ignores_argument(per_rule_ignores={issue_code: ("package",)}, **ignore_params)
-    # We do not care about the order of the sequences that are in the values of the dict.
-    assert {k: sorted(v) for k, v in result.items()} == {k: sorted(v) for k, v in expected_result.items()}
-    assert (
-        generate_deprecation_warning(flag_name=flag_name, issue_code=issue_code, sequence=("hello", "goodbye"))
-        in caplog.text
-    )
diff --git a/tests/unit/deprecate/test_skip_flags.py b/tests/unit/deprecate/test_skip_flags.py
deleted file mode 100644
index c74ee33f..00000000
--- a/tests/unit/deprecate/test_skip_flags.py
+++ /dev/null
@@ -1,58 +0,0 @@
-from __future__ import annotations
-
-from typing import TYPE_CHECKING
-
-if TYPE_CHECKING:
-    import pytest
-
-from deptry.deprecate.skip_flags import generate_deprecation_warning, get_value_for_ignore_argument
-
-
-def test_generate_deprecation_warning() -> None:
-    result = generate_deprecation_warning(flag_name="skip-unused", issue_code="DEP002")
-    assert (
-        result
-        == "Warning: In an upcoming release, support for the `--skip-unused` command-line option and the `skip_unused`"
-        " configuration parameter will be discontinued. Instead, use `--ignore DEP002` or add a line `ignore ="
-        " ['DEP002']` to the `[tool.deptry]` section of the configuration file."
-    )
-
-
-def test_skip_obsolete(caplog: pytest.LogCaptureFixture) -> None:
-    result = get_value_for_ignore_argument(
-        ignore=(),
-        skip_obsolete=True,
-        skip_unused=False,
-        skip_missing=False,
-        skip_transitive=False,
-        skip_misplaced_dev=False,
-    )
-    assert result == ("DEP002",)
-    assert generate_deprecation_warning(flag_name="skip-obsolete", issue_code="DEP002") in caplog.text
-
-
-def test_skip_unused(caplog: pytest.LogCaptureFixture) -> None:
-    result = get_value_for_ignore_argument(
-        ignore=(),
-        skip_obsolete=True,
-        skip_unused=True,
-        skip_missing=False,
-        skip_transitive=False,
-        skip_misplaced_dev=False,
-    )
-    assert result == ("DEP002",)
-    assert generate_deprecation_warning(flag_name="skip-unused", issue_code="DEP002") in caplog.text
-
-
-def test_skip_transitive_and_missing(caplog: pytest.LogCaptureFixture) -> None:
-    result = get_value_for_ignore_argument(
-        ignore=(),
-        skip_obsolete=False,
-        skip_unused=False,
-        skip_missing=True,
-        skip_transitive=True,
-        skip_misplaced_dev=False,
-    )
-    assert result == ("DEP001", "DEP003")
-    assert generate_deprecation_warning(flag_name="skip-missing", issue_code="DEP001") in caplog.text
-    assert generate_deprecation_warning(flag_name="skip-transitive", issue_code="DEP003") in caplog.text