rats-apps 0.2.0.dev20240904170114__py3-none-any.whl → 0.2.0.dev20240906121056__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/apps/__init__.py +4 -0
- rats/apps/_annotations.py +54 -1
- {rats_apps-0.2.0.dev20240904170114.dist-info → rats_apps-0.2.0.dev20240906121056.dist-info}/METADATA +1 -1
- {rats_apps-0.2.0.dev20240904170114.dist-info → rats_apps-0.2.0.dev20240906121056.dist-info}/RECORD +6 -6
- {rats_apps-0.2.0.dev20240904170114.dist-info → rats_apps-0.2.0.dev20240906121056.dist-info}/WHEEL +0 -0
- {rats_apps-0.2.0.dev20240904170114.dist-info → rats_apps-0.2.0.dev20240906121056.dist-info}/entry_points.txt +0 -0
rats/apps/__init__.py
CHANGED
@@ -7,7 +7,9 @@ domain.
|
|
7
7
|
|
8
8
|
from ._annotations import (
|
9
9
|
autoid,
|
10
|
+
autoid_factory_service,
|
10
11
|
autoid_service,
|
12
|
+
factory_service,
|
11
13
|
fallback_group,
|
12
14
|
fallback_service,
|
13
15
|
group,
|
@@ -63,4 +65,6 @@ __all__ = [
|
|
63
65
|
"StandardRuntime",
|
64
66
|
"StandardRuntime",
|
65
67
|
"SimpleApplication",
|
68
|
+
"factory_service",
|
69
|
+
"autoid_factory_service",
|
66
70
|
]
|
rats/apps/_annotations.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
from collections.abc import Callable
|
2
|
-
from typing import Any, NamedTuple, ParamSpec, cast
|
2
|
+
from typing import Any, Concatenate, Generic, NamedTuple, ParamSpec, TypeVar, cast
|
3
3
|
|
4
4
|
from rats import annotations
|
5
5
|
|
@@ -8,6 +8,8 @@ from ._namespaces import ProviderNamespaces
|
|
8
8
|
from ._scoping import scope_service_name
|
9
9
|
|
10
10
|
P = ParamSpec("P")
|
11
|
+
R = TypeVar("R")
|
12
|
+
T_Container = TypeVar("T_Container")
|
11
13
|
|
12
14
|
|
13
15
|
def service(
|
@@ -49,6 +51,57 @@ def fallback_group(
|
|
49
51
|
)
|
50
52
|
|
51
53
|
|
54
|
+
def _factory_to_factory_provider(
|
55
|
+
method: Callable[Concatenate[T_Container, P], R],
|
56
|
+
) -> Callable[[T_Container], Callable[P, R]]:
|
57
|
+
"""Convert a factory method a factory provider method returning the original method."""
|
58
|
+
|
59
|
+
def new_method(self: T_Container) -> Callable[P, R]:
|
60
|
+
def factory(*args: P.args, **kwargs: P.kwargs) -> R:
|
61
|
+
return method(self, *args, **kwargs)
|
62
|
+
|
63
|
+
return factory
|
64
|
+
|
65
|
+
new_method.__name__ = method.__name__
|
66
|
+
new_method.__module__ = method.__module__
|
67
|
+
new_method.__qualname__ = method.__qualname__
|
68
|
+
new_method.__doc__ = method.__doc__
|
69
|
+
return new_method
|
70
|
+
|
71
|
+
|
72
|
+
class factory_service(Generic[P, R]):
|
73
|
+
"""
|
74
|
+
A decorator to create a factory service.
|
75
|
+
|
76
|
+
Decorate a method that takes any number of arguments and returns an object. The resulting
|
77
|
+
service will be that factory - taking the same arguments and returning a new object each time.
|
78
|
+
"""
|
79
|
+
|
80
|
+
_service_id: ServiceId[Callable[P, R]]
|
81
|
+
|
82
|
+
def __init__(self, service_id: ServiceId[Callable[P, R]]) -> None:
|
83
|
+
self._service_id = service_id
|
84
|
+
|
85
|
+
def __call__(
|
86
|
+
self, method: Callable[Concatenate[T_Container, P], R]
|
87
|
+
) -> Callable[[T_Container], Callable[P, R]]:
|
88
|
+
new_method = _factory_to_factory_provider(method)
|
89
|
+
return service(self._service_id)(new_method)
|
90
|
+
|
91
|
+
|
92
|
+
def autoid_factory_service(
|
93
|
+
method: Callable[Concatenate[T_Container, P], R],
|
94
|
+
) -> Callable[[T_Container], Callable[P, R]]:
|
95
|
+
"""
|
96
|
+
A decorator to create a factory service, with an automatically generated service id.
|
97
|
+
|
98
|
+
Decorate a method that takes any number of arguments and returns an object. The resulting
|
99
|
+
service will be that factory - taking the same arguments and returning a new object each time.
|
100
|
+
"""
|
101
|
+
new_method = _factory_to_factory_provider(method)
|
102
|
+
return autoid_service(new_method)
|
103
|
+
|
104
|
+
|
52
105
|
def autoid(method: Callable[..., T_ServiceType]) -> ServiceId[T_ServiceType]:
|
53
106
|
"""
|
54
107
|
Get a service id for a method.
|
{rats_apps-0.2.0.dev20240904170114.dist-info → rats_apps-0.2.0.dev20240906121056.dist-info}/RECORD
RENAMED
@@ -2,9 +2,9 @@ rats/annotations/__init__.py,sha256=wsGhRQzZrV2oJTnBAX0aGgpyT1kYT235jkP3Wb8BTRY,
|
|
2
2
|
rats/annotations/__main__.py,sha256=vlzQOM9y82P0OL5tYcmSM_4jTg0s8jayAcvEoi9cBvI,1065
|
3
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=SlqFKChSf661J6nlcuSGNQO-fLceqZrwOGn1YoyYDzs,1703
|
6
6
|
rats/apps/__main__.py,sha256=KjdadN4rdP0xhWiLzdmtCsXejWx_gxOK-ah-L1r1dTI,1818
|
7
|
-
rats/apps/_annotations.py,sha256=
|
7
|
+
rats/apps/_annotations.py,sha256=tCa7_IzGBBbR827O3UpYBI-lCAnhj6yM9wxUeSYcXG4,4487
|
8
8
|
rats/apps/_composite_container.py,sha256=s_of6NyyrjFVYWGVehyEHe9WJIPRCnbB-tyWyNF8zyc,585
|
9
9
|
rats/apps/_container.py,sha256=rLUPnsDfLR26YjFUGGu3YYpqIta1l0q8p077Hzfflwo,5989
|
10
10
|
rats/apps/_executables.py,sha256=QJ5_UPdZPmDQ1a3cLRJDUoeUMzNMwa3ZHYhYeS3AVq4,971
|
@@ -27,7 +27,7 @@ rats/cli/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
27
27
|
rats/logs/__init__.py,sha256=fCn4pfpYiAcTtt5CsnUZX68CjOB3KJHxMSiYxsma4qE,183
|
28
28
|
rats/logs/_plugin.py,sha256=eAAG4ci-XS9A9ituXj9PrcI6zH-xlCqhJlUbSGC-MYM,2175
|
29
29
|
rats/logs/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
30
|
-
rats_apps-0.2.0.
|
31
|
-
rats_apps-0.2.0.
|
32
|
-
rats_apps-0.2.0.
|
33
|
-
rats_apps-0.2.0.
|
30
|
+
rats_apps-0.2.0.dev20240906121056.dist-info/METADATA,sha256=urdUHZ3l3yfAf5zCFP8iTFUeLO4Gyi-f9YbcOiPFwyQ,774
|
31
|
+
rats_apps-0.2.0.dev20240906121056.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
32
|
+
rats_apps-0.2.0.dev20240906121056.dist-info/entry_points.txt,sha256=9oOvf2loQr5ACWQgvuu9Q3KZIVIxKE5Aa-rLuUII5WQ,91
|
33
|
+
rats_apps-0.2.0.dev20240906121056.dist-info/RECORD,,
|
{rats_apps-0.2.0.dev20240904170114.dist-info → rats_apps-0.2.0.dev20240906121056.dist-info}/WHEEL
RENAMED
File without changes
|
File without changes
|