Skip to content

Refactor view factory registration#32

Open
kaitj wants to merge 1 commit into
childmindresearch:enh/pluginsfrom
kaitj:maint/figures
Open

Refactor view factory registration#32
kaitj wants to merge 1 commit into
childmindresearch:enh/pluginsfrom
kaitj:maint/figures

Conversation

@kaitj
Copy link
Copy Markdown
Contributor

@kaitj kaitj commented Sep 25, 2024

The plugin discovery gave me some inspiration to refactor how we initially implemented the view registration. Some primary changes with this PR

  1. Reworked the plugin discovery code you had into a "register_views" function in factory.py, allowing for calling a single function instead of importing every single view in the __init__.py. Also reworked the register function to be called as part of register_views rather than being used as a decorator for each function.
  2. Retain the ability to search for plugins prefixed with "niftyone_" both on the sys.path or from a user-defined plugin directory. The plugin registration is called as part of the participant workflow.
  3. To maintain compatability with the existing version (e.g. views had a string associated in the registry), I've added a view_name (maybe temporary?), that will register a view factory using said name. If one is not provided, the view_name would be equivalent to the class name.

Edit: Will need to refactor this slightly such that the old register functionality is brought back rather than the automatic registration if view is a child of the base class.

@kaitj kaitj requested a review from clane9 September 25, 2024 19:26
@kaitj kaitj self-assigned this Sep 25, 2024
@kaitj kaitj marked this pull request as ready for review September 25, 2024 19:34
@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.72%. Comparing base (95c0715) to head (3e92f99).

Additional details and impacted files
@@               Coverage Diff               @@
##           enh/plugins      #32      +/-   ##
===============================================
- Coverage        99.72%   99.72%   -0.01%     
===============================================
  Files               19       18       -1     
  Lines              730      727       -3     
===============================================
- Hits               728      725       -3     
  Misses               2        2              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Repurposes the code from plugins.py (now deprecated) to register the
different view factories. To maintain compatability, added a "view_name"
attribute which is the name that gets added to the registry.
Additionally, the import code tries to import from the path if a search
path is provided, otherwise will search the sys.path for existing
modules with the "niftyone_" prefix.
@kaitj kaitj closed this Sep 27, 2024
@kaitj kaitj deleted the maint/figures branch September 27, 2024 14:13
@kaitj kaitj restored the maint/figures branch September 27, 2024 14:14
@kaitj kaitj reopened this Sep 27, 2024
@kaitj
Copy link
Copy Markdown
Contributor Author

kaitj commented Sep 27, 2024

Oops - accidently closed this when I deleted the branch. Reopening.

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.

1 participant