Skip to content

template evaluation: handle string templates only#6737

Open
snejus wants to merge 1 commit into
masterfrom
evaluate-template-strings-only
Open

template evaluation: handle string templates only#6737
snejus wants to merge 1 commit into
masterfrom
evaluate-template-strings-only

Conversation

@snejus

@snejus snejus commented Jun 13, 2026

Copy link
Copy Markdown
Member

What changed

  • Template evaluation is now routed through a single string-based API: evaluate_fmt(...).
  • Format values are treated as plain strings everywhere, instead of sometimes being strings and sometimes compiled Template objects.
  • Template compilation and caching are centralized in beets.util.functemplate.get_template(...).

Architecture impact

  • dbcore now owns one clear path for evaluating format strings.
  • path_formats now carries tuple[str, str] values, which removes type branching in consumers.
  • Callers in library, modify, and plugins now pass raw format strings and rely on the shared helper to compile/cache them.

Why this matters

  • Removes conditional logic around 'string vs Template object' handling.
  • Makes the formatting flow easier to follow and easier to maintain.
  • Keeps behavior the same at a high level while simplifying the internal contract for template usage.

Copilot AI review requested due to automatic review settings June 13, 2026 17:17
@snejus snejus requested a review from a team as a code owner June 13, 2026 17:17
@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.

@codecov

codecov Bot commented Jun 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.51%. Comparing base (beff630) to head (10f49d1).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6737      +/-   ##
==========================================
- Coverage   74.54%   74.51%   -0.03%     
==========================================
  Files         162      162              
  Lines       20832    20820      -12     
  Branches     3298     3295       -3     
==========================================
- Hits        15529    15515      -14     
- Misses       4548     4549       +1     
- Partials      755      756       +1     
Files with missing lines Coverage Δ
beets/dbcore/db.py 94.07% <100.00%> (-0.02%) ⬇️
beets/library/models.py 87.63% <100.00%> (-0.14%) ⬇️
beets/ui/commands/modify.py 93.84% <ø> (-0.19%) ⬇️
beets/util/functemplate.py 88.64% <100.00%> (+0.04%) ⬆️
beets/util/pathformats.py 100.00% <100.00%> (ø)
beetsplug/bench.py 26.82% <ø> (-1.75%) ⬇️
beetsplug/smartplaylist.py 87.96% <100.00%> (ø)

... 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.

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

grug see PR make template eval go through one string path: evaluate_fmt(...). goal is less “string vs Template object” branching.

Changes:

  • rename model templating API to string-only evaluate_fmt(fmt, for_path=...) and route eval through get_template(...) cache
  • switch path_formats plumbing to carry raw format strings (no compiled Template objects)
  • update callers (library/models, modify command, smartplaylist, bench, tests) to pass strings

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
test/test_library.py switch item template eval assertions to evaluate_fmt
test/plugins/test_types_plugin.py switch template conditionals tests to evaluate_fmt
test/plugins/test_smartplaylist.py update smartplaylist mocks to evaluate_fmt (but currently broken w/ kwargs + bytes)
test/plugins/test_rewrite.py switch album template eval assertion to evaluate_fmt
test/plugins/test_inline.py switch inline plugin test to evaluate_fmt
beetsplug/smartplaylist.py use evaluate_fmt(..., for_path=True) for playlist name + debug formatting
beetsplug/bench.py set lib.path_formats entries to raw format strings
beets/util/pathformats.py make get_path_formats return (key, fmt_str) pairs
beets/util/functemplate.py centralize compilation/cache under get_template(fmt)
beets/ui/commands/modify.py remove per-run template compile dict; call evaluate_fmt directly
beets/library/models.py switch formatting and path destination building to evaluate_fmt
beets/dbcore/db.py replace evaluate_template with evaluate_fmt using get_template

Comment thread beets/util/functemplate.py Outdated
Comment thread beets/util/functemplate.py Outdated
Comment thread beets/dbcore/db.py Outdated
Comment thread test/plugins/test_smartplaylist.py Outdated
Comment thread test/plugins/test_smartplaylist.py Outdated
Comment thread test/plugins/test_smartplaylist.py Outdated
@snejus snejus force-pushed the evaluate-template-strings-only branch 2 times, most recently from 23faa20 to 151fc58 Compare June 13, 2026 17:33
- Handle formats as strings ONLY and evaluate them through a shared
  cached template helper.
- This removes the need for conditional logic that acts on Template
  objects or strings.
@snejus snejus force-pushed the evaluate-template-strings-only branch from 151fc58 to 10f49d1 Compare June 13, 2026 17:42
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