-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Move Distance to a dedicated module and refactor related tests #5800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR reorganizes distance‐related logic into a dedicated module and updates tests accordingly. Key changes include:
- Moving functions and classes (Distance, string distance functions, track/album distance calculators) to distance.py.
- Refactoring tests from unittest to pytest with improved structure and additional test coverage.
- Replacing current_metadata with get_most_common_tags for clarity and consistency.
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
test/util/test_config.py | Adds tests for sanitize_choices and sanitize_pairs |
test/test_util.py | Refactors plurality tests using pytest; note potential tuple issue |
test/test_plugins.py | Removes outdated unittest-based tests |
test/autotag/test_distance.py | Covers various aspects of distance calculations and distance methods |
beetsplug/*.py | Updates imports to use the new distance module |
beets/util/config.py | Introduces new configuration sanitization functions |
beets/util/init.py | Adds get_most_common_tags implementation |
beets/plugins.py | Removes local configuration cleaning functions from plugins |
beets/importer/tasks.py | Updates metadata extraction to use get_most_common_tags |
beets/autotag/match.py | Removes current_metadata in favor of get_most_common_tags, cleans diff |
beets/autotag/hooks.py | Removes legacy distance implementation |
beets/autotag/init.py | Removes Distance and current_metadata exports from public API |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks mostly good to me.
You renamed current_metadata
to get_most_common_tags
which will break external programs using this function. We need to keep this in mind when incrementing the version number. This should be mentioned it in the changelog imo.
A note on test durations
|
Very good point!!! I see it's indeed used outside of beets: $ gh search code autotag.current_metadata beets 2.3.1 │ 🐍 3.9 🐶
Showing 3 of 3 results
beetbox/beets beets/importer/tasks.py
likelies, consensus = autotag.current_metadata(self.items)
rembo10/headphones lib/beets/importer.py
likelies, consensus = autotag.current_metadata(self.items)
pSpitzner/beets-flask backend/beets_flask/importer/states.py
info, _ = autotag.current_metadata(items) So good to have another pair of eyes looking at this! <3 Added both |
I had to bring back our patchy Safe to say, I'm not delighted about it. Well, this way at least we will continue being aware of the issue! Essentially, we shouldn't be importing |
Maybe it is reasonable to move the plugins related code out of the distances.py as it is only used in the I.e. move this from distance.py to match.py: # Plugins.
dist.update(plugins.album_distance(items, album_info, mapping)) |
Same issue since I'm instead questioning the entire design of
|
Indeed seems a bit convoluted. Optimally and if possible, autotag should be completely independent of plugins. Not sure what is the right approach here, maybe a flowcharts might help? Keep in mind that I also moved the distance function from plugins into a metadataplugin file in #5787. Might help to disentangle this a bit too. Let's also keep the scope of this PR in mind, maybe we split this into multiple PRs and refactor further once we are more confident on how to proceed here. |
Oh yeah I forgot to mention in my comment that I'm not going to fix it here to keep it within the scope 😅 |
Is this good to go by any chance @semohr ? |
Sure, feel free to merge it. |
This integration test failed because `chartlyrics.com` website is no longer available, so I'm removing it.
This PR:
Reorganizes distance-related code by moving it from
hooks.py
andmatch.py
to a new dedicateddistance.py
module:current_metadata
function is replaced with equivalentget_most_common_tags
function for clarityRefactors the distance testing code from unittest to pytest:
distance.py
coverage slightly increased since I included an additional testAdds a test for the
sanitize_pairs
function to complete config utility test coverageThis 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.