Skip to content

Commit 3dd18dc

Browse files
committed
Bring back and deprecate queries and types imports from beets.library
1 parent 2680750 commit 3dd18dc

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

beets/library/__init__.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,33 @@
1+
import warnings
2+
from importlib import import_module
3+
14
from .exceptions import FileOperationError, ReadError, WriteError
25
from .library import Library
36
from .models import Album, Item, LibModel
47
from .queries import parse_query_parts, parse_query_string
58

9+
NEW_MODULE_BY_NAME = dict.fromkeys(
10+
("DateType", "DurationType", "MusicalKey", "PathType"), "beets.dbcore.types"
11+
) | dict.fromkeys(
12+
("BLOB_TYPE", "SingletonQuery", "PathQuery"), "beets.dbcore.query"
13+
)
14+
15+
16+
def __getattr__(name: str):
17+
if name in NEW_MODULE_BY_NAME:
18+
new_module = NEW_MODULE_BY_NAME[name]
19+
warnings.warn(
20+
(
21+
f"'beets.library.{name}' import is deprecated and will be removed"
22+
f"in v3.0.0; import '{new_module}.{name}' instead."
23+
),
24+
DeprecationWarning,
25+
stacklevel=2,
26+
)
27+
return getattr(import_module(new_module), name)
28+
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
29+
30+
631
__all__ = [
732
"Library",
833
"LibModel",

docs/changelog.rst

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Bug fixes:
5454
e.g. non latin characters as 盗作. If you want to keep the legacy behavior
5555
set the config option ``spotify.search_query_ascii: yes``.
5656
:bug:`5699`
57-
57+
5858
For packagers:
5959

6060
* Optional ``extra_tags`` parameter has been removed from
@@ -67,7 +67,7 @@ For plugin developers:
6767
source registration in the process of introducing typings to the code.
6868
Custom art sources might need to be adapted.
6969
* We split the responsibilities of plugins into two base classes
70-
#. :class:`beets.plugins.BeetsPlugin`
70+
#. :class:`beets.plugins.BeetsPlugin`
7171
is the base class for all plugins, any plugin needs to inherit from this class.
7272
#. :class:`beets.metadata_plugin.MetadataSourcePlugin`
7373
allows plugins to act like metadata sources. E.g. used by the MusicBrainz plugin. All plugins
@@ -76,15 +76,22 @@ For plugin developers:
7676
``album_for_id``, ``candidates``, ``item_candidates``, ``album_distance``, ``track_distance`` methods,
7777
please update your plugin to inherit from the new baseclass, as otherwise your plugin will
7878
stop working with the next major release.
79-
79+
* Several definitions have been moved away from ``beets.library`` module:
80+
* ``BLOB_TYPE`` constant, ``PathQuery`` and ``SingletonQuery`` queries have moved
81+
to ``beets.dbcore.queries`` module
82+
* ``DateType``, ``DurationType``, ``PathType`` types and ``MusicalKey`` class have
83+
moved to ``beets.dbcore.types`` module.
84+
Old imports are now deprecated and will be removed in version ``3.0.0``.
85+
86+
8087
Other changes:
8188

8289
* Refactor: Split responsibilities of Plugins into MetaDataPlugins and general Plugins.
8390
* Documentation structure for auto generated API references changed slightly.
8491
Autogenerated API references are now located in the `docs/api` subdirectory.
8592
* :doc:`/plugins/substitute`: Fix rST formatting for example cases so that each
8693
case is shown on separate lines.
87-
* Refactored library.py file by splitting it into multiple modules within the
94+
* Refactored library.py file by splitting it into multiple modules within the
8895
beets/library directory.
8996

9097
2.3.1 (May 14, 2025)

0 commit comments

Comments
 (0)