Skip to content

template evaluation: feed all templates into evaluate_fmt as strings#6692

Open
snejus wants to merge 1 commit into
masterfrom
rename-evaluate-template-to-evaluate-fmt
Open

template evaluation: feed all templates into evaluate_fmt as strings#6692
snejus wants to merge 1 commit into
masterfrom
rename-evaluate-template-to-evaluate-fmt

Conversation

@snejus

@snejus snejus commented May 30, 2026

Copy link
Copy Markdown
Member

This change standardizes template handling around evaluate_fmt, so callers now pass plain format strings everywhere instead of a mix of strings and precompiled Template objects.

At a high level, it:

  • centralizes template compilation in get_template
  • keeps path_formats as simple (query, "format string") pairs
  • removes template parsing from models, commands, plugins, and tests

Architecturally, this makes formatting flow through one consistent path: string in, evaluate_fmt handles compilation and evaluation. The result is a simpler API, fewer special cases at call sites, and easier reasoning about how path and display formatting works across the codebase.

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

- Replace evaluate_template with evaluate_fmt across models, commands,
  plugins, and tests, and centralize template compilation through
  a cached get_template helper.
- Store path format patterns as plain strings instead of Template
  objects so template parsing happens in one place and call sites stay
  simpler and more consistent.
@snejus snejus force-pushed the rename-evaluate-template-to-evaluate-fmt branch from 3998eec to 888eca8 Compare May 30, 2026 20:33

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 look at PR. grug see refactor: many place pass Template object around, now all place pass plain string. one funnel: evaluate_fmt call get_template (lru_cache) and substitute. less special case, less branch, less complexity demon spirit. grug like.

Changes:

  • rename evaluate_templateevaluate_fmt and accept only str (no more Template branch)
  • rename functemplate.templateget_template, add type hint, keep lru_cache
  • path_formats now tuple[str, str] everywhere; get_path_formats no longer pre-compiles

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
beets/util/functemplate.py rename templateget_template, add from __future__ import annotations and type hint
beets/util/pathformats.py PathFormat is now tuple[str, str]; drop pre-compilation
beets/dbcore/db.py rename evaluate_templateevaluate_fmt; drop Template/str branch
beets/library/models.py __format__, art_destination, destination use evaluate_fmt directly
beets/ui/commands/modify.py drop pre-compiled templates dict; pass raw fmt strings
beetsplug/smartplaylist.py call evaluate_fmt instead of evaluate_template
beetsplug/bench.py use raw format strings in path_formats
test/test_library.py rename calls to evaluate_fmt
test/plugins/test_inline.py rename calls to evaluate_fmt
test/plugins/test_rewrite.py rename calls to evaluate_fmt
test/plugins/test_smartplaylist.py mock evaluate_fmt instead of evaluate_template
test/plugins/test_types_plugin.py rename calls to evaluate_fmt
test/ui/test_ui.py assert plain (key, str) tuple
test/util/test_pathformats.py drop tmpl.original unwrapping

grug check whole repo: no leftover evaluate_template call, no leftover functemplate.template( call. rename clean. cache still on get_template so no perf regression from dropping pre-compile in get_path_formats. grug happy.

@codecov

codecov Bot commented May 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.55%. Comparing base (2efc80b) to head (888eca8).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6692      +/-   ##
==========================================
- Coverage   72.57%   72.55%   -0.02%     
==========================================
  Files         162      162              
  Lines       20810    20797      -13     
  Branches     3292     3289       -3     
==========================================
- Hits        15103    15090      -13     
  Misses       4982     4982              
  Partials      725      725              
Files with missing lines Coverage Δ
beets/dbcore/db.py 93.92% <100.00%> (-0.02%) ⬇️
beets/library/models.py 87.20% <100.00%> (-0.16%) ⬇️
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%> (ø)
🚀 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