-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
50 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
from . import utils | ||
from .viewer import * | ||
from .conversion import register_converter, get_converter | ||
from .conversion import register_converter, get_converter | ||
from .plugins import register_plugins | ||
|
||
|
||
register_plugins() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import importlib | ||
|
||
from importlib_metadata import entry_points | ||
|
||
registered_plugins = [] | ||
|
||
|
||
def register_plugins(): | ||
"""Register a plugin.""" | ||
# Find all plugins that defined an entry point | ||
discovered_plugins = entry_points(group="octarine.plugins") | ||
|
||
# Go over each of the plugins | ||
for plugin in discovered_plugins: | ||
# Import the module | ||
try: | ||
module = importlib.import_module(plugin.module) | ||
except BaseException as e: | ||
print(f"Error importing plugin {plugin.name}: {e}") | ||
continue | ||
|
||
# Get the function to register the plugin | ||
register_func = getattr(module, plugin.value.split(":")[-1], None) | ||
|
||
# If the function is not found, print an error | ||
if register_func is None: | ||
print( | ||
f"Registration function {plugin.value.split(':')[-1]} not found for plugin {plugin.name}." | ||
) | ||
continue | ||
|
||
# Otherwise, register the plugin | ||
try: | ||
register_func() | ||
except BaseException as e: | ||
print(f"Error registering plugin {plugin.name}: {e}") | ||
|
||
# Add the plugin to the list of registered plugins | ||
registered_plugins.append(plugin.name) | ||
|
||
|
||
register_plugins() |