Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Metadata Support to Pluginspace #467

Merged
merged 50 commits into from
Jul 5, 2023

Commits on Jun 24, 2023

  1. NEW: move metadata support to plugin space

    This commit is still very VIP
    
    - Clients can register implementations of the metadata handler using
      @exif.register(exif.Methods.XXX)
    - For copy_metadata, get_raw_metadata, get_formatted_metadata, and
      get_keys all registered implementations are run, and the output
      combined, for get_date_time, only the last registered one is used
    - Two internal plugins for metadata support, using piexif and py3exiv2
      respectively, were added
    jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    d66107d View commit details
    Browse the repository at this point in the history
  2. Add convenience functions to determine metadata support

    Module functions indicate whether any implementations for the
    Methods have been registered, and hence, what functionality
    MetadataHandler is able to provide.
    jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    9de230d View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    6f3d885 View commit details
    Browse the repository at this point in the history
  4. Remove get_raw_md, cleanup and docstrings

    - MetadataHandler no longer has two operations that distinguish between
    formatted and raw metadata. Such a functionality can be added later if
    needed.
    - exif.Methods was renamed to exif.Operations
    - Docstrings were added
    - Minor fixes
    jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    9fb1155 View commit details
    Browse the repository at this point in the history
  5. Improve metadata handler by operations.

    Consecutive calls using the same arguments are cached and served from
    cache. This applies for the backend setup, get_metadata and get_keys, as
    these are rather expensive calls.
    
    This may be problematic if metadata is written to the image in-between
    calls.
    jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    26cf2b6 View commit details
    Browse the repository at this point in the history
  6. Rename imutils.exif to imutils.metadata

    Renaming is done as this file handles all metadata related
    functionalities and not just exif metadata.
    jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    50cb581 View commit details
    Browse the repository at this point in the history
  7. Refactor registry to make client subclass MetadataPlugin

    Clients no longer register individual functions, but they subclass
    `MetadataPlugin`, and overwrite whatever methods the plugin offers.
    In addition, clients are required to set the `name` and `version`
    field of `MetadataPlugin`.
    The subclass is registered using the register function.
    jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    f0740e5 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    824fe8e View commit details
    Browse the repository at this point in the history
  9. Fix pyexiv2 plugin to conform to refactoring

    Also rename plugin from py3exiv2 to pyexiv2 to prevent confusion.
    jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    f2af1de View commit details
    Browse the repository at this point in the history
  10. Refactor MetadataPlugin to be an abstract class

    Changing MetadataPlugin to a abstract class:
    - Enforces the client to set both, `get_metadata` and `get_keys`
        - `copy_metadata` and `get_date_time` is optional to implement
    - Enforces the client to set `name` and `version`
        - Both are now a property. Prevents the loading of plugins if not
          used.
    
    Additional changes:
    - Simplified `_registry` to be a simple list. There is no need for a
      dict. Also, the additional `_has_...` properties are no longer needed.
    - Got rid of all module level `has_...` functions, and added
      `has_metadata_support` instead. Fine-grain control is not needed.
    jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    23c8fd1 View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    2bd2ded View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    e2e9c4a View commit details
    Browse the repository at this point in the history
  13. Fix conftest for metadata redesign and test version

    This is a first attempt on fixing the tests for the redesign of the
    metadata handling:
    
    - The metadata_markers (old exif_markers) have been adapted. However, I
      do not think that they make sense. For `metadata` and `nometadata` the
      condition only indicates whether the current instance of vimiv has
      metadata support (or not). For `piexif` and `pyexiv2`they indicate if
      the backend package is installed.
    
    - In addition, having condition `metadata_pyexiv2.pyexiv2 is not None`
      fails for mark `pyexiv2`. I am not sure why that is the case.
    
    - Fixtures `metadata_support`, `no_metadata_support`, `piexif` and
      `pyexiv2` have been added and implemented. They bring
      `metadata._registry` into the respective state, and make use of
      `reset_metadata_registration`, to undo the changes after each tests.
    
    - Updated `test_version`. Am I required to set for each testcase the
      mark, as well as appropriated fixture (i.e. `@mark.piexif` and specify
      `test_XXX(piexif)`. This seems a bit tedious.
    jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    446f4bd View commit details
    Browse the repository at this point in the history
  14. Make piexif / pyexiv2 lazy imports optional

    While they are absolutely required to run the plugin - and I thus
    thought they could stay required - running the test suite without piexif
    / pyexiv2 is very messy with them not being optional. We need to be able
    to compare to None there.
    karlch authored and jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    b610237 View commit details
    Browse the repository at this point in the history
  15. Temporarily shorten metadata (integration) test

    As we now rely on a plugin infrastructure, the old unit test no longer
    makes sense. Thus the test is now moved to integration and can be
    expanded in the next steps.
    karlch authored and jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    2d98a51 View commit details
    Browse the repository at this point in the history
  16. Remove metadata-related version unit tests

    With the new plugin structure, adding this information directly to
    --version is no longer simple and up for discussion.
    karlch authored and jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    fd6f951 View commit details
    Browse the repository at this point in the history
  17. Fix end2end test markers: exif -> metadata

    karlch authored and jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    6bc1742 View commit details
    Browse the repository at this point in the history
  18. Add plugins_loaded signal to api.signals

    The signal is emitted when plugins have been loaded. This allows the
    mainwindow to initialize the metadatawidget afterwards, and only if
    metadata related plugins have been loaded.
    karlch authored and jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    65fcb20 View commit details
    Browse the repository at this point in the history
  19. Remove metadata information from --version

    As these are now plugins, they are not available this early in the
    loading process. Instead plugin information should be added in :version
    explicitly.
    karlch authored and jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    56c88df View commit details
    Browse the repository at this point in the history
  20. Tests: rewrite metadata markers

    Unfortunately using metadata.has_metadata_support() does not work this
    early in the code, as we import conftest much before loading plugins and
    actually registering the metadata handlers.
    karlch authored and jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    8a93af6 View commit details
    Browse the repository at this point in the history
  21. Update metadatawidget end2end test

    Avoid importing the widget without metadata support as this registers
    the :metadata command.
    karlch authored and jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    53e12e7 View commit details
    Browse the repository at this point in the history
  22. Fix bug in piexif's copy_metadata implementation

    The metadata is stored in self._metadata, while metadata is the actual
    module.
    karlch authored and jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    99d29ad View commit details
    Browse the repository at this point in the history
  23. Add metadata wrapper plugin

    This allows loading metadata support by default, as is the current
    behaviour. We can consider deprecating this over time, but we should
    definitely keep metadata support by default as it is currently the case
    for now.
    karlch authored and jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    01fa41d View commit details
    Browse the repository at this point in the history
  24. Extend metadata integration test and markers

    - Simple tests to check if piexif / pyexiv2 correctly register the
      metadata handler
    - Correct skipping of fixtures with pytest.mark.piexif /
      pytest.mark.pyexiv2
    karlch authored and jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    1555d20 View commit details
    Browse the repository at this point in the history
  25. Fix lint / mypy

    karlch authored and jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    a0fcb6b View commit details
    Browse the repository at this point in the history
  26. Fix typo: iff -> if

    karlch authored and jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    4448981 View commit details
    Browse the repository at this point in the history
  27. Change name/version property of MetadataPlugin to static method

    While a property is well suited to get this data, having to call these
    properties on an instance of MetadataPlugin does not really make sense.
    While it is possible to implement classproperties, `abc` cannot enforce
    their implementation out-of-the-box.
    Therefore, the properties were changed to static methods.
    jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    0aa4f8b View commit details
    Browse the repository at this point in the history
  28. Cleanup of supression of exception which is never raised

    `get_metadata/get_keys` do not raise NotImplementedError. This is a
    leftover from before refactoring MetadataPlugin into an abstract class
    jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    b3206b8 View commit details
    Browse the repository at this point in the history
  29. Configuration menu
    Copy the full SHA
    03fc90f View commit details
    Browse the repository at this point in the history
  30. Configuration menu
    Copy the full SHA
    5507de9 View commit details
    Browse the repository at this point in the history
  31. Make all MetadataHandle methods raise exceptions

    Changed the `UnsupportedMetadataOperation` exception to a more general
    `MetadataError`. It gets called when a `MetadataHandler` method is called
    without any metadata plugin registered, or if none of the registered one
    provides support for `get_date_time`/`copy_metadata`.
    jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    1132667 View commit details
    Browse the repository at this point in the history
  32. Change metadat_pyexiv to require full keys

    Remove backward compatibility: Someone having the old piexif keys
    defined in their config, but wanting to use the pyexiv2 backend.
    Maintaining this backward compatibility required ugly guessing of
    potential key prefixes.
    jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    409c804 View commit details
    Browse the repository at this point in the history
  33. Assert earlier if piexif is available

    Assertion in `add_exif_inforamtion_bdd` is not reached when piexif is
    not available. The fixture `exif_content` fails before with an
    AttributeError NoneType.
    jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    89dd893 View commit details
    Browse the repository at this point in the history
  34. Make widget displaying images in the requested order

    Make sure that the extracted metadata is displayed in the same order, as
    specified in the config.
    jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    aa6a80a View commit details
    Browse the repository at this point in the history
  35. Configuration menu
    Copy the full SHA
    37d9809 View commit details
    Browse the repository at this point in the history
  36. Fix piexif data not displayed in widget

    The dict returned by `get_metadata` was keyed by the *truncated*
    metadata key, and not the original one. As the metadata widget uses the
    original keys to read out the data, nothing was displayed if long keys
    are used in the config.
    jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    7b3e2ee View commit details
    Browse the repository at this point in the history
  37. Cleaup obsolete comments

    jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    1820813 View commit details
    Browse the repository at this point in the history
  38. Remove broken link

    I did not replace the link with one to `metadata.rst` as this lead to
    a weird error. I also do not think that this link is super relevant.
    jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    a22982f View commit details
    Browse the repository at this point in the history
  39. Ensure backward compatibility but allow overwriting

    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.
    jcjgraf committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    fb66610 View commit details
    Browse the repository at this point in the history

Commits on Jul 5, 2023

  1. Configuration menu
    Copy the full SHA
    9266928 View commit details
    Browse the repository at this point in the history
  2. Fix typos

    karlch authored and jcjgraf committed Jul 5, 2023
    Configuration menu
    Copy the full SHA
    db95c4b View commit details
    Browse the repository at this point in the history
  3. Refactor (metadata) plugin loading

    User plugins are now loaded before app plugins, and not overridden. This
    allows metadata (and any other app plugins) to be loaded later and
    access any user-specific information. In this case, the user can
    deactivate auto-loading by passing
    
    metadata = none
    
    in the plugins section of the config.
    karlch authored and jcjgraf committed Jul 5, 2023
    Configuration menu
    Copy the full SHA
    1cbba4a View commit details
    Browse the repository at this point in the history
  4. Improve subsection titles

    Also make them Title Case, as in other pasts of the docs
    jcjgraf committed Jul 5, 2023
    Configuration menu
    Copy the full SHA
    c3c1654 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    2040326 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    b9fb5dd View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    1062817 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    2d16f89 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    ebfd9d6 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    816dc32 View commit details
    Browse the repository at this point in the history
  11. Docs: minor wording changes

    karlch committed Jul 5, 2023
    Configuration menu
    Copy the full SHA
    bff129b View commit details
    Browse the repository at this point in the history