diff --git a/src/pdm/cli/actions.py b/src/pdm/cli/actions.py index d1d633ed06..fe708b2674 100644 --- a/src/pdm/cli/actions.py +++ b/src/pdm/cli/actions.py @@ -8,7 +8,7 @@ import sys import textwrap import warnings -from typing import Any, Collection, Iterable, cast +from typing import Collection, Iterable, cast from resolvelib.reporters import BaseReporter from resolvelib.resolvers import ResolutionImpossible, ResolutionTooDeep, Resolver @@ -34,7 +34,6 @@ from pdm.project.lockfile import FLAG_CROSS_PLATFORM, FLAG_DIRECT_MINIMAL_VERSIONS, FLAG_INHERIT_METADATA from pdm.resolver import resolve from pdm.termui import logger -from pdm.utils import deprecation_warning def do_lock( @@ -382,59 +381,3 @@ def check_update(project: Project) -> None: # pragma: no cover " to disable the check.", ] project.core.ui.info("".join(message)) - - -# Moved functions -def do_add(*args: Any, **kwargs: Any) -> None: # pragma: no cover - from pdm.cli.commands.add import Command as AddCommand - - deprecation_warning( - "`pdm.actions.do_add` has been moved to `pdm.cli.commands.add:Command.do_add` method, " - "This function will be removed in the future.", - stacklevel=2, - ) - AddCommand().do_add(*args, **kwargs) - - -def do_update(*args: Any, **kwargs: Any) -> None: # pragma: no cover - from pdm.cli.commands.update import Command as UpdateCommand - - deprecation_warning( - "`pdm.actions.do_update` has been moved to `pdm.cli.commands.update:Command.do_update` method, " - "This function will be removed in the future.", - stacklevel=2, - ) - UpdateCommand().do_update(*args, **kwargs) - - -def do_use(*args: Any, **kwargs: Any) -> None: # pragma: no cover - from pdm.cli.commands.use import Command as UseCommand - - deprecation_warning( - "`pdm.actions.do_use` has been moved to `pdm.cli.commands.use:Command.do_use` method, " - "This function will be removed in the future.", - stacklevel=2, - ) - UseCommand().do_use(*args, **kwargs) - - -def do_remove(*args: Any, **kwargs: Any) -> None: # pragma: no cover - from pdm.cli.commands.remove import Command as RemoveCommand - - deprecation_warning( - "`pdm.actions.do_remove` has been moved to `pdm.cli.commands.remove:Command.do_remove` method, " - "This function will be removed in the future.", - stacklevel=2, - ) - RemoveCommand().do_remove(*args, **kwargs) - - -def do_import(*args: Any, **kwargs: Any) -> None: # pragma: no cover - from pdm.cli.commands.import_cmd import Command as ImportCommand - - deprecation_warning( - "`pdm.actions.do_import` has been moved to `pdm.cli.commands.import_:Command.do_import` method, " - "This function will be removed in the future.", - stacklevel=2, - ) - ImportCommand().do_import(*args, **kwargs) diff --git a/src/pdm/exceptions.py b/src/pdm/exceptions.py index 24ebd76efb..0eb87f6a0f 100644 --- a/src/pdm/exceptions.py +++ b/src/pdm/exceptions.py @@ -49,6 +49,10 @@ class PackageWarning(PDMWarning): pass +class PDMDeprecationWarning(PDMWarning): + pass + + class ExtrasWarning(PDMWarning): def __init__(self, project_name: str, extras: list[str]) -> None: super().__init__(f"Extras not found for {project_name}: [{','.join(extras)}]") diff --git a/src/pdm/models/specifiers.py b/src/pdm/models/specifiers.py index 12aae2f66b..26803fa681 100644 --- a/src/pdm/models/specifiers.py +++ b/src/pdm/models/specifiers.py @@ -2,6 +2,7 @@ import json import re +import warnings from functools import lru_cache from operator import attrgetter from typing import Any, Iterable, Match, cast @@ -36,21 +37,22 @@ def fix_legacy_specifier(specifier: str) -> str: """Since packaging 22.0, legacy specifiers like '>=4.*' are no longer supported. We try to normalize them to the new format. """ - from pdm.utils import deprecation_warning def fix_wildcard(match: Match[str]) -> str: operator, _, version = match.groups() if operator in ("==", "!="): return match.group(0) if ".*" in version: - deprecation_warning(".* suffix can only be used with `==` or `!=` operators", stacklevel=4) + warnings.warn(".* suffix can only be used with `==` or `!=` operators", FutureWarning, stacklevel=4) version = version.replace(".*", ".0") if operator in ("<", "<="): # <4.* and <=4.* are equivalent to <4.0 operator = "<" elif operator in (">", ">="): # >4.* and >=4.* are equivalent to >=4.0 operator = ">=" elif "+" in version: # Drop the local version - deprecation_warning("Local version label can only be used with `==` or `!=` operators", stacklevel=4) + warnings.warn( + "Local version label can only be used with `==` or `!=` operators", FutureWarning, stacklevel=4 + ) version = version.split("+")[0] return f"{operator}{version}" diff --git a/src/pdm/project/core.py b/src/pdm/project/core.py index 7e2e52224a..bae163c732 100644 --- a/src/pdm/project/core.py +++ b/src/pdm/project/core.py @@ -670,17 +670,6 @@ def _get_python_finder(self) -> Finder: finder.add_provider(VenvProvider(self), venv_pos) return finder - # compatibility, shouldn't be used directly - @property - def meta(self) -> dict[str, Any]: - deprecation_warning("project.meta is deprecated, use project.pyproject.metadata instead", stacklevel=2) - return self.pyproject.metadata - - @property - def tool_settings(self) -> dict[str, Any]: - deprecation_warning("project.tool_settings is deprecated, use project.pyproject.settings instead", stacklevel=2) - return self.pyproject.settings - @property def is_library(self) -> bool: return bool(self.name) and self.pyproject.settings.get("package-type", "library") == "library" diff --git a/src/pdm/project/project_file.py b/src/pdm/project/project_file.py index c12c83740c..5fca5310a2 100644 --- a/src/pdm/project/project_file.py +++ b/src/pdm/project/project_file.py @@ -8,7 +8,6 @@ from pdm import termui from pdm.project.toml_file import TOMLBase -from pdm.utils import deprecation_warning def _remove_empty_tables(doc: dict) -> None: @@ -66,13 +65,6 @@ def resolution_overrides(self) -> Mapping[str, str]: in the pyproject.toml file. """ settings = self.settings - if "overrides" in settings: - deprecation_warning( - "The 'tool.pdm.overrides' table has been renamed to " - "'tool.pdm.resolution.overrides', please update the " - "setting accordingly." - ) - return settings["overrides"] return settings.get("resolution", {}).get("overrides", {}) def content_hash(self, algo: str = "sha256") -> str: diff --git a/src/pdm/utils.py b/src/pdm/utils.py index db9afdcd05..6df2cf07cc 100644 --- a/src/pdm/utils.py +++ b/src/pdm/utils.py @@ -23,7 +23,7 @@ from packaging.version import Version, _cmpkey from pdm.compat import importlib_metadata -from pdm.exceptions import PdmException +from pdm.exceptions import PDMDeprecationWarning, PdmException if TYPE_CHECKING: from re import Match @@ -422,8 +422,8 @@ def deprecation_warning(message: str, stacklevel: int = 1, raise_since: str | No if raise_since is not None: if Version(__version__) >= Version(raise_since): - raise FutureWarning(message) - warnings.warn(message, FutureWarning, stacklevel=stacklevel + 1) + raise PDMDeprecationWarning(message) + warnings.warn(message, PDMDeprecationWarning, stacklevel=stacklevel + 1) def is_pip_compatible_with_python(python_version: Version | str) -> bool: diff --git a/tests/test_utils.py b/tests/test_utils.py index 5b57decd4e..b4e0b5399f 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -11,7 +11,7 @@ from pdm import utils from pdm.cli import utils as cli_utils from pdm.cli.filters import GroupSelection -from pdm.exceptions import PdmUsageError +from pdm.exceptions import PdmUsageError, PDMWarning @pytest.mark.parametrize( @@ -517,12 +517,12 @@ def test_prod_should_not_be_with_dev(project): def test_deprecation_warning(): - with pytest.warns(FutureWarning) as record: + with pytest.warns(PDMWarning) as record: utils.deprecation_warning("Test warning", raise_since="99.99") assert len(record) == 1 assert str(record[0].message) == "Test warning" - with pytest.raises(FutureWarning): + with pytest.raises(PDMWarning): utils.deprecation_warning("Test warning", raise_since="0.0")