rats-apps 0.2.0.dev20240813083850__py3-none-any.whl → 0.2.0.dev20240816092449__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rats/annotations/_functions.py +5 -7
- rats/apps/__init__.py +3 -0
- rats/apps/_scoping.py +9 -13
- rats/apps/_static_container.py +29 -0
- {rats_apps-0.2.0.dev20240813083850.dist-info → rats_apps-0.2.0.dev20240816092449.dist-info}/METADATA +1 -1
- {rats_apps-0.2.0.dev20240813083850.dist-info → rats_apps-0.2.0.dev20240816092449.dist-info}/RECORD +8 -7
- {rats_apps-0.2.0.dev20240813083850.dist-info → rats_apps-0.2.0.dev20240816092449.dist-info}/WHEEL +0 -0
- {rats_apps-0.2.0.dev20240813083850.dist-info → rats_apps-0.2.0.dev20240816092449.dist-info}/entry_points.txt +0 -0
rats/annotations/_functions.py
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
from __future__ import annotations
|
2
|
-
|
3
1
|
from collections import defaultdict
|
4
2
|
from collections.abc import Callable
|
5
3
|
from functools import cache
|
@@ -30,14 +28,14 @@ class AnnotationsContainer(NamedTuple):
|
|
30
28
|
annotations: tuple[GroupAnnotations[Any], ...]
|
31
29
|
|
32
30
|
@staticmethod
|
33
|
-
def empty() -> AnnotationsContainer:
|
31
|
+
def empty() -> "AnnotationsContainer":
|
34
32
|
return AnnotationsContainer(annotations=())
|
35
33
|
|
36
34
|
def with_group(
|
37
35
|
self,
|
38
36
|
namespace: str,
|
39
37
|
group_id: NamedTuple,
|
40
|
-
) -> AnnotationsContainer:
|
38
|
+
) -> "AnnotationsContainer":
|
41
39
|
return AnnotationsContainer(
|
42
40
|
annotations=tuple(
|
43
41
|
[
|
@@ -52,7 +50,7 @@ class AnnotationsContainer(NamedTuple):
|
|
52
50
|
def with_namespace(
|
53
51
|
self,
|
54
52
|
namespace: str,
|
55
|
-
) -> AnnotationsContainer:
|
53
|
+
) -> "AnnotationsContainer":
|
56
54
|
return AnnotationsContainer(
|
57
55
|
annotations=tuple([x for x in self.annotations if x.namespace == namespace]),
|
58
56
|
)
|
@@ -64,7 +62,7 @@ class AnnotationsBuilder:
|
|
64
62
|
def __init__(self) -> None:
|
65
63
|
self._group_ids = defaultdict(set)
|
66
64
|
|
67
|
-
def add(self, namespace: str, group_id:
|
65
|
+
def add(self, namespace: str, group_id: NamedTuple) -> None:
|
68
66
|
self._group_ids[namespace].add(group_id)
|
69
67
|
|
70
68
|
def make(self, name: str) -> AnnotationsContainer:
|
@@ -83,7 +81,7 @@ DecoratorType = TypeVar("DecoratorType", bound=Callable[..., Any])
|
|
83
81
|
|
84
82
|
def annotation(
|
85
83
|
namespace: str,
|
86
|
-
group_id:
|
84
|
+
group_id: NamedTuple,
|
87
85
|
) -> Callable[[DecoratorType], DecoratorType]:
|
88
86
|
"""
|
89
87
|
Decorator to add an annotation to a function.
|
rats/apps/__init__.py
CHANGED
@@ -30,11 +30,14 @@ from ._plugins import PluginRunner
|
|
30
30
|
from ._runtimes import NullRuntime, Runtime
|
31
31
|
from ._scoping import autoscope
|
32
32
|
from ._simple_apps import AppServices, SimpleApplication, StandardRuntime
|
33
|
+
from ._static_container import StaticContainer, StaticProvider
|
33
34
|
|
34
35
|
__all__ = [
|
35
36
|
"App",
|
36
37
|
"CompositeContainer",
|
37
38
|
"Container",
|
39
|
+
"StaticContainer",
|
40
|
+
"StaticProvider",
|
38
41
|
"DuplicateServiceError",
|
39
42
|
"Executable",
|
40
43
|
"PluginContainers",
|
rats/apps/_scoping.py
CHANGED
@@ -1,30 +1,25 @@
|
|
1
1
|
from collections.abc import Callable
|
2
2
|
from types import FunctionType
|
3
|
-
from typing import Any, ParamSpec, TypeVar
|
3
|
+
from typing import Any, ParamSpec, TypeVar
|
4
4
|
|
5
5
|
from ._ids import ServiceId
|
6
6
|
|
7
|
-
T = TypeVar("T")
|
7
|
+
T = TypeVar("T", bound=type)
|
8
8
|
P = ParamSpec("P")
|
9
9
|
|
10
10
|
|
11
|
-
def autoscope(cls:
|
12
|
-
"""
|
13
|
-
Decorator that replaces all ServiceId instances in the class with scoped ServiceId instances.
|
11
|
+
def autoscope(cls: T) -> T:
|
12
|
+
"""Decorator to automatically scope ServiceId attributes in a class."""
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
"""
|
18
|
-
|
19
|
-
def wrap(func: Callable[..., Any]) -> Callable[..., Any]:
|
20
|
-
def wrapper(*args: P.args, **kwargs: P.kwargs) -> ServiceId[Any]:
|
14
|
+
def _wrap(func: Callable[P, Any]) -> Callable[P, Any]:
|
15
|
+
def _wrapper(*args: P.args, **kwargs: P.kwargs) -> ServiceId[Any]:
|
21
16
|
result = func(*args, **kwargs)
|
22
17
|
if not isinstance(result, ServiceId):
|
23
18
|
return result
|
24
19
|
|
25
20
|
return ServiceId[Any](scope_service_name(cls.__module__, cls.__name__, result.name))
|
26
21
|
|
27
|
-
return
|
22
|
+
return _wrapper
|
28
23
|
|
29
24
|
props = [prop for prop in dir(cls) if not prop.startswith("_")]
|
30
25
|
|
@@ -32,7 +27,7 @@ def autoscope(cls: type[T]) -> type[T]:
|
|
32
27
|
non_ns = getattr(cls, prop_name)
|
33
28
|
|
34
29
|
if isinstance(non_ns, FunctionType):
|
35
|
-
setattr(cls, prop_name,
|
30
|
+
setattr(cls, prop_name, _wrap(non_ns))
|
36
31
|
else:
|
37
32
|
if not isinstance(non_ns, ServiceId):
|
38
33
|
continue
|
@@ -44,4 +39,5 @@ def autoscope(cls: type[T]) -> type[T]:
|
|
44
39
|
|
45
40
|
|
46
41
|
def scope_service_name(module_name: str, cls_name: str, name: str) -> str:
|
42
|
+
"""Generate a ServiceId name based on an objects module and class name."""
|
47
43
|
return f"{module_name}:{cls_name}[{name}]"
|
@@ -0,0 +1,29 @@
|
|
1
|
+
from collections.abc import Callable, Iterator
|
2
|
+
from typing import Any, Generic
|
3
|
+
|
4
|
+
from typing_extensions import NamedTuple as ExtNamedTuple
|
5
|
+
|
6
|
+
from ._container import Container
|
7
|
+
from ._ids import ServiceId, T_ServiceType
|
8
|
+
|
9
|
+
|
10
|
+
class StaticProvider(ExtNamedTuple, Generic[T_ServiceType]):
|
11
|
+
namespace: str
|
12
|
+
service_id: ServiceId[T_ServiceType]
|
13
|
+
provider: Callable[[], T_ServiceType]
|
14
|
+
|
15
|
+
|
16
|
+
class StaticContainer(Container):
|
17
|
+
_providers: tuple[StaticProvider[Any], ...]
|
18
|
+
|
19
|
+
def __init__(self, *providers: StaticProvider[Any]) -> None:
|
20
|
+
self._providers = providers
|
21
|
+
|
22
|
+
def get_namespaced_group(
|
23
|
+
self,
|
24
|
+
namespace: str,
|
25
|
+
group_id: ServiceId[T_ServiceType],
|
26
|
+
) -> Iterator[T_ServiceType]:
|
27
|
+
for provider in self._providers:
|
28
|
+
if provider.namespace == namespace and provider.service_id == group_id:
|
29
|
+
yield provider.provider()
|
{rats_apps-0.2.0.dev20240813083850.dist-info → rats_apps-0.2.0.dev20240816092449.dist-info}/RECORD
RENAMED
@@ -1,8 +1,8 @@
|
|
1
1
|
rats/annotations/__init__.py,sha256=wsGhRQzZrV2oJTnBAX0aGgpyT1kYT235jkP3Wb8BTRY,498
|
2
2
|
rats/annotations/__main__.py,sha256=vlzQOM9y82P0OL5tYcmSM_4jTg0s8jayAcvEoi9cBvI,1065
|
3
|
-
rats/annotations/_functions.py,sha256=
|
3
|
+
rats/annotations/_functions.py,sha256=UkHh3zdBivluE7dBeGQ17zoIfGdyIokMAkFmpWaIlDc,4284
|
4
4
|
rats/annotations/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
|
-
rats/apps/__init__.py,sha256=
|
5
|
+
rats/apps/__init__.py,sha256=KtAsBY62BS5lYom6j5x69BDItfEYeOxu5EY0kbRWC0g,1601
|
6
6
|
rats/apps/__main__.py,sha256=KjdadN4rdP0xhWiLzdmtCsXejWx_gxOK-ah-L1r1dTI,1818
|
7
7
|
rats/apps/_annotations.py,sha256=yOf4MKFGQz3x4hpaWgMf2y2GlbXtbIh4uED15voXzyY,2566
|
8
8
|
rats/apps/_composite_container.py,sha256=s_of6NyyrjFVYWGVehyEHe9WJIPRCnbB-tyWyNF8zyc,585
|
@@ -13,8 +13,9 @@ rats/apps/_namespaces.py,sha256=THUV_Xj5PtweC23Ob-zsSpk8exC4fT-qRwjpQ6IDm0U,188
|
|
13
13
|
rats/apps/_plugin_container.py,sha256=wmaBgxmvKo82ue9CrKHRXafgik5wIXh8XkEYMfhcTjs,1530
|
14
14
|
rats/apps/_plugins.py,sha256=mvSYQPi11wTGZpM4umoyD37Rc8CQX8nt5eAJbmLrBFM,688
|
15
15
|
rats/apps/_runtimes.py,sha256=qKhsuaH3ZesSP4pGwRbS8zj2mwapysSxyS_F9pkUtM4,1738
|
16
|
-
rats/apps/_scoping.py,sha256=
|
16
|
+
rats/apps/_scoping.py,sha256=6C2-ID22cCPR9Cbexf3CvCF3o9F_7ieURbwqkf6DI68,1360
|
17
17
|
rats/apps/_simple_apps.py,sha256=n-3zeHY3iintZ9LN597c7zDHv3DiIdl7c8NTk0gUk1Y,5477
|
18
|
+
rats/apps/_static_container.py,sha256=5lzLh1CUoQVwhxfDhK6ZOQaBrPpudbRHWJkaDppphZo,881
|
18
19
|
rats/apps/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
19
20
|
rats/cli/__init__.py,sha256=_g9xWv6Uy73AudzCn-A9JKP-IpfZMRgvoO1b64dAxPw,464
|
20
21
|
rats/cli/__main__.py,sha256=3JZ7mrTTrrODQHutefm2zJp1-cQQB7I5-1xhYw7SMBU,1656
|
@@ -26,7 +27,7 @@ rats/cli/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
26
27
|
rats/logs/__init__.py,sha256=fCn4pfpYiAcTtt5CsnUZX68CjOB3KJHxMSiYxsma4qE,183
|
27
28
|
rats/logs/_plugin.py,sha256=eAAG4ci-XS9A9ituXj9PrcI6zH-xlCqhJlUbSGC-MYM,2175
|
28
29
|
rats/logs/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
29
|
-
rats_apps-0.2.0.
|
30
|
-
rats_apps-0.2.0.
|
31
|
-
rats_apps-0.2.0.
|
32
|
-
rats_apps-0.2.0.
|
30
|
+
rats_apps-0.2.0.dev20240816092449.dist-info/METADATA,sha256=wK_sezpSv7sGI7qxpyNQ_u1V8u9aAKO6IWqGEhdSj-0,774
|
31
|
+
rats_apps-0.2.0.dev20240816092449.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
32
|
+
rats_apps-0.2.0.dev20240816092449.dist-info/entry_points.txt,sha256=9oOvf2loQr5ACWQgvuu9Q3KZIVIxKE5Aa-rLuUII5WQ,91
|
33
|
+
rats_apps-0.2.0.dev20240816092449.dist-info/RECORD,,
|
{rats_apps-0.2.0.dev20240813083850.dist-info → rats_apps-0.2.0.dev20240816092449.dist-info}/WHEEL
RENAMED
File without changes
|
File without changes
|