Skip to content

Commit

Permalink
Harmonised serializer_registry init
Browse files Browse the repository at this point in the history
  • Loading branch information
sveinugu committed Jan 5, 2024
1 parent fd60c6c commit 9151f9d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
15 changes: 2 additions & 13 deletions src/omnipy/compute/mixins/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,16 @@
from omnipy.compute.mixins.name import NameJobBaseMixin
from omnipy.config.job import JobConfig
from omnipy.data.dataset import Dataset
from omnipy.data.serializer import SerializerRegistry
from omnipy.modules import register_serializers
from omnipy.modules import get_serializer_registry

PersistOpts = PersistOutputsOptions
RestoreOpts = RestoreOutputsOptions
ProtocolOpts = OutputStorageProtocolOptions


def _setup_serializer_registry() -> IsSerializerRegistry:
from omnipy.hub.runtime import runtime
if runtime is not None:
return runtime.objects.serializers
else:
registry = SerializerRegistry()
register_serializers(registry)
return registry


class SerializerFuncJobBaseMixin:

_serializer_registry: IsSerializerRegistry = _setup_serializer_registry()
_serializer_registry: IsSerializerRegistry = get_serializer_registry()

def __init__(self,
*,
Expand Down
10 changes: 2 additions & 8 deletions src/omnipy/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,8 @@ def load(self, tar_gz_file_path: str):

@staticmethod
def _get_serializer_registry():
from omnipy.data.serializer import SerializerRegistry
from omnipy.hub.runtime import runtime
from omnipy.modules import register_serializers
serializer_registry = SerializerRegistry() if runtime is None else \
runtime.objects.serializers
if len(serializer_registry.serializers) == 0:
register_serializers(serializer_registry)
return serializer_registry
from omnipy.modules import get_serializer_registry
return get_serializer_registry

def as_multi_model_dataset(self) -> 'MultiModelDataset[ModelT]':
multi_model_dataset = MultiModelDataset[self.get_model_class()]()
Expand Down
11 changes: 11 additions & 0 deletions src/omnipy/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,16 @@ def register_serializers(registry: IsSerializerRegistry):
registry.register(PandasDatasetToTarFileSerializer)


def get_serializer_registry():
from omnipy.data.serializer import SerializerRegistry
from omnipy.hub.runtime import runtime

serializer_registry = SerializerRegistry() if runtime is None else \
runtime.objects.serializers
if len(serializer_registry.serializers) == 0:
register_serializers(serializer_registry)
return serializer_registry


# TODO: Add module with helper classes/functions/takss to make it simpler to contact REST apis
# Augmentation service should have some attempts at this.

0 comments on commit 9151f9d

Please sign in to comment.