mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 08:39:17 +01:00
beetsplug: Error out on conflicts in template functions
Raises an exception if multiple plugins provide template functions for the same field. Closes #5002, supersedes #5003.
This commit is contained in:
parent
adf4b9779a
commit
e64ee0b0cd
2 changed files with 27 additions and 4 deletions
|
|
@ -444,14 +444,29 @@ def import_stages():
|
||||||
# New-style (lazy) plugin-provided fields.
|
# New-style (lazy) plugin-provided fields.
|
||||||
|
|
||||||
|
|
||||||
|
def _check_conflicts_and_merge(plugin, plugin_funcs, funcs):
|
||||||
|
"""Check the provided template functions for conflicts and merge into funcs.
|
||||||
|
|
||||||
|
Raises a `PluginConflictException` if a plugin defines template functions
|
||||||
|
for fields that another plugin has already defined template functions for.
|
||||||
|
"""
|
||||||
|
if plugin_funcs:
|
||||||
|
if not plugin_funcs.keys().isdisjoint(funcs.keys()):
|
||||||
|
conflicted_fields = ", ".join(plugin_funcs.keys() & funcs.keys())
|
||||||
|
raise PluginConflictException(
|
||||||
|
f"Plugin {plugin.name} defines template functions for "
|
||||||
|
f"{conflicted_fields} that conflict with another plugin."
|
||||||
|
)
|
||||||
|
funcs.update(plugin_funcs)
|
||||||
|
|
||||||
|
|
||||||
def item_field_getters():
|
def item_field_getters():
|
||||||
"""Get a dictionary mapping field names to unary functions that
|
"""Get a dictionary mapping field names to unary functions that
|
||||||
compute the field's value.
|
compute the field's value.
|
||||||
"""
|
"""
|
||||||
funcs = {}
|
funcs = {}
|
||||||
for plugin in find_plugins():
|
for plugin in find_plugins():
|
||||||
if plugin.template_fields:
|
_check_conflicts_and_merge(plugin, plugin.template_fields, funcs)
|
||||||
funcs.update(plugin.template_fields)
|
|
||||||
return funcs
|
return funcs
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -459,8 +474,7 @@ def album_field_getters():
|
||||||
"""As above, for album fields."""
|
"""As above, for album fields."""
|
||||||
funcs = {}
|
funcs = {}
|
||||||
for plugin in find_plugins():
|
for plugin in find_plugins():
|
||||||
if plugin.album_template_fields:
|
_check_conflicts_and_merge(plugin, plugin.album_template_fields, funcs)
|
||||||
funcs.update(plugin.album_template_fields)
|
|
||||||
return funcs
|
return funcs
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -277,6 +277,15 @@ Bug fixes:
|
||||||
* Fix bug regarding displaying tracks that have been changed not being
|
* Fix bug regarding displaying tracks that have been changed not being
|
||||||
displayed unless the detail configuration is enabled.
|
displayed unless the detail configuration is enabled.
|
||||||
|
|
||||||
|
For plugin developers:
|
||||||
|
|
||||||
|
* beets now explicitly prevents multiple plugins to define replacement
|
||||||
|
functions for the same field. When previously defining `template_fields`
|
||||||
|
for the same field in two plugins, the last loaded plugin would silently
|
||||||
|
overwrite the function defined by the other plugin.
|
||||||
|
Now, beets will raise an exception when this happens.
|
||||||
|
:bug:`5002`
|
||||||
|
|
||||||
For packagers:
|
For packagers:
|
||||||
|
|
||||||
* As noted above, the minimum Python version is now 3.7.
|
* As noted above, the minimum Python version is now 3.7.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue