mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 16:42:42 +01:00
Add deprecation warning for <plugin>.source_weight
This commit is contained in:
parent
5757579e27
commit
f8887d48b6
4 changed files with 43 additions and 2 deletions
|
|
@ -13,6 +13,7 @@ from functools import cache, cached_property
|
||||||
from typing import TYPE_CHECKING, Generic, Literal, Sequence, TypedDict, TypeVar
|
from typing import TYPE_CHECKING, Generic, Literal, Sequence, TypedDict, TypeVar
|
||||||
|
|
||||||
import unidecode
|
import unidecode
|
||||||
|
from confuse import NotFoundError
|
||||||
from typing_extensions import NotRequired
|
from typing_extensions import NotRequired
|
||||||
|
|
||||||
from beets.util import cached_classproperty
|
from beets.util import cached_classproperty
|
||||||
|
|
@ -106,7 +107,10 @@ class MetadataSourcePlugin(BeetsPlugin, metaclass=abc.ABCMeta):
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def data_source_mismatch_penalty(self) -> float:
|
def data_source_mismatch_penalty(self) -> float:
|
||||||
return self.config["data_source_mismatch_penalty"].as_number()
|
try:
|
||||||
|
return self.config["source_weight"].as_number()
|
||||||
|
except NotFoundError:
|
||||||
|
return self.config["data_source_mismatch_penalty"].as_number()
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs) -> None:
|
def __init__(self, *args, **kwargs) -> None:
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
|
||||||
|
|
@ -225,6 +225,37 @@ class BeetsPlugin(metaclass=abc.ABCMeta):
|
||||||
if not any(isinstance(f, PluginLogFilter) for f in self._log.filters):
|
if not any(isinstance(f, PluginLogFilter) for f in self._log.filters):
|
||||||
self._log.addFilter(PluginLogFilter(self))
|
self._log.addFilter(PluginLogFilter(self))
|
||||||
|
|
||||||
|
# In order to verify the config we need to make sure the plugin is fully
|
||||||
|
# configured (plugins usually add the default configuration *after*
|
||||||
|
# calling super().__init__()).
|
||||||
|
self.register_listener("pluginload", self.verify_config)
|
||||||
|
|
||||||
|
def verify_config(self, *_, **__) -> None:
|
||||||
|
"""Verify plugin configuration.
|
||||||
|
|
||||||
|
If deprecated 'source_weight' option is explicitly set by the user, they
|
||||||
|
will see a warning in the logs. Otherwise, this must be configured by
|
||||||
|
a third party plugin, thus we raise a deprecation warning which won't be
|
||||||
|
shown to user but will be visible to plugin developers.
|
||||||
|
"""
|
||||||
|
# TODO: Remove in v3.0.0
|
||||||
|
if (
|
||||||
|
not hasattr(self, "data_source")
|
||||||
|
or "source_weight" not in self.config
|
||||||
|
):
|
||||||
|
return
|
||||||
|
|
||||||
|
message = (
|
||||||
|
"'source_weight' configuration option is deprecated and will be"
|
||||||
|
" removed in v3.0.0. Use 'data_source_mismatch_penalty' instead"
|
||||||
|
)
|
||||||
|
for source in self.config.root().sources:
|
||||||
|
if "source_weight" in (source.get(self.name) or {}):
|
||||||
|
if source.filename: # user config
|
||||||
|
self._log.warning(message)
|
||||||
|
else: # 3rd-party plugin config
|
||||||
|
warnings.warn(message, DeprecationWarning, stacklevel=0)
|
||||||
|
|
||||||
def commands(self) -> Sequence[Subcommand]:
|
def commands(self) -> Sequence[Subcommand]:
|
||||||
"""Should return a list of beets.ui.Subcommand objects for
|
"""Should return a list of beets.ui.Subcommand objects for
|
||||||
commands that should be added to beets' CLI.
|
commands that should be added to beets' CLI.
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,8 @@ Using Metadata Source Plugins
|
||||||
We provide several :ref:`autotagger_extensions` that fetch metadata from online
|
We provide several :ref:`autotagger_extensions` that fetch metadata from online
|
||||||
databases. They share the following configuration options:
|
databases. They share the following configuration options:
|
||||||
|
|
||||||
|
.. _data_source_mismatch_penalty:
|
||||||
|
|
||||||
- **data_source_mismatch_penalty**: Penalty applied to matches during import.
|
- **data_source_mismatch_penalty**: Penalty applied to matches during import.
|
||||||
Any decimal number between 0 and 1. Default: ``0.5``.
|
Any decimal number between 0 and 1. Default: ``0.5``.
|
||||||
|
|
||||||
|
|
@ -66,6 +68,10 @@ databases. They share the following configuration options:
|
||||||
By default, all sources are equally preferred with each having
|
By default, all sources are equally preferred with each having
|
||||||
``data_source_mismatch_penalty`` set to ``0.5``.
|
``data_source_mismatch_penalty`` set to ``0.5``.
|
||||||
|
|
||||||
|
- **source_weight**
|
||||||
|
|
||||||
|
.. deprecated:: 2.5 Use `data_source_mismatch_penalty`_ instead.
|
||||||
|
|
||||||
- **search_limit**: Maximum number of search results to consider. Default:
|
- **search_limit**: Maximum number of search results to consider. Default:
|
||||||
``5``.
|
``5``.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ limited_ to one request per second.
|
||||||
enabled
|
enabled
|
||||||
+++++++
|
+++++++
|
||||||
|
|
||||||
.. deprecated:: 2.3 Add ``musicbrainz`` to the ``plugins`` list instead.
|
.. deprecated:: 2.4 Add ``musicbrainz`` to the ``plugins`` list instead.
|
||||||
|
|
||||||
This option allows you to disable using MusicBrainz as a metadata source. This
|
This option allows you to disable using MusicBrainz as a metadata source. This
|
||||||
applies if you use plugins that fetch data from alternative sources and should
|
applies if you use plugins that fetch data from alternative sources and should
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue