Skip to content

Commit 648a9be

Browse files
committed
Added deprecation warning for legacy type metadata plugins.
1 parent 5cd6a39 commit 648a9be

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

beets/metadata_plugins.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
from __future__ import annotations
99

1010
import abc
11+
import inspect
1112
import re
1213
import sys
14+
import warnings
1315
from typing import TYPE_CHECKING, Generic, Literal, Sequence, TypedDict, TypeVar
1416

1517
from beets.util import cached_classproperty
@@ -36,11 +38,24 @@ def find_metadata_source_plugins() -> list[MetadataSourcePlugin]:
3638
3739
Resolved from all currently loaded beets plugins.
3840
"""
39-
return [
40-
plugin
41-
for plugin in find_plugins()
42-
if isinstance(plugin, MetadataSourcePlugin)
43-
]
41+
42+
all_plugins = find_plugins()
43+
metadata_plugins = []
44+
for plugin in all_plugins:
45+
if isinstance(plugin, MetadataSourcePlugin):
46+
metadata_plugins.append(plugin)
47+
elif hasattr(plugin, "data_source"):
48+
# TODO: Remove this in the future major release, v3.0.0
49+
warnings.warn(
50+
f"{plugin.__class__.__name__} is used as a legacy metadata source. "
51+
"It should extend MetadataSourcePlugin instead of BeetsPlugin. "
52+
"Support for this will be removed in the v3.0.0 release!",
53+
DeprecationWarning,
54+
stacklevel=2,
55+
)
56+
metadata_plugins.append(plugin)
57+
58+
return metadata_plugins
4459

4560

4661
@notify_info_yielded("albuminfo_received")
@@ -369,3 +384,13 @@ def item_candidates(
369384
None,
370385
self.tracks_for_ids([result["id"] for result in results if result]),
371386
)
387+
388+
389+
# Dynamically copy methods to BeetsPlugin for legacy support
390+
# TODO: Remove this in the future major release, v3.0.0
391+
392+
for name, method in inspect.getmembers(
393+
MetadataSourcePlugin, predicate=inspect.isfunction
394+
):
395+
if not hasattr(BeetsPlugin, name):
396+
setattr(BeetsPlugin, name, method)

beets/plugins.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,9 @@ def load_plugins(names: Sequence[str] = ()) -> None:
299299
for obj in getattr(namespace, name).__dict__.values():
300300
if (
301301
inspect.isclass(obj)
302-
and not isinstance(obj, GenericAlias)
302+
and not isinstance(
303+
obj, GenericAlias
304+
) # seems to be needed for python <= 3.9 only
303305
and issubclass(obj, BeetsPlugin)
304306
and obj != BeetsPlugin
305307
and not inspect.isabstract(obj)

0 commit comments

Comments
 (0)