Skip to content

Commit

Permalink
Tmp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sveinugu committed May 16, 2024
1 parent 9315ad8 commit 8c66d89
Show file tree
Hide file tree
Showing 26 changed files with 1,274 additions and 920 deletions.
794 changes: 50 additions & 744 deletions docs/notebooks/isa_json_data_wrangling_example.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ objsize = "^0.7.0"
humanize = "^4.9.0"
httpx = "^0.26.0"
pydantic = {version = "<2", extras = ["email"]}
bidict = "^0.23.1"

[tool.poetry.group.dev.dependencies]
deepdiff = "^6.2.1"
Expand Down
24 changes: 24 additions & 0 deletions src/omnipy/api/protocols/private/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from typing import Protocol

from omnipy.api.protocols.public.config import IsDataConfig


class IsDataConfigHolder(Protocol):
""""""
@property
def config(self) -> IsDataConfig:
...

def set_config(self, config: IsDataConfig) -> None:
...


class IsDataClassBase(Protocol):
""""""
@property
def _data_class_creator(self) -> IsDataConfigHolder:
...

@property
def config(self) -> IsDataConfig:
...
10 changes: 9 additions & 1 deletion src/omnipy/api/protocols/private/util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import Callable, Protocol, runtime_checkable
from typing import Callable, Protocol, runtime_checkable, TypeVar

from omnipy.api.typedefs import DecoratorClassT

_ContentT = TypeVar("_ContentT", covariant=True, bound=object)


@runtime_checkable
class IsCallableParamAfterSelf(Protocol):
Expand All @@ -15,3 +17,9 @@ class IsCallableClass(Protocol[DecoratorClassT]):
""""""
def __call__(self, *args: object, **kwargs: object) -> Callable[[Callable], DecoratorClassT]:
...


class HasContents(Protocol[_ContentT]):
@property
def contents(self) -> _ContentT:
...
1 change: 1 addition & 0 deletions src/omnipy/api/protocols/public/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class IsJobConfig(Protocol):
class IsDataConfig(Protocol):
""""""
interactive_mode: bool
dynamically_convert_elements_to_models: bool
terminal_size_columns: int
terminal_size_lines: int

Expand Down
8 changes: 7 additions & 1 deletion src/omnipy/api/protocols/public/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from omnipy.api.enums import EngineChoice
from omnipy.api.protocols.private.compute.job_creator import IsJobConfigHolder
from omnipy.api.protocols.private.data import IsDataConfigHolder
from omnipy.api.protocols.private.engine import IsEngine
from omnipy.api.protocols.private.log import IsRunStateRegistry
from omnipy.api.protocols.public.config import (IsDataConfig,
Expand Down Expand Up @@ -41,16 +42,20 @@ def __init__(
engine: EngineChoice = EngineChoice.LOCAL, # noqa
local: IsLocalRunnerConfig | None = None, # noqa
prefect: IsPrefectEngineConfig | None = None, # noqa
root_log: 'IsRootLogConfigEntryPublisher | None' = None, # noqa
root_log: IsRootLogConfig | None = None, # noqa
*args: object,
**kwargs: object) -> None:
...

def reset_to_defaults(self):
...


class IsRuntimeObjects(Protocol):
""""""

job_creator: IsJobConfigHolder
data_class_creator: IsDataConfigHolder
local: IsEngine
prefect: IsEngine
registry: IsRunStateRegistry
Expand All @@ -61,6 +66,7 @@ class IsRuntimeObjects(Protocol):
def __init__(
self,
job_creator: IsJobConfigHolder | None = None, # noqa
data_class_creator: IsDataConfigHolder | None = None, # noqa
local: IsEngine | None = None, # noqa
prefect: IsEngine | None = None, # noqa
registry: IsRunStateRegistry | None = None, # noqa
Expand Down
1 change: 1 addition & 0 deletions src/omnipy/config/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
@dataclass
class DataConfig:
interactive_mode: bool = True
dynamically_convert_elements_to_models: bool = False
terminal_size_columns: int = _terminal_size.columns
terminal_size_lines: int = _terminal_size.lines
2 changes: 1 addition & 1 deletion src/omnipy/config/root_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


def _get_log_dir_path() -> str:
return str(Path.cwd().joinpath(Path('logs')))
return str(Path.cwd() / 'logs')


@dataclass
Expand Down
36 changes: 36 additions & 0 deletions src/omnipy/data/data_class_creator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from abc import ABCMeta

from omnipy.api.protocols.private.data import IsDataConfigHolder
from omnipy.api.protocols.public.config import IsDataConfig
from omnipy.config.data import DataConfig


class DataClassCreator:
def __init__(self) -> None:
self._config: IsDataConfig = DataConfig()

def set_config(self, config: IsDataConfig) -> None:
self._config = config

@property
def config(self) -> IsDataConfig:
return self._config


class DataClassBaseMeta(ABCMeta):
""""""
_data_class_creator_obj = DataClassCreator()

@property
def data_class_creator(self) -> IsDataConfigHolder:
return self._data_class_creator_obj


class DataClassBase(metaclass=DataClassBaseMeta):
@property
def _data_class_creator(self) -> IsDataConfigHolder:
return self.__class__.data_class_creator

@property
def config(self) -> IsDataConfig:
return self.__class__.data_class_creator.config
11 changes: 8 additions & 3 deletions src/omnipy/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
from pydantic import Field, PrivateAttr, root_validator, ValidationError
from pydantic.fields import ModelField, Undefined, UndefinedType
from pydantic.generics import GenericModel
from pydantic.main import ModelMetaclass
from pydantic.utils import lenient_isinstance, lenient_issubclass

from omnipy.data.data_class_creator import DataClassBase, DataClassBaseMeta
from omnipy.data.model import (_cleanup_name_qualname_and_module,
_is_interactive_mode,
_waiting_for_terminal_repr,
DataWithParams,
INTERACTIVE_MODULES,
Expand Down Expand Up @@ -56,7 +57,11 @@
# BaseModel.copy()


class Dataset(GenericModel, Generic[ModelT], UserDict):
class _DatasetMetaclass(ModelMetaclass, DataClassBaseMeta):
...


class Dataset(GenericModel, Generic[ModelT], UserDict, DataClassBase, metaclass=_DatasetMetaclass):
"""
Dict-based container of data files that follow a specific Model
Expand Down Expand Up @@ -538,7 +543,7 @@ def __repr_args__(self):
return [(k, v.contents) for k, v in self.data.items()]

def __repr__(self):
if _is_interactive_mode() and not _waiting_for_terminal_repr():
if self.config.interactive_mode and not _waiting_for_terminal_repr():
if get_calling_module_name() in INTERACTIVE_MODULES:
_waiting_for_terminal_repr(True)
return self._table_repr()
Expand Down
Loading

0 comments on commit 8c66d89

Please sign in to comment.