Skip to content

Commit 44af7b2

Browse files
authored
Merge branch 'master' into feature/add-artist-to-item-entry-template
2 parents 034e608 + 619589d commit 44af7b2

File tree

5 files changed

+91
-8
lines changed

5 files changed

+91
-8
lines changed

beets/autotag/__init__.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@
1616

1717
from __future__ import annotations
1818

19+
import warnings
20+
from importlib import import_module
1921
from typing import TYPE_CHECKING, Union
2022

2123
from beets import config, logging
22-
from beets.util import get_most_common_tags as current_metadata
2324

2425
# Parts of external interface.
2526
from beets.util import unique_list
2627

27-
from .distance import Distance
28+
from ..util import deprecate_imports
2829
from .hooks import AlbumInfo, AlbumMatch, TrackInfo, TrackMatch
2930
from .match import Proposal, Recommendation, tag_album, tag_item
3031

@@ -33,18 +34,34 @@
3334

3435
from beets.library import Album, Item, LibModel
3536

37+
38+
def __getattr__(name: str):
39+
if name == "current_metadata":
40+
warnings.warn(
41+
(
42+
f"'beets.autotag.{name}' is deprecated and will be removed in"
43+
" 3.0.0. Use 'beets.util.get_most_common_tags' instead."
44+
),
45+
DeprecationWarning,
46+
stacklevel=2,
47+
)
48+
return import_module("beets.util").get_most_common_tags
49+
50+
return deprecate_imports(
51+
__name__, {"Distance": "beets.autotag.distance"}, name, "3.0.0"
52+
)
53+
54+
3655
__all__ = [
3756
"AlbumInfo",
3857
"AlbumMatch",
39-
"Distance", # for backwards compatibility
4058
"Proposal",
4159
"Recommendation",
4260
"TrackInfo",
4361
"TrackMatch",
4462
"apply_album_metadata",
4563
"apply_item_metadata",
4664
"apply_metadata",
47-
"current_metadata", # for backwards compatibility
4865
"tag_album",
4966
"tag_item",
5067
]

beets/library/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1+
from beets.util import deprecate_imports
2+
13
from .exceptions import FileOperationError, ReadError, WriteError
24
from .library import Library
35
from .models import Album, Item, LibModel
46
from .queries import parse_query_parts, parse_query_string
57

