From 3dd18dc3be58792dfbda539359c83f5ecc02551c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Thu, 24 Jul 2025 02:57:04 +0100 Subject: [PATCH] Bring back and deprecate queries and types imports from beets.library --- beets/library/__init__.py | 25 +++++++++++++++++++++++++ docs/changelog.rst | 15 +++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/beets/library/__init__.py b/beets/library/__init__.py index 286b84189..929f935a6 100644 --- a/beets/library/__init__.py +++ b/beets/library/__init__.py @@ -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", diff --git a/docs/changelog.rst b/docs/changelog.rst index 7fb81237e..21fe951ac 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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)