Skip to content

Commit

Permalink
Ensure backward compatibility but allow overwriting
Browse files Browse the repository at this point in the history
If no metadata plugin has been specified, the default `metadata` plugins
loads one of `metadata_pyexiv` or `metadata_piexif` (depending on the
installed backend). If a specific backend is configured, they it is
ensured that `metadata` does not interfere.

This is achieved by deferring the loading of the `metadata` plugin to
the end of all plugins. At that point `metadata` can check if another
metadata plugin has been loaded, and if so, do nothing.
  • Loading branch information
jcjgraf committed Jun 24, 2023
1 parent a22982f commit 92975bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions vimiv/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ def load() -> None:
user_plugins = _get_plugins(_user_plugin_directory)
_logger.debug("Available user plugins: %s", quotedjoin(user_plugins))
for plugin, info in _plugins.items():
if plugin == "metadata":
# Skip metadata plugin and load it manually after all other plugins. This way the plugin can check whether another metadata plugin has been loaded
_logger.debug("Deffer loading of metadata plugin")
continue
if plugin in app_plugins:
_load_plugin(plugin, info, _app_plugin_directory)
elif plugin in user_plugins:
Expand All @@ -113,6 +117,7 @@ def load() -> None:
quotedjoin(user_plugins),
_user_plugin_directory,
)
_load_plugin("metadata", _plugins["metadata"], _app_plugin_directory)
_logger.debug("Plugin loading completed")
api.signals.plugins_loaded.emit()

Expand Down
10 changes: 9 additions & 1 deletion vimiv/plugins/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,20 @@

from vimiv.plugins import metadata_piexif, metadata_pyexiv2
from vimiv.utils import log
from vimiv.imutils import metadata

_logger = log.module_logger(__name__)


def init(*_args: Any, **_kwargs: Any) -> None:
"""Initialize metadata plugin depending on available backend."""
"""Initialize metadata plugin depending on available backend.
If any other backend has already been registered, do not register any new one.
"""
if metadata.has_metadata_support():
_logger.info("Not loading a default metadata backend, as one has been loaded manually")
return

if metadata_pyexiv2.pyexiv2 is not None:
metadata_pyexiv2.init()
elif metadata_piexif.piexif is not None:
Expand Down

0 comments on commit 92975bc

Please sign in to comment.