Skip to content

Commit 87701fd

Browse files
authored
Move Distance to a dedicated module and refactor related tests (#5800)
This PR: 1. Reorganizes distance-related code by moving it from `hooks.py` and `match.py` to a new dedicated `distance.py` module: - The actual implementation logic and algorithms remain unchanged - code is moved, not rewritten - Distance class, string distance functions, and track/album distance calculators are relocated intact - Only imports and function references are updated to maintain compatibility - `current_metadata` function is replaced with equivalent `get_most_common_tags` function for clarity 2. Refactors the distance testing code from unittest to pytest: - Tests now use fixtures and parametrization while verifying the same functionality - The tested behaviors remain identical, just with improved test structure - Actually, `distance.py` coverage slightly increased since I included an additional test 3. Adds a test for the `sanitize_pairs` function to complete config utility test coverage This is primarily a code organization improvement that follows better separation of concerns, grouping related distance functionality in a single module without changing how the distance calculations work. No algorithm changes or behavior modifications were made to the core distance calculation code - it was simply moved to a more appropriate location.
2 parents 0f76312 + 99f7e94 commit 87701fd

File tree

18 files changed

+1053
-1261
lines changed

18 files changed

+1053
-1261
lines changed

beets/autotag/__init__.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,37 @@
1414

1515
"""Facilities for automatically determining files' correct metadata."""
1616

17-
from collections.abc import Mapping, Sequence
18-
from typing import Union
17+
from __future__ import annotations
18+
19+
from typing import TYPE_CHECKING, Union
1920

2021
from beets import config, logging
21-
from beets.library import Album, Item, LibModel
22+
from beets.util import get_most_common_tags as current_metadata
2223

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

26-
from .hooks import AlbumInfo, AlbumMatch, Distance, TrackInfo, TrackMatch
27-
from .match import (
28-
Proposal,
29-
Recommendation,
30-
current_metadata,
31-
tag_album,
32-
tag_item,
33-
)
27+
from .distance import Distance
28+
from .hooks import AlbumInfo, AlbumMatch, TrackInfo, TrackMatch
29+
from .match import Proposal, Recommendation, tag_album, tag_item
30+
31+
if TYPE_CHECKING:
32+
from collections.abc import Mapping, Sequence
33+
34+
from beets.library import Album, Item, LibModel
3435

3536
__all__ = [
3637
"AlbumInfo",
3738
"AlbumMatch",
38-
"Distance",
39-
"TrackInfo",
40-
"TrackMatch",
39+
"Distance", # for backwards compatibility
4140
"Proposal",
4241
"Recommendation",
42+
"TrackInfo",
43+
"TrackMatch",
4344
"apply_album_metadata",
4445
"apply_item_metadata",
4546
"apply_metadata",
46-
"current_metadata",
47+
"current_metadata", # for backwards compatibility
4748
"tag_album",
4849
"tag_item",
4950
]

0 commit comments

Comments
 (0)