utils: centralise path asciification#6733
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.
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. |
| # 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) |
| 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.85% 74.84% -0.02%
==========================================
Files 163 163
Lines 20947 20947
Branches 3299 3297 -2
==========================================
- Hits 15680 15677 -3
- Misses 4510 4512 +2
- Partials 757 758 +1
🚀 New features to boost your workflow:
|
- Move Unicode normalization and separator replacement into util.asciify_path. - Update library callers and relocate focused asciify tests to util coverage.
c1999ba to
335e512
Compare
semohr
left a comment
There was a problem hiding this comment.
Looks fine from my perspective. I think we lost a bit of test coverage here, maybe you want to check.
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.