8+
NEW_MODULE_BY_NAME = dict.fromkeys(
9+
("DateType", "DurationType", "MusicalKey", "PathType"), "beets.dbcore.types"
10+
) | dict.fromkeys(
11+
("BLOB_TYPE", "SingletonQuery", "PathQuery"), "beets.dbcore.query"
12+
)
13+
14+
15+
def __getattr__(name: str):
16+
return deprecate_imports(__name__, NEW_MODULE_BY_NAME, name, "3.0.0")
17+
18+
619
__all__ = [
720
"Library",
821
"LibModel",

beets/ui/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import sys
2929
import textwrap
3030
import traceback
31+
import warnings
3132
from difflib import SequenceMatcher
3233
from typing import TYPE_CHECKING, Any, Callable
3334

@@ -104,6 +105,21 @@ def _stream_encoding(stream, default="utf-8"):
104105
return stream.encoding or default
105106

106107

108+
def decargs(arglist):
109+
"""Given a list of command-line argument bytestrings, attempts to
110+
decode them to Unicode strings when running under Python 2.
111+
112+
.. deprecated:: 2.4.0
113+
This function will be removed in 3.0.0.
114+
"""
115+
warnings.warn(
116+
"decargs() is deprecated and will be removed in version 3.0.0.",
117+
DeprecationWarning,
118+
stacklevel=2,
119+
)
120+
return arglist
121+
122+
107123
def print_(*strings: str, end: str = "\n") -> None:
108124
"""Like print, but rather than raising an error when a character
109125
is not in the terminal's encoding's character set, just silently

beets/util/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import sys
2828
import tempfile
2929
import traceback
30+
import warnings
3031
from collections import Counter
3132
from collections.abc import Sequence
3233
from contextlib import suppress
@@ -1191,3 +1192,26 @@ def get_temp_filename(
11911192
def unique_list(elements: Iterable[T]) -> list[T]:
11921193
"""Return a list with unique elements in the original order."""
11931194
return list(dict.fromkeys(elements))
1195+
1196+
1197+
def deprecate_imports(
1198+
old_module: str, new_module_by_name: dict[str, str], name: str, version: str
1199+
) -> Any:
1200+
"""Handle deprecated module imports by redirecting to new locations.
1201+
1202+
Facilitates gradual migration of module structure by intercepting import
1203+
attempts for relocated functionality. Issues deprecation warnings while
1204+
transparently providing access to the moved implementation, allowing
1205+
existing code to continue working during transition periods.
1206+
"""
1207+
if new_module := new_module_by_name.get(name):
1208+
warnings.warn(
1209+
(
1210+
f"'{old_module}.{name}' is deprecated and will be removed"
1211+
f" in {version}. Use '{new_module}.{name}' instead."
1212+
),
1213+
DeprecationWarning,
1214+
stacklevel=2,
1215+
)
1216+
return getattr(import_module(new_module), name)
1217+
raise AttributeError(f"module '{old_module}' has no attribute '{name}'")

docs/changelog.rst

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

6161
* Optional ``extra_tags`` parameter has been removed from
@@ -68,7 +68,7 @@ For plugin developers:
6868
source registration in the process of introducing typings to the code.
6969
Custom art sources might need to be adapted.
7070
* We split the responsibilities of plugins into two base classes
71-
#. :class:`beets.plugins.BeetsPlugin`
71+
#. :class:`beets.plugins.BeetsPlugin`
7272
is the base class for all plugins, any plugin needs to inherit from this class.
7373
#. :class:`beets.metadata_plugin.MetadataSourcePlugin`
7474
allows plugins to act like metadata sources. E.g. used by the MusicBrainz plugin. All plugins
@@ -77,15 +77,28 @@ For plugin developers:
7777
``album_for_id``, ``candidates``, ``item_candidates``, ``album_distance``, ``track_distance`` methods,
7878
please update your plugin to inherit from the new baseclass, as otherwise your plugin will
7979
stop working with the next major release.
80-
80+
* Several definitions have been moved:
81+
* ``BLOB_TYPE`` constant, ``PathQuery`` and ``SingletonQuery`` queries have
82+
moved from ``beets.library`` to ``beets.dbcore.query`` module
83+
* ``DateType``, ``DurationType``, ``PathType`` types and ``MusicalKey``
84+
class have moved from ``beets.library`` to ``beets.dbcore.types`` module.
85+
* ``Distance`` has moved from ``beets.autotag`` to
86+
``beets.autotag.distance`` module.
87+
* ``beets.autotag.current_metadata`` has been renamed to
88+
``beets.util.get_most_common_tags``.
89+
90+
Old imports are now deprecated and will be removed in version ``3.0.0``.
91+
* ``beets.ui.decargs`` is deprecated and will be removed in version ``3.0.0``.
92+
93+
8194
Other changes:
8295

8396
* Refactor: Split responsibilities of Plugins into MetaDataPlugins and general Plugins.
8497
* Documentation structure for auto generated API references changed slightly.
8598
Autogenerated API references are now located in the `docs/api` subdirectory.
8699
* :doc:`/plugins/substitute`: Fix rST formatting for example cases so that each
87100
case is shown on separate lines.
88-
* Refactored library.py file by splitting it into multiple modules within the
101+
* Refactored library.py file by splitting it into multiple modules within the
89102
beets/library directory.
90103

91104
2.3.1 (May 14, 2025)

0 commit comments

Comments
 (0)