-
Notifications
You must be signed in to change notification settings - Fork 39
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
Improved interface for discovery of and access to installed Webviz plugins #377
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""Implements registry that contains all installed plugins | ||
""" | ||
|
||
from typing import Dict, List, Type, Callable | ||
|
||
from .._plugin_abc import WebvizPluginABC | ||
from ._load_all_installed_webviz_plugins import load_all_installed_webviz_plugins | ||
from ._load_all_installed_webviz_plugins import PluginDistInfo | ||
from ._load_all_installed_webviz_plugins import LoadedPlugin | ||
|
||
try: | ||
# Python 3.8+ | ||
from importlib.metadata import distributions # type: ignore | ||
except ModuleNotFoundError: | ||
# Python < 3.8 | ||
from importlib_metadata import distributions # type: ignore | ||
Comment on lines
+11
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will not give similar issues as what caused #373? |
||
|
||
# Currently do all the imports here during module execution | ||
# May be refactored to do lazy loading when first accessed through one of the functions below | ||
_all_loaded_plugins: Dict[str, LoadedPlugin] = load_all_installed_webviz_plugins( | ||
distributions() | ||
) | ||
|
||
|
||
def has_plugin(plugin_name: str) -> bool: | ||
return plugin_name in _all_loaded_plugins | ||
|
||
|
||
def plugin_class(plugin_name: str) -> Type[WebvizPluginABC]: | ||
return _all_loaded_plugins[plugin_name].plugin_class | ||
|
||
|
||
def plugin_metadata(plugin_name: str) -> PluginDistInfo: | ||
return _all_loaded_plugins[plugin_name].dist_info | ||
|
||
|
||
# Something along these lines will probably be needed for validation using pydantic | ||
def overloaded_init_methods_for_plugin(_plugin_name: str) -> List[Callable]: | ||
return [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Raise a |
||
|
||
|
||
def all_plugin_names() -> List[str]: | ||
return list(_all_loaded_plugins) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must say: I wasn't aware of this, and not anything to do with the PR, but to skip plugins that starts with
Example
in the doc is quite hacky and magic 😋There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we (in a separate PR) can consider #381 and then remove
if not plugin_name.startswith("Example")
here afterwards?