Skip to content

Commit

Permalink
feat: remove some deprecated members
Browse files Browse the repository at this point in the history
Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming committed Jan 10, 2024
1 parent 13860e5 commit 6cbd113
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 86 deletions.
59 changes: 1 addition & 58 deletions src/pdm/cli/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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)
4 changes: 4 additions & 0 deletions src/pdm/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}]")
Expand Down
8 changes: 5 additions & 3 deletions src/pdm/models/specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"

Expand Down
11 changes: 0 additions & 11 deletions src/pdm/project/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
8 changes: 0 additions & 8 deletions src/pdm/project/project_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions src/pdm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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")


Expand Down

0 comments on commit 6cbd113

Please sign in to comment.