Bring back and deprecate queries and types imports from beets.library

This commit is contained in:
Šarūnas Nejus 2025-07-24 02:57:04 +01:00
parent 268075063f
commit 3dd18dc3be
No known key found for this signature in database
GPG key ID: DD28F6704DBE3435
2 changed files with 36 additions and 4 deletions

View file

@ -1,8 +1,33 @@
import warnings
from importlib import import_module
from .exceptions import FileOperationError, ReadError, WriteError
from .library import Library
from .models import Album, Item, LibModel
from .queries import parse_query_parts, parse_query_string
NEW_MODULE_BY_NAME = dict.fromkeys(
("DateType", "DurationType", "MusicalKey", "PathType"), "beets.dbcore.types"
) | dict.fromkeys(
("BLOB_TYPE", "SingletonQuery", "PathQuery"), "beets.dbcore.query"
)
def __getattr__(name: str):
if name in NEW_MODULE_BY_NAME:
new_module = NEW_MODULE_BY_NAME[name]
warnings.warn(
(
f"'beets.library.{name}' import is deprecated and will be removed"
f"in v3.0.0; import '{new_module}.{name}' instead."
),
DeprecationWarning,
stacklevel=2,
)
return getattr(import_module(new_module), name)
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
__all__ = [
"Library",
"LibModel",

View file

@ -54,7 +54,7 @@ Bug fixes:
e.g. non latin characters as 盗作. If you want to keep the legacy behavior
set the config option ``spotify.search_query_ascii: yes``.
:bug:`5699`
For packagers:
* Optional ``extra_tags`` parameter has been removed from
@ -67,7 +67,7 @@ For plugin developers:
source registration in the process of introducing typings to the code.
Custom art sources might need to be adapted.
* We split the responsibilities of plugins into two base classes
#. :class:`beets.plugins.BeetsPlugin`
#. :class:`beets.plugins.BeetsPlugin`
is the base class for all plugins, any plugin needs to inherit from this class.
#. :class:`beets.metadata_plugin.MetadataSourcePlugin`
allows plugins to act like metadata sources. E.g. used by the MusicBrainz plugin. All plugins
@ -76,7 +76,14 @@ For plugin developers:
``album_for_id``, ``candidates``, ``item_candidates``, ``album_distance``, ``track_distance`` methods,
please update your plugin to inherit from the new baseclass, as otherwise your plugin will
stop working with the next major release.
* Several definitions have been moved away from ``beets.library`` module:
* ``BLOB_TYPE`` constant, ``PathQuery`` and ``SingletonQuery`` queries have moved
to ``beets.dbcore.queries`` module
* ``DateType``, ``DurationType``, ``PathType`` types and ``MusicalKey`` class have
moved to ``beets.dbcore.types`` module.
Old imports are now deprecated and will be removed in version ``3.0.0``.
Other changes:
* Refactor: Split responsibilities of Plugins into MetaDataPlugins and general Plugins.
@ -84,7 +91,7 @@ Other changes:
Autogenerated API references are now located in the `docs/api` subdirectory.
* :doc:`/plugins/substitute`: Fix rST formatting for example cases so that each
case is shown on separate lines.
* Refactored library.py file by splitting it into multiple modules within the
* Refactored library.py file by splitting it into multiple modules within the
beets/library directory.
2.3.1 (May 14, 2025)