Skip to content

Commit 5a3ecf6

Browse files
committed
Add deprecate_for_user function
1 parent 3928863 commit 5a3ecf6

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

beets/plugins.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import beets
3333
from beets import logging
3434
from beets.util import unique_list
35-
from beets.util.deprecation import deprecate_for_maintainers
35+
from beets.util.deprecation import deprecate_for_maintainers, deprecate_for_user
3636

3737
if TYPE_CHECKING:
3838
from collections.abc import Callable, Iterable, Sequence
@@ -257,14 +257,14 @@ def _verify_config(self, *_, **__) -> None:
257257
):
258258
return
259259

260-
message = (
261-
"'source_weight' configuration option is deprecated and will be"
262-
" removed in v3.0.0. Use 'data_source_mismatch_penalty' instead"
263-
)
264260
for source in self.config.root().sources:
265261
if "source_weight" in (source.get(self.name) or {}):
266262
if source.filename: # user config
267-
self._log.warning(message)
263+
deprecate_for_user(
264+
self._log,
265+
f"'{self.name}.source_weight' configuration option",
266+
f"'{self.name}.data_source_mismatch_penalty'",
267+
)
268268
else: # 3rd-party plugin config
269269
deprecate_for_maintainers(
270270
"'source_weight' configuration option",

beets/util/deprecation.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
import warnings
44
from importlib import import_module
5-
from typing import Any
5+
from typing import TYPE_CHECKING, Any
66

77
from packaging.version import Version
88

99
import beets
1010

11+
if TYPE_CHECKING:
12+
from logging import Logger
13+
1114

1215
def _format_message(old: str, new: str | None = None) -> str:
1316
next_major = f"{Version(beets.__version__).major + 1}.0.0"
@@ -18,6 +21,10 @@ def _format_message(old: str, new: str | None = None) -> str:
1821
return msg
1922

2023

24+
def deprecate_for_user(logger: Logger, old: str, new: str) -> None:
25+
logger.warning(_format_message(old, new))
26+
27+
2128
def deprecate_for_maintainers(
2229
old: str, new: str | None = None, stacklevel: int = 1
2330
) -> None:

beetsplug/musicbrainz.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import beets.autotag.hooks
3232
from beets import config, plugins, util
3333
from beets.metadata_plugins import MetadataSourcePlugin
34+
from beets.util.deprecation import deprecate_for_user
3435
from beets.util.id_extractors import extract_release_id
3536

3637
if TYPE_CHECKING:
@@ -403,9 +404,10 @@ def __init__(self):
403404
self.config["search_limit"] = self.config["match"][
404405
"searchlimit"
405406
].get()
406-
self._log.warning(
407-
"'musicbrainz.searchlimit' option is deprecated and will be "
408-
"removed in 3.0.0. Use 'musicbrainz.search_limit' instead."
407+
deprecate_for_user(
408+
self._log,
409+
"'musicbrainz.searchlimit' configuration option",
410+
"'musicbrainz.search_limit'",
409411
)
410412
hostname = self.config["host"].as_str()
411413
https = self.config["https"].get(bool)

0 commit comments

Comments
 (0)