Skip to content

Commit

Permalink
Add plugin registration init method
Browse files Browse the repository at this point in the history
  • Loading branch information
devinrsmith committed Jan 12, 2022
1 parent 1d80d1c commit 3ad011b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ where=src

[options.entry_points]
console_scripts =
deephaven-plugin-list-registrations = deephaven.plugin:list_registrations
deephaven-plugin-list-plugins = deephaven.plugin:list_plugins
deephaven-plugin-list-registrations = deephaven.plugin:list_registrations_console
deephaven-plugin-list-plugins = deephaven.plugin:list_plugins_console
26 changes: 26 additions & 0 deletions src/deephaven/plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class Callback(abc.ABC):
def register(self, plugin: Union[Plugin, Type[Plugin]]) -> None:
pass

@classmethod
@abc.abstractmethod
def init(cls) -> None:
pass

@classmethod
@abc.abstractmethod
def register_into(cls, callback: Callback) -> None:
Expand Down Expand Up @@ -50,6 +55,11 @@ def collect_registration_classes():
return [e.load() for e in collect_registration_entrypoints()]


def initialize_all():
for registration_cls in collect_registration_classes():
registration_cls.init()


def register_all_into(callback: Registration.Callback):
for registration_cls in collect_registration_classes():
registration_cls.register_into(callback)
Expand All @@ -69,3 +79,19 @@ def list_plugins():
plugins = registration_cls.collect_plugins()
output += ''.join([f'\n {plugin}' for plugin in plugins])
print(output)


def list_registrations_console():
"""
Entrypoint for the console script deephaven-plugin-list-registrations
"""
# note: don't need to initialize the registrations unless registering into
list_registrations()


def list_plugins_console():
"""
Entrypoint for the console script deephaven-plugin-list-plugins
"""
initialize_all()
list_plugins()

0 comments on commit 3ad011b

Please sign in to comment.