utils: centralise path asciification#6733
Open
snejus wants to merge 1 commit into
Open
Conversation
- Move Unicode normalization and separator replacement into util.asciify_path. - Update library callers and relocate focused asciify tests to util coverage.
|
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. |
Contributor
There was a problem hiding this comment.
Pull request overview
PR move Unicode normalize + separator cleanup into beets.util.asciify_path() so path shaping live one place, and library model call util for asciify.
Changes:
- Change
util.asciify_path()signature to readpath_sep_replacefrom config and do platform Unicode normalization internally. - Update
Item.destination(),Album.art_destination(), andtmpl_asciify()to call newutil.asciify_path(subpath). - Move asciify-related tests out of
test/test_library.pyinto newTestAsciifyPathintest/test_util.py.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
beets/util/__init__.py |
Centralize Unicode normalization + separator replacement inside asciify_path(). |
beets/library/models.py |
Switch callers to new asciify_path() signature and remove in-function normalization code. |
test/test_library.py |
Remove destination/asciify tests that used to assert normalization behavior via Item.destination(). |
test/test_util.py |
Add direct tests for util.asciify_path() behavior. |
Comment on lines
1212
to
+1216
| # Evaluate the selected template. | ||
| subpath = self.evaluate_template(subpath_tmpl, True) | ||
|
|
||
| # Prepare path for output: normalize Unicode characters. | ||
| if sys.platform == "darwin": | ||
| subpath = unicodedata.normalize("NFD", subpath) | ||
| else: | ||
| subpath = unicodedata.normalize("NFC", subpath) | ||
|
|
||
| if beets.config["asciify_paths"]: | ||
| subpath = util.asciify_path( | ||
| subpath, beets.config["path_sep_replace"].as_str() | ||
| ) | ||
| subpath = util.asciify_path(subpath) |
Comment on lines
+262
to
+268
| def test_unicode_normalized_nfd_on_mac(self, monkeypatch): | ||
| monkeypatch.setattr("sys.platform", "darwin") | ||
| assert util.asciify_path("caf\xe9") == "cafe" | ||
|
|
||
| def test_unicode_normalized_nfc_on_linux(self, monkeypatch): | ||
| monkeypatch.setattr("sys.platform", "linux") | ||
| assert util.asciify_path("caf\xe9") == "cafe" |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6733 +/- ##
==========================================
- Coverage 74.71% 74.50% -0.21%
==========================================
Files 162 162
Lines 20831 20822 -9
Branches 3298 3296 -2
==========================================
- Hits 15563 15514 -49
- Misses 4508 4551 +43
+ Partials 760 757 -3
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change moves path Unicode normalization and separator cleanup into
beets.util.asciify_path(), so path shaping now lives in one place instead of being split betweenbeets.library.modelsandutil.Callers in
Item.destination(),art_destination(), andtmpl_asciify()now use the sameutil.asciify_path()flow. This makes path generation more consistent and removes duplicate platform-specific normalization logic from the library layer.High-level impact: when
asciify_pathsis enabled, all asciified paths now get the same normalization, transliteration, and separator-replacement behavior through one shared utility. This should make path handling easier to reason about and safer to change later.Test coverage follows the architecture change: focused asciify behavior tests move from
test/test_library.pytotest/test_util.py, soasciify_path()is tested directly where the behavior now lives.