Skip to content

Commit

Permalink
UI descriptions (can this be deleted?)
Browse files Browse the repository at this point in the history
  • Loading branch information
sveinugu committed Dec 10, 2024
1 parent 6b3e368 commit 3dee800
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pydantic-core = "^2.24.2"
aiohttp = "^3.10.6"
aiohttp-retry = "^2.9.0"
aiolimiter = "^1.1.0"
tabulate = "^0.9.0"

[tool.poetry.group.dev.dependencies]
deepdiff = "^6.2.1"
Expand Down
16 changes: 16 additions & 0 deletions src/omnipy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
__version__ = '0.18.0'

import importlib
import os

from omnipy.api.enums import (BackoffStrategy,
Expand Down Expand Up @@ -172,6 +173,7 @@
rename_col_names,
transpose_columns_with_data_files)
from omnipy.util.contexts import print_exception
from omnipy.util.helpers import recursive_module_import

ROOT_DIR = os.path.dirname(os.path.abspath(__file__))

Expand Down Expand Up @@ -354,3 +356,17 @@
'transpose_columns_with_data_files',
'print_exception',
]


def __getattr__(attr_name: str) -> object:
omnipy = importlib.import_module(__name__)
all_modules = []
recursive_module_import(omnipy, all_modules)
print(all_modules)


#
#
# print(__file__)
# print(__name__)
# print(list(globals().keys()))
9 changes: 9 additions & 0 deletions src/omnipy/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import tarfile
from typing import Any, Callable, cast, Generic, Iterator, TYPE_CHECKING

from tabulate import tabulate
from typing_extensions import TypeVar

from omnipy.api.typedefs import TypeForm
Expand Down Expand Up @@ -705,6 +706,14 @@ def __eq__(self, other: object) -> bool:
def __repr_args__(self):
return [(k, v.contents) if is_model_instance(v) else (k, v) for k, v in self.data.items()]

def __repr__(self):
return tabulate(
((k, type(v).__name__, len(v) if hasattr(v, '__len__') else 'N/A')
for k, v in self.items()),
('Data file name', 'Type', 'Length'),
tablefmt='rounded_outline',
)


class MultiModelDataset(Dataset[GeneralModelT], Generic[GeneralModelT]):
"""
Expand Down
13 changes: 12 additions & 1 deletion src/omnipy/data/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
Optional,
Union)

from devtools import debug
from tabulate import tabulate
from typing_extensions import get_original_bases, TypeVar

from omnipy.api.protocols.private.util import IsSnapshotWrapper
Expand Down Expand Up @@ -772,7 +774,8 @@ def _check_for_root_key(self) -> None:
'\t"class MyNumberList(Model[list[int]]): ..."')

def __setattr__(self, attr: str, value: Any) -> None:
if attr in ['__module__'] + list(self.__dict__.keys()) and attr not in [ROOT_KEY]:
if attr in ['__module__'] + list(
self.__dict__.keys()) and attr not in [ROOT_KEY] or attr in ['__repr__']:
super().__setattr__(attr, value)
else:
match (attr):
Expand Down Expand Up @@ -1185,3 +1188,11 @@ def __call__(self, *args: object, **kwargs: object) -> object:

def __repr_args__(self):
return [(None, self.contents)]

def __str__(self):
return tabulate(
((self.__class__.__name__, ''), ('Raw file preview', 'Data structure'),
(str(self.to_data()), debug.format(self))),
maxcolwidths=[(40, 40)],
tablefmt='rounded_outline',
)

0 comments on commit 3dee800

Please sign in to comment.