orionis 0.657.0__py3-none-any.whl → 0.659.0__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.
- orionis/container/container.py +62 -57
- orionis/metadata/framework.py +1 -1
- {orionis-0.657.0.dist-info → orionis-0.659.0.dist-info}/METADATA +1 -1
- {orionis-0.657.0.dist-info → orionis-0.659.0.dist-info}/RECORD +7 -7
- {orionis-0.657.0.dist-info → orionis-0.659.0.dist-info}/WHEEL +0 -0
- {orionis-0.657.0.dist-info → orionis-0.659.0.dist-info}/licenses/LICENCE +0 -0
- {orionis-0.657.0.dist-info → orionis-0.659.0.dist-info}/top_level.txt +0 -0
orionis/container/container.py
CHANGED
|
@@ -3,7 +3,7 @@ import asyncio
|
|
|
3
3
|
import inspect
|
|
4
4
|
import threading
|
|
5
5
|
import typing
|
|
6
|
-
from typing import Any, Callable, Optional
|
|
6
|
+
from typing import Any, Callable, Optional, Union
|
|
7
7
|
from orionis.container.context.manager import ScopeManager
|
|
8
8
|
from orionis.container.context.scope import ScopedContext
|
|
9
9
|
from orionis.container.contracts.container import IContainer
|
|
@@ -11,11 +11,6 @@ from orionis.container.entities.binding import Binding
|
|
|
11
11
|
from orionis.container.enums.lifetimes import Lifetime
|
|
12
12
|
from orionis.container.exceptions import OrionisContainerException
|
|
13
13
|
from orionis.container.exceptions.container import OrionisContainerTypeError
|
|
14
|
-
from orionis.container.validators import (
|
|
15
|
-
IsCallable,
|
|
16
|
-
IsValidAlias,
|
|
17
|
-
LifetimeValidator
|
|
18
|
-
)
|
|
19
14
|
from orionis.services.introspection.abstract.reflection import ReflectionAbstract
|
|
20
15
|
from orionis.services.introspection.callables.reflection import ReflectionCallable
|
|
21
16
|
from orionis.services.introspection.concretes.reflection import ReflectionConcrete
|
|
@@ -35,7 +30,9 @@ class Container(IContainer):
|
|
|
35
30
|
# This lock ensures that only one thread can create or access instances at a time
|
|
36
31
|
_lock = threading.RLock() # RLock allows reentrant locking
|
|
37
32
|
|
|
38
|
-
def __new__(
|
|
33
|
+
def __new__(
|
|
34
|
+
cls
|
|
35
|
+
) -> 'Container':
|
|
39
36
|
"""
|
|
40
37
|
Creates and returns a singleton instance for each specific class.
|
|
41
38
|
|
|
@@ -79,7 +76,9 @@ class Container(IContainer):
|
|
|
79
76
|
# Return the newly created instance
|
|
80
77
|
return instance
|
|
81
78
|
|
|
82
|
-
def __init__(
|
|
79
|
+
def __init__(
|
|
80
|
+
self
|
|
81
|
+
) -> None:
|
|
83
82
|
"""
|
|
84
83
|
Initializes the internal state of the container instance.
|
|
85
84
|
|
|
@@ -113,7 +112,7 @@ class Container(IContainer):
|
|
|
113
112
|
self.__singleton_cache = {} # Caches singleton instances
|
|
114
113
|
|
|
115
114
|
# Mark this instance as initialized to prevent re-initialization
|
|
116
|
-
self.__initialized = True
|
|
115
|
+
self.__initialized = True # NOSONAR
|
|
117
116
|
|
|
118
117
|
def __handleSyncAsyncResult(
|
|
119
118
|
self,
|
|
@@ -445,6 +444,7 @@ class Container(IContainer):
|
|
|
445
444
|
|
|
446
445
|
# If an alias is provided, validate and use it directly
|
|
447
446
|
if alias:
|
|
447
|
+
|
|
448
448
|
# Check for None, empty string, or whitespace-only alias
|
|
449
449
|
if alias is None or alias == "" or str(alias).isspace():
|
|
450
450
|
raise OrionisContainerTypeError(
|
|
@@ -970,68 +970,76 @@ class Container(IContainer):
|
|
|
970
970
|
|
|
971
971
|
def callable(
|
|
972
972
|
self,
|
|
973
|
-
alias: str,
|
|
974
973
|
fn: Callable[..., Any],
|
|
975
974
|
*,
|
|
976
|
-
|
|
975
|
+
alias: str
|
|
977
976
|
) -> Optional[bool]:
|
|
978
977
|
"""
|
|
979
|
-
Registers a function or factory under a given alias.
|
|
978
|
+
Registers a function or factory under a given alias with transient lifetime.
|
|
979
|
+
|
|
980
|
+
This method registers a callable (function or factory) in the container and associates it with a unique alias.
|
|
981
|
+
The registered function will be resolved with transient lifetime, meaning a new result is produced each time it is invoked.
|
|
982
|
+
The alias is validated for uniqueness and correctness, and any previous registration under the same alias is removed.
|
|
980
983
|
|
|
981
984
|
Parameters
|
|
982
985
|
----------
|
|
983
|
-
alias : str
|
|
984
|
-
The alias to register the function under.
|
|
985
986
|
fn : Callable[..., Any]
|
|
986
|
-
The function or factory to register.
|
|
987
|
-
|
|
988
|
-
The
|
|
987
|
+
The function or factory to register. Must be a valid Python callable.
|
|
988
|
+
alias : str
|
|
989
|
+
The alias to register the function under. Must be a non-empty, valid string.
|
|
989
990
|
|
|
990
991
|
Returns
|
|
991
992
|
-------
|
|
992
|
-
bool
|
|
993
|
-
True if the function was registered successfully.
|
|
993
|
+
bool or None
|
|
994
|
+
Returns True if the function was registered successfully.
|
|
995
|
+
Returns None if registration fails due to an exception.
|
|
994
996
|
|
|
995
997
|
Raises
|
|
996
998
|
------
|
|
997
999
|
OrionisContainerTypeError
|
|
998
1000
|
If the alias is invalid or the function is not callable.
|
|
999
1001
|
OrionisContainerException
|
|
1000
|
-
If
|
|
1001
|
-
"""
|
|
1002
|
+
If an unexpected error occurs during registration.
|
|
1002
1003
|
|
|
1003
|
-
|
|
1004
|
-
|
|
1004
|
+
Notes
|
|
1005
|
+
-----
|
|
1006
|
+
- The function is registered with transient lifetime, so each invocation produces a new result.
|
|
1007
|
+
- If a service is already registered under the same alias, it is removed before registering the new function.
|
|
1008
|
+
- The alias is validated for uniqueness and correctness.
|
|
1009
|
+
"""
|
|
1005
1010
|
|
|
1006
|
-
|
|
1007
|
-
|
|
1011
|
+
try:
|
|
1012
|
+
# Validate and normalize the alias using the internal alias key generator
|
|
1013
|
+
alias = self.__makeAliasKey(lambda: None, alias)
|
|
1008
1014
|
|
|
1009
|
-
|
|
1010
|
-
|
|
1015
|
+
# Ensure the provided fn is actually callable
|
|
1016
|
+
if not callable(fn):
|
|
1017
|
+
raise OrionisContainerTypeError(
|
|
1018
|
+
f"Expected a callable type, but got {type(fn).__name__} instead."
|
|
1019
|
+
)
|
|
1011
1020
|
|
|
1012
|
-
|
|
1013
|
-
|
|
1021
|
+
# Remove any existing registration under this alias
|
|
1022
|
+
self.drop(None, alias)
|
|
1014
1023
|
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1024
|
+
# Register the function in the bindings dictionary with transient lifetime
|
|
1025
|
+
self.__bindings[alias] = Binding(
|
|
1026
|
+
function=fn,
|
|
1027
|
+
lifetime=Lifetime.TRANSIENT,
|
|
1028
|
+
alias=alias
|
|
1019
1029
|
)
|
|
1020
1030
|
|
|
1021
|
-
|
|
1022
|
-
|
|
1031
|
+
# Register the alias for lookup in the aliases dictionary
|
|
1032
|
+
self.__aliases[alias] = self.__bindings[alias]
|
|
1023
1033
|
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
function=fn,
|
|
1027
|
-
lifetime=lifetime,
|
|
1028
|
-
alias=alias
|
|
1029
|
-
)
|
|
1034
|
+
# Return True to indicate successful registration
|
|
1035
|
+
return True
|
|
1030
1036
|
|
|
1031
|
-
|
|
1032
|
-
self.__aliases[alias] = self.__bindings[alias]
|
|
1037
|
+
except Exception as e:
|
|
1033
1038
|
|
|
1034
|
-
|
|
1039
|
+
# Raise a container exception with details if registration fails
|
|
1040
|
+
raise OrionisContainerException(
|
|
1041
|
+
f"Unexpected error registering callable: {e}"
|
|
1042
|
+
) from e
|
|
1035
1043
|
|
|
1036
1044
|
def bound(
|
|
1037
1045
|
self,
|
|
@@ -1129,7 +1137,7 @@ class Container(IContainer):
|
|
|
1129
1137
|
# Return None if no binding is found for the requested abstract type or alias
|
|
1130
1138
|
return None
|
|
1131
1139
|
|
|
1132
|
-
def __validateBinding(
|
|
1140
|
+
def __validateBinding( # NOSONAR
|
|
1133
1141
|
self,
|
|
1134
1142
|
binding: Binding,
|
|
1135
1143
|
requested_key: Any
|
|
@@ -1205,7 +1213,7 @@ class Container(IContainer):
|
|
|
1205
1213
|
# Additional validations based on binding type
|
|
1206
1214
|
self.__validateBindingByType(binding, requested_key)
|
|
1207
1215
|
|
|
1208
|
-
def __validateBindingByType(
|
|
1216
|
+
def __validateBindingByType( # NOSONAR
|
|
1209
1217
|
self,
|
|
1210
1218
|
binding: Binding,
|
|
1211
1219
|
requested_key: Any
|
|
@@ -1272,7 +1280,7 @@ class Container(IContainer):
|
|
|
1272
1280
|
f"Invalid alias in binding for '{requested_key}': alias cannot be empty"
|
|
1273
1281
|
)
|
|
1274
1282
|
|
|
1275
|
-
def drop(
|
|
1283
|
+
def drop( # NOSONAR
|
|
1276
1284
|
self,
|
|
1277
1285
|
abstract: Callable[..., Any] = None,
|
|
1278
1286
|
alias: str = None
|
|
@@ -1888,7 +1896,8 @@ class Container(IContainer):
|
|
|
1888
1896
|
|
|
1889
1897
|
# If there are unresolved dependencies, raise an exception
|
|
1890
1898
|
if dependencies.unresolved:
|
|
1891
|
-
unresolved_args =
|
|
1899
|
+
unresolved_args = list(dependencies.unresolved.keys())
|
|
1900
|
+
|
|
1892
1901
|
raise OrionisContainerException(
|
|
1893
1902
|
f"Cannot invoke callable '{getattr(fn, '__name__', str(fn))}' because the following required arguments are missing: [{', '.join(unresolved_args)}]."
|
|
1894
1903
|
)
|
|
@@ -2046,7 +2055,8 @@ class Container(IContainer):
|
|
|
2046
2055
|
|
|
2047
2056
|
# Check for unresolved dependencies
|
|
2048
2057
|
if dependencies.unresolved:
|
|
2049
|
-
unresolved_args =
|
|
2058
|
+
unresolved_args = list(dependencies.unresolved.keys())
|
|
2059
|
+
|
|
2050
2060
|
raise OrionisContainerException(
|
|
2051
2061
|
f"Cannot resolve '{name}' because the following required arguments are missing: [{', '.join(unresolved_args)}]."
|
|
2052
2062
|
)
|
|
@@ -2070,7 +2080,7 @@ class Container(IContainer):
|
|
|
2070
2080
|
f"Error resolving dependencies for '{name}': {str(e)}"
|
|
2071
2081
|
) from e
|
|
2072
2082
|
|
|
2073
|
-
def __resolveSingleDependency(
|
|
2083
|
+
def __resolveSingleDependency( # NOSONAR
|
|
2074
2084
|
self,
|
|
2075
2085
|
name: str,
|
|
2076
2086
|
param_name: str,
|
|
@@ -2228,12 +2238,7 @@ class Container(IContainer):
|
|
|
2228
2238
|
try:
|
|
2229
2239
|
|
|
2230
2240
|
# If explicit arguments are provided, attempt direct instantiation or invocation
|
|
2231
|
-
if args or kwargs:
|
|
2232
|
-
if isinstance(type_, type):
|
|
2233
|
-
# Instantiate the class directly with provided arguments
|
|
2234
|
-
return type_(*args, **kwargs)
|
|
2235
|
-
elif callable(type_):
|
|
2236
|
-
# Invoke the callable directly with provided arguments
|
|
2241
|
+
if args or kwargs and callable(type_):
|
|
2237
2242
|
return type_(*args, **kwargs)
|
|
2238
2243
|
|
|
2239
2244
|
# Attempt auto-resolution for eligible types
|
|
@@ -2958,4 +2963,4 @@ class Container(IContainer):
|
|
|
2958
2963
|
except TypeError:
|
|
2959
2964
|
raise OrionisContainerException(
|
|
2960
2965
|
f"Failed to call method '{method.__name__}': {reflection_error}"
|
|
2961
|
-
) from reflection_error
|
|
2966
|
+
) from reflection_error
|
orionis/metadata/framework.py
CHANGED
|
@@ -67,7 +67,7 @@ orionis/console/stubs/listener.stub,sha256=DbX-ghx2-vb73kzQ6L20lyg5vSKn58jSLTwFu
|
|
|
67
67
|
orionis/console/tasks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
68
68
|
orionis/console/tasks/schedule.py,sha256=ZeeuQ9Tbu5KNowKC5oIk7yWeJXzlDQiQ278mWEgoCXc,87989
|
|
69
69
|
orionis/container/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
70
|
-
orionis/container/container.py,sha256=
|
|
70
|
+
orionis/container/container.py,sha256=oj6Wrm_3pY5fvgrXWoFAq8CUfbxHBpXBcauf6LzqZDU,114177
|
|
71
71
|
orionis/container/context/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
72
72
|
orionis/container/context/manager.py,sha256=I08K_jKXSKmrq18Pv33qYyMKIlAovVOwIgmfiVm-J7c,2971
|
|
73
73
|
orionis/container/context/scope.py,sha256=p_oCzR7dDz-5ZAd16ab4vfLc3gBf34CaN0f4iR9D0bQ,1155
|
|
@@ -217,7 +217,7 @@ orionis/foundation/providers/scheduler_provider.py,sha256=IrPQJwvQVLRm5Qnz0Cxon4
|
|
|
217
217
|
orionis/foundation/providers/testing_provider.py,sha256=eI1p2lUlxl25b5Z487O4nmqLE31CTDb4c3Q21xFadkE,1615
|
|
218
218
|
orionis/foundation/providers/workers_provider.py,sha256=GdHENYV_yGyqmHJHn0DCyWmWId5xWjD48e6Zq2PGCWY,1674
|
|
219
219
|
orionis/metadata/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
220
|
-
orionis/metadata/framework.py,sha256
|
|
220
|
+
orionis/metadata/framework.py,sha256=PyWuw6-moXHRfxXdES-vDFIuICRkDMY0mlXcYqm-b5E,4089
|
|
221
221
|
orionis/metadata/package.py,sha256=k7Yriyp5aUcR-iR8SK2ec_lf0_Cyc-C7JczgXa-I67w,16039
|
|
222
222
|
orionis/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
223
223
|
orionis/services/asynchrony/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -404,8 +404,8 @@ orionis/test/validators/workers.py,sha256=rWcdRexINNEmGaO7mnc1MKUxkHKxrTsVuHgbnI
|
|
|
404
404
|
orionis/test/view/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
405
405
|
orionis/test/view/render.py,sha256=R55ykeRs0wDKcdTf4O1YZ8GDHTFmJ0IK6VQkbJkYUvo,5571
|
|
406
406
|
orionis/test/view/report.stub,sha256=QLqqCdRoENr3ECiritRB3DO_MOjRQvgBh5jxZ3Hs1r0,28189
|
|
407
|
-
orionis-0.
|
|
408
|
-
orionis-0.
|
|
409
|
-
orionis-0.
|
|
410
|
-
orionis-0.
|
|
411
|
-
orionis-0.
|
|
407
|
+
orionis-0.659.0.dist-info/licenses/LICENCE,sha256=JhC-z_9mbpUrCfPjcl3DhDA8trNDMzb57cvRSam1avc,1463
|
|
408
|
+
orionis-0.659.0.dist-info/METADATA,sha256=JE66lCLtLLy1kspYW6VF2ufJMkC_TD-fMuvT9ywbC9g,4772
|
|
409
|
+
orionis-0.659.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
410
|
+
orionis-0.659.0.dist-info/top_level.txt,sha256=lyXi6jArpqJ-0zzNqd_uwsH-z9TCEBVBL-pC3Ekv7hU,8
|
|
411
|
+
orionis-0.659.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|