Skip to content

Move path formats and replacements logic into Library and shared util#6647

Open
snejus wants to merge 5 commits into
masterfrom
relocate-path-formats-replacements-retrieval-to-lib
Open

Move path formats and replacements logic into Library and shared util#6647
snejus wants to merge 5 commits into
masterfrom
relocate-path-formats-replacements-retrieval-to-lib

Conversation

@snejus
Copy link
Copy Markdown
Member

@snejus snejus commented May 17, 2026

Summary

This PR moves path format and replacement retrieval out of beets.ui into library/shared utilities.

Changes

  • Added beets/util/pathformats.py with PF_KEY_DEFAULT, PF_KEY_QUERIES, and get_path_formats(subview).
  • Added Library.path_formats and Library.replacements as cached_property values derived from config.
  • Removed UI-owned get_path_formats/get_replacements and simplified _open_library() to construct Library without passing those values.
  • Updated consumers (beets/library/models.py, beetsplug/bench.py, beetsplug/convert.py) to use the shared path-format utility.
  • Refactored convert destination path calls through ConvertPlugin.get_item_destination.
  • Replaced redundant UI tests with focused coverage in test/util/test_pathformats.py.
  • Updated .git-blame-ignore-revs.

Why

  • Keeps path/replacement behavior close to library internals instead of CLI orchestration.
  • Preserves layered paths defaults by iterating config via Confuse items().
  • Reduces duplication in convert destination handling.

@snejus snejus requested a review from a team as a code owner May 17, 2026 07:41
@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.

@snejus snejus force-pushed the create-separate-module-for-sort branch from 03551b8 to 0075269 Compare May 17, 2026 07:43
@snejus snejus force-pushed the relocate-path-formats-replacements-retrieval-to-lib branch from 82173d0 to 1bab999 Compare May 17, 2026 07:43
@codecov
Copy link
Copy Markdown

codecov Bot commented May 17, 2026

Codecov Report

❌ Patch coverage is 93.02326% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.48%. Comparing base (6dd6251) to head (5c2c530).

Files with missing lines Patch % Lines
beets/library/library.py 90.90% 2 Missing ⚠️
beetsplug/convert.py 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6647      +/-   ##
==========================================
+ Coverage   72.46%   72.48%   +0.02%     
==========================================
  Files         161      162       +1     
  Lines       20719    20727       +8     
  Branches     3280     3279       -1     
==========================================
+ Hits        15014    15024      +10     
+ Misses       4979     4978       -1     
+ Partials      726      725       -1     
Files with missing lines Coverage Δ
beets/library/models.py 87.36% <100.00%> (+0.32%) ⬆️
beets/library/queries.py 100.00% <ø> (ø)
beets/ui/__init__.py 81.77% <100.00%> (-0.34%) ⬇️
beets/util/pathformats.py 100.00% <100.00%> (ø)
beetsplug/bench.py 28.57% <100.00%> (+1.74%) ⬆️
beetsplug/convert.py 74.77% <88.88%> (+0.22%) ⬆️
beets/library/library.py 93.18% <90.90%> (-1.27%) ⬇️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Base automatically changed from create-separate-module-for-sort to master May 19, 2026 20:58
@snejus snejus requested a review from Copilot May 21, 2026 14:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

grug see PR move path format + replace rules out of UI layer into library + shared util. grug like: library own library things, UI just drive.

Changes:

  • add beets/util/pathformats.py helper for reading layered paths config (with query key expansion)
  • make Library.path_formats + Library.replacements come from config via cached_property, and simplify UI _open_library()
  • update convert + bench + tests to use new shared path format plumbing

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test/util/test_pathformats.py new focused pytest coverage for layered paths reading
test/ui/test_ui.py remove UI-owned path format tests now covered elsewhere
test/test_library.py make destination tests set explicit lib.path_formats to avoid depending on config defaults
beetsplug/convert.py switch to shared get_path_formats + refactor destination calculation via helper
beetsplug/bench.py use shared PF_KEY_DEFAULT constant for benchmark path formats
beets/util/pathformats.py new shared path format constants + get_path_formats util
beets/ui/init.py remove UI-owned get_path_formats/get_replacements; open Library without passing them
beets/library/queries.py remove PF_KEY_DEFAULT constant from queries module
beets/library/models.py import PF_KEY_DEFAULT from util instead of queries
beets/library/library.py add cached_property path_formats + replacements derived from config

Comment thread beets/util/pathformats.py
Comment thread beets/library/library.py
Comment thread beets/ui/__init__.py
Comment thread beets/library/library.py Outdated
Comment thread beetsplug/bench.py Outdated
snejus added 3 commits May 21, 2026 21:50
Ensure that path_formats is set in relevant tests to avoid reliance on
defaults and to clarify test intent. Update Library constructor type hint for
path_formats to use Template type.

This default value was only relevant in tests.
@snejus snejus force-pushed the relocate-path-formats-replacements-retrieval-to-lib branch from 1bab999 to 290c5f8 Compare May 21, 2026 20:52
@snejus snejus force-pushed the relocate-path-formats-replacements-retrieval-to-lib branch from 290c5f8 to 5c2c530 Compare May 21, 2026 20:52
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