mirror of
https://github.com/beetbox/beets.git
synced 2025-12-07 17:16:07 +01:00
Define MetadataSourcePlugin methods on the subclass only
This commit is contained in:
parent
33feb0348d
commit
1736a5e735
2 changed files with 15 additions and 11 deletions
|
|
@ -8,7 +8,6 @@ implemented as plugins.
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import abc
|
import abc
|
||||||
import inspect
|
|
||||||
import re
|
import re
|
||||||
import warnings
|
import warnings
|
||||||
from typing import TYPE_CHECKING, Generic, Literal, Sequence, TypedDict, TypeVar
|
from typing import TYPE_CHECKING, Generic, Literal, Sequence, TypedDict, TypeVar
|
||||||
|
|
@ -421,13 +420,3 @@ class SearchApiMetadataSourcePlugin(
|
||||||
query = unidecode.unidecode(query)
|
query = unidecode.unidecode(query)
|
||||||
|
|
||||||
return query
|
return query
|
||||||
|
|
||||||
|
|
||||||
# Dynamically copy methods to BeetsPlugin for legacy support
|
|
||||||
# TODO: Remove this in the future major release, v3.0.0
|
|
||||||
|
|
||||||
for name, method in inspect.getmembers(
|
|
||||||
MetadataSourcePlugin, predicate=inspect.isfunction
|
|
||||||
):
|
|
||||||
if not hasattr(BeetsPlugin, name):
|
|
||||||
setattr(BeetsPlugin, name, method)
|
|
||||||
|
|
|
||||||
|
|
@ -158,6 +158,21 @@ class BeetsPlugin(metaclass=abc.ABCMeta):
|
||||||
early_import_stages: list[ImportStageFunc]
|
early_import_stages: list[ImportStageFunc]
|
||||||
import_stages: list[ImportStageFunc]
|
import_stages: list[ImportStageFunc]
|
||||||
|
|
||||||
|
def __init_subclass__(cls) -> None:
|
||||||
|
# Dynamically copy methods to BeetsPlugin for legacy support
|
||||||
|
# TODO: Remove this in the future major release, v3.0.0
|
||||||
|
if inspect.isabstract(cls):
|
||||||
|
return
|
||||||
|
|
||||||
|
from beets.metadata_plugins import MetadataSourcePlugin
|
||||||
|
|
||||||
|
abstractmethods = MetadataSourcePlugin.__abstractmethods__
|
||||||
|
for name, method in inspect.getmembers(
|
||||||
|
MetadataSourcePlugin, predicate=inspect.isfunction
|
||||||
|
):
|
||||||
|
if name not in abstractmethods and not hasattr(cls, name):
|
||||||
|
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."""
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue