Skip to content

Commit

Permalink
Start of code reorganisation. Unsure what the plan was, but it was at…
Browse files Browse the repository at this point in the history
… least related to organisation of the code to allow two types if reference documentation, one for primarily users of the library, and one for library developers.
  • Loading branch information
sveinugu committed Dec 10, 2024
1 parent 6b3e368 commit 626acee
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/omnipy/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .enums import * # noqa: F401, F403
from .exceptions import * # noqa: F401, F403
from .protocols import * # noqa: F401, F403
from .typedefs import * # noqa: F401, F403
11 changes: 11 additions & 0 deletions src/omnipy/api/enums.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
from enum import Enum, IntEnum

__all__ = [
'PersistOutputsOptions',
'RestoreOutputsOptions',
'OutputStorageProtocolOptions',
'ConfigPersistOutputsOptions',
'ConfigRestoreOutputsOptions',
'ConfigOutputStorageProtocolOptions',
'EngineChoice',
'RunState',
]


class PersistOutputsOptions(str, Enum):
""""""
Expand Down
2 changes: 2 additions & 0 deletions src/omnipy/api/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import omnipy.util.pydantic as pyd

__all__ = ['JobStateException']


class JobStateException(Exception):
...
Expand Down
1 change: 1 addition & 0 deletions src/omnipy/api/protocols/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .public import * # noqa: F401, F403
4 changes: 4 additions & 0 deletions src/omnipy/api/protocols/public/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .compute import * # noqa: F401, F403
from .config import * # noqa: F401, F403
from .engine import * # noqa: F401, F403
from .hub import * # noqa: F401, F403
4 changes: 4 additions & 0 deletions src/omnipy/api/protocols/public/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
IsTaskTemplateArgsJob,
IsTaskTemplateArgsJobTemplate)
from omnipy.api.protocols.private.compute.mixins import IsNestedContext
from omnipy.util.decorators import export

__all__ = []

CallP = ParamSpec('CallP')
RetT = TypeVar('RetT')
RetCovT = TypeVar('RetCovT', covariant=True)


@export
class IsTaskTemplate(IsFuncArgJobTemplate['IsTaskTemplate[CallP, RetT]',
'IsTask[CallP, RetT]',
CallP,
Expand Down
2 changes: 2 additions & 0 deletions src/omnipy/api/typedefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from typing import _UnionGenericAlias # type: ignore[attr-defined]
from typing import _SpecialForm, Callable, ForwardRef, TypeAlias, TypeVar

__all__: list[str] = []

GeneralDecorator = Callable[[Callable], Callable]
LocaleType: TypeAlias = str | tuple[str | None, str | None]

Expand Down
17 changes: 17 additions & 0 deletions src/omnipy/util/decorators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from contextlib import AbstractContextManager
import inspect
from typing import Any, Callable, Concatenate, ContextManager, Generic, ParamSpec, TypeVar

_DecoratedP = ParamSpec('_DecoratedP')
Expand Down Expand Up @@ -108,3 +109,19 @@ def __call__(self, arg: _ArgT) -> _ArgT:
return method(self._calling_obj_or_cls, arg)

return SuperCaller


"""
Simple decorator for self-registering classes and functions as exported (in `__all__`).
Adapted from https://stackoverflow.com/a/35710527
"""


def export(cls_or_fn):
module = inspect.getmodule(cls_or_fn)
if hasattr(module, '__all__'):
module.__all__.append(cls_or_fn.__name__)
else:
module.__all__ = [cls_or_fn.__name__]
return cls_or_fn

0 comments on commit 626acee

Please sign in to comment.