Skip to content

Commit

Permalink
Updated Exporter, bump type
Browse files Browse the repository at this point in the history
  • Loading branch information
devinrsmith committed Jan 14, 2022
1 parent d6a686d commit 6793ee1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/deephaven/plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import abc
from typing import Union, Type

__version__ = '0.0.1.dev2'
__version__ = '0.0.1.dev3'

DEEPHAVEN_PLUGIN_ENTRY_KEY = 'deephaven.plugin'
DEEPHAVEN_PLUGIN_REGISTRATION_CLASS = 'registration_cls'
Expand Down
56 changes: 28 additions & 28 deletions src/deephaven/plugin/object/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,6 @@
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, index: int, type: Optional[str], ticket: bytes):
self._index = index
Expand All @@ -48,11 +25,10 @@ def ticket(self) -> bytes:

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

@abc.abstractmethod
def new_reference(self, object) -> Reference:
def reference(self,
object,
allow_unknown_type: bool = False,
force_new: bool = False) -> Optional[Reference]:
pass


Expand All @@ -69,3 +45,27 @@ def is_type(self, object) -> bool:
@abc.abstractmethod
def to_bytes(self, exporter: Exporter, object) -> bytes:
pass


def find_object_type(object) -> Optional[ObjectType]:
class Visitor(Registration.Callback):
def __init__(self) -> None:
self._found = None

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):
if plugin.is_type(object):
self._found = plugin

@property
def found(self) -> Optional[ObjectType]:
return self._found
visitor = Visitor()
register_all_into(visitor)
return visitor.found

0 comments on commit 6793ee1

Please sign in to comment.