mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 08:39:17 +01:00
Fixed issue with legacy plugin copy not copying properties. Also
added test for it
This commit is contained in:
parent
ecea47320c
commit
670c300625
3 changed files with 37 additions and 10 deletions
|
|
@ -22,7 +22,7 @@ import re
|
||||||
import sys
|
import sys
|
||||||
import warnings
|
import warnings
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from functools import wraps
|
from functools import cached_property, wraps
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from types import GenericAlias
|
from types import GenericAlias
|
||||||
|
|
@ -192,15 +192,20 @@ class BeetsPlugin(metaclass=abc.ABCMeta):
|
||||||
stacklevel=3,
|
stacklevel=3,
|
||||||
)
|
)
|
||||||
|
|
||||||
for name, method in inspect.getmembers(
|
abstracts = MetadataSourcePlugin.__abstractmethods__
|
||||||
MetadataSourcePlugin,
|
|
||||||
predicate=lambda f: (
|
for name, method in inspect.getmembers(MetadataSourcePlugin):
|
||||||
inspect.isfunction(f)
|
# Skip if already defined in the subclass
|
||||||
and f.__name__ not in MetadataSourcePlugin.__abstractmethods__
|
if hasattr(cls, name) or name in abstracts:
|
||||||
and not hasattr(cls, f.__name__)
|
continue
|
||||||
),
|
|
||||||
):
|
# Copy functions, methods, and properties
|
||||||
setattr(cls, name, method)
|
if (
|
||||||
|
inspect.isfunction(method)
|
||||||
|
or inspect.ismethod(method)
|
||||||
|
or isinstance(method, cached_property)
|
||||||
|
):
|
||||||
|
setattr(cls, name, method)
|
||||||
|
|
||||||
def __init__(self, name: str | None = None):
|
def __init__(self, name: str | None = None):
|
||||||
"""Perform one-time plugin setup."""
|
"""Perform one-time plugin setup."""
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,8 @@ For packagers:
|
||||||
|
|
||||||
- Fixed dynamic versioning install not disabled for source distribution builds.
|
- Fixed dynamic versioning install not disabled for source distribution builds.
|
||||||
:bug:`6089`
|
:bug:`6089`
|
||||||
|
- Fixed issue with legacy metadata plugins not copying properties from the base
|
||||||
|
class.
|
||||||
|
|
||||||
Other changes:
|
Other changes:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -523,3 +523,23 @@ class TestImportPlugin(PluginMixin):
|
||||||
assert "PluginImportError" not in caplog.text, (
|
assert "PluginImportError" not in caplog.text, (
|
||||||
f"Plugin '{plugin_name}' has issues during import."
|
f"Plugin '{plugin_name}' has issues during import."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class TestDeprecationCopy:
|
||||||
|
# TODO: remove this test in Beets 3.0.0
|
||||||
|
def test_legacy_metadata_plugin_deprecation(self):
|
||||||
|
"""Test that a MetadataSourcePlugin with 'legacy' data_source
|
||||||
|
raises a deprecation warning and all function and properties are
|
||||||
|
copied from the base class.
|
||||||
|
"""
|
||||||
|
with pytest.warns(DeprecationWarning, match="LegacyMetadataPlugin"):
|
||||||
|
|
||||||
|
class LegacyMetadataPlugin(plugins.BeetsPlugin):
|
||||||
|
data_source = "legacy"
|
||||||
|
|
||||||
|
# Assert all methods are present
|
||||||
|
assert hasattr(LegacyMetadataPlugin, "albums_for_ids")
|
||||||
|
assert hasattr(LegacyMetadataPlugin, "tracks_for_ids")
|
||||||
|
assert hasattr(LegacyMetadataPlugin, "data_source_mismatch_penalty")
|
||||||
|
assert hasattr(LegacyMetadataPlugin, "_extract_id")
|
||||||
|
assert hasattr(LegacyMetadataPlugin, "get_artist")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue