template evaluation: feed all templates into evaluate_fmt as strings#6692
template evaluation: feed all templates into evaluate_fmt as strings#6692snejus wants to merge 1 commit into
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. |
- 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.
3998eec to
888eca8
Compare
There was a problem hiding this comment.
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_template→evaluate_fmtand accept onlystr(no moreTemplatebranch) - rename
functemplate.template→get_template, add type hint, keep lru_cache path_formatsnowtuple[str, str]everywhere;get_path_formatsno 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 template → get_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_template → evaluate_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 Report✅ All modified and coverable lines are covered by tests. 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
🚀 New features to boost your workflow:
|
This change standardizes template handling around
evaluate_fmt, so callers now pass plain format strings everywhere instead of a mix of strings and precompiledTemplateobjects.At a high level, it:
get_templatepath_formatsas simple(query, "format string")pairsArchitecturally, this makes formatting flow through one consistent path: string in,
evaluate_fmthandles 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.