Skip to content

Commit

Permalink
Updated reference, added object type plugin checking
Browse files Browse the repository at this point in the history
  • Loading branch information
devinrsmith committed Jan 13, 2022
1 parent 3ad011b commit d6a686d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 18 deletions.
12 changes: 0 additions & 12 deletions src/deephaven/plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ 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 @@ -55,11 +50,6 @@ 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 @@ -85,13 +75,11 @@ 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()
50 changes: 44 additions & 6 deletions src/deephaven/plugin/object/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,58 @@
import abc
from typing import Optional, Union, Type

from .. import Plugin
from .. import Plugin, Registration, register_all_into


def has_object_type_plugin(object) -> bool:
class IsObjectType(Registration.Callback):
def __init__(self) -> None:
self._found = False

def register(self, plugin: Union[Plugin, Type[Plugin]]) -> None:
if self._found:
return
if isinstance(plugin, type):
if not issubclass(plugin, ObjectType):
return
plugin = plugin()
if isinstance(plugin, ObjectType):
self._found = plugin.is_type(object)

@property
def found(self) -> bool:
return self._found
visitor = IsObjectType()
register_all_into(visitor)
return visitor.found


class Reference:
def __init__(self, id: bytes):
self._id = id
def __init__(self, index: int, type: Optional[str], ticket: bytes):
self._index = index
self._type = type
self._ticket = ticket

@property
def id(self) -> bytes:
return self._id
def index(self) -> int:
return self._index

@property
def type(self) -> Optional[str]:
return self._type

@property
def ticket(self) -> bytes:
return self._ticket


class Exporter(abc.ABC):
@abc.abstractmethod
def new_server_side_reference(self, object) -> Reference:
def reference(self, object) -> Reference:
pass

@abc.abstractmethod
def new_reference(self, object) -> Reference:
pass


Expand Down

0 comments on commit d6a686d

Please sign in to comment.