Skip to content

utils: centralise path asciification#6733

Open
snejus wants to merge 1 commit into
masterfrom
include-unicodedata-in-asciify-path
Open

utils: centralise path asciification#6733
snejus wants to merge 1 commit into
masterfrom
include-unicodedata-in-asciify-path

Conversation

@snejus

@snejus snejus commented Jun 13, 2026

Copy link
Copy Markdown
Member
  • 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 between beets.library.models and util.

  • Callers in Item.destination(), art_destination(), and tmpl_asciify() now use the same util.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_paths is 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.py to test/test_util.py, so asciify_path() is tested directly where the behavior now lives.

- Move Unicode normalization and separator replacement into util.asciify_path.
- Update library callers and relocate focused asciify tests to util coverage.
Copilot AI review requested due to automatic review settings June 13, 2026 00:39
@snejus snejus requested a review from a team as a code owner June 13, 2026 00:39
@github-actions

Copy link
Copy Markdown

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 read path_sep_replace from config and do platform Unicode normalization internally.
  • Update Item.destination(), Album.art_destination(), and tmpl_asciify() to call new util.asciify_path(subpath).
  • Move asciify-related tests out of test/test_library.py into new TestAsciifyPath in test/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 thread beets/library/models.py
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 thread test/test_util.py
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

codecov Bot commented Jun 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.50%. Comparing base (ec729d3) to head (c1999ba).
⚠️ Report is 3 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
beets/library/models.py 33.33% 2 Missing ⚠️
beets/util/__init__.py 91.66% 1 Missing ⚠️
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     
Files with missing lines Coverage Δ
beets/util/__init__.py 79.64% <91.66%> (+0.40%) ⬆️
beets/library/models.py 87.36% <33.33%> (-0.41%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants