orionis 0.436.0__py3-none-any.whl → 0.438.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.
Files changed (68) hide show
  1. orionis/console/contracts/kernel.py +16 -3
  2. orionis/console/dumper/contracts/dump.py +8 -9
  3. orionis/console/dynamic/progress_bar.py +21 -29
  4. orionis/console/output/console.py +12 -0
  5. orionis/container/context/manager.py +27 -17
  6. orionis/container/context/scope.py +8 -7
  7. orionis/container/contracts/service_provider.py +12 -8
  8. orionis/container/providers/service_provider.py +9 -16
  9. orionis/container/resolver/resolver.py +29 -22
  10. orionis/foundation/contracts/application.py +437 -47
  11. orionis/foundation/contracts/config.py +14 -6
  12. orionis/foundation/providers/console_provider.py +16 -15
  13. orionis/foundation/providers/dumper_provider.py +20 -8
  14. orionis/foundation/providers/logger_provider.py +19 -14
  15. orionis/foundation/providers/path_resolver_provider.py +17 -14
  16. orionis/foundation/providers/progress_bar_provider.py +15 -14
  17. orionis/foundation/providers/testing_provider.py +20 -14
  18. orionis/foundation/providers/workers_provider.py +19 -14
  19. orionis/metadata/framework.py +1 -1
  20. orionis/services/asynchrony/contracts/coroutines.py +1 -0
  21. orionis/services/asynchrony/coroutines.py +2 -0
  22. orionis/services/asynchrony/exceptions/exception.py +2 -0
  23. orionis/services/environment/core/dot_env.py +9 -0
  24. orionis/services/environment/dynamic/caster.py +31 -2
  25. orionis/services/environment/key/key_generator.py +1 -0
  26. orionis/services/environment/validators/key_name.py +1 -0
  27. orionis/services/environment/validators/types.py +5 -1
  28. orionis/services/introspection/abstract/contracts/reflection.py +188 -221
  29. orionis/services/introspection/abstract/reflection.py +311 -178
  30. orionis/services/introspection/callables/contracts/reflection.py +64 -21
  31. orionis/services/introspection/callables/reflection.py +98 -23
  32. orionis/services/introspection/concretes/reflection.py +278 -181
  33. orionis/services/introspection/dependencies/contracts/reflection.py +21 -18
  34. orionis/services/introspection/dependencies/entities/callable_dependencies.py +15 -16
  35. orionis/services/introspection/dependencies/entities/class_dependencies.py +24 -16
  36. orionis/services/introspection/dependencies/entities/known_dependencies.py +19 -13
  37. orionis/services/introspection/dependencies/entities/method_dependencies.py +22 -16
  38. orionis/services/introspection/dependencies/reflection.py +0 -3
  39. orionis/services/introspection/instances/reflection.py +16 -6
  40. orionis/services/log/contracts/log_service.py +4 -0
  41. orionis/services/log/handlers/filename.py +2 -0
  42. orionis/services/paths/contracts/resolver.py +0 -3
  43. orionis/services/paths/resolver.py +0 -3
  44. {orionis-0.436.0.dist-info → orionis-0.438.0.dist-info}/METADATA +1 -1
  45. {orionis-0.436.0.dist-info → orionis-0.438.0.dist-info}/RECORD +68 -67
  46. tests/container/core/__init__.py +0 -0
  47. tests/container/mocks/mock_complex_classes.py +502 -192
  48. tests/container/mocks/mock_simple_classes.py +72 -6
  49. tests/container/validators/test_is_valid_alias.py +1 -1
  50. tests/foundation/config/database/test_foundation_config_database.py +54 -28
  51. tests/foundation/config/filesystems/test_foundation_config_filesystems_aws.py +40 -22
  52. tests/foundation/config/filesystems/test_foundation_config_filesystems_public.py +75 -48
  53. tests/foundation/config/logging/test_foundation_config_logging_channels.py +49 -37
  54. tests/foundation/config/logging/test_foundation_config_logging_monthly.py +80 -42
  55. tests/foundation/config/logging/test_foundation_config_logging_stack.py +46 -22
  56. tests/foundation/config/root/test_foundation_config_root_paths.py +37 -44
  57. tests/foundation/config/session/test_foundation_config_session.py +65 -20
  58. tests/foundation/config/startup/test_foundation_config_startup.py +37 -33
  59. tests/services/introspection/dependencies/test_reflect_dependencies.py +77 -25
  60. tests/services/introspection/reflection/test_reflection_abstract.py +403 -47
  61. /orionis/services/introspection/concretes/contracts/{concrete.py → reflection.py} +0 -0
  62. {orionis-0.436.0.dist-info → orionis-0.438.0.dist-info}/WHEEL +0 -0
  63. {orionis-0.436.0.dist-info → orionis-0.438.0.dist-info}/licenses/LICENCE +0 -0
  64. {orionis-0.436.0.dist-info → orionis-0.438.0.dist-info}/top_level.txt +0 -0
  65. {orionis-0.436.0.dist-info → orionis-0.438.0.dist-info}/zip-safe +0 -0
  66. /tests/container/{test_container.py → core/test_container.py} +0 -0
  67. /tests/container/{test_singleton.py → core/test_singleton.py} +0 -0
  68. /tests/container/{test_thread_safety.py → core/test_thread_safety.py} +0 -0
@@ -1,11 +1,19 @@
1
1
  from abc import ABC, abstractmethod
2
2
 
3
3
  class IReflectionCallable(ABC):
4
+ """
5
+ Abstract base class defining the interface for callable reflection operations.
6
+
7
+ This interface provides methods to introspect and manipulate callable objects,
8
+ including functions, methods, and lambdas. It enables reflection capabilities
9
+ such as source code retrieval, dependency analysis, and runtime execution.
10
+ """
4
11
 
5
12
  @abstractmethod
6
13
  def getCallable(self) -> callable:
7
14
  """
8
15
  Retrieve the callable function associated with this instance.
16
+
9
17
  Returns
10
18
  -------
11
19
  callable
@@ -16,17 +24,20 @@ class IReflectionCallable(ABC):
16
24
  @abstractmethod
17
25
  def getName(self) -> str:
18
26
  """
27
+ Get the name of the callable function.
28
+
19
29
  Returns
20
30
  -------
21
31
  str
22
- The name of the function.
32
+ The name of the function as defined in its declaration.
23
33
  """
24
34
  pass
25
35
 
26
36
  @abstractmethod
27
37
  def getModuleName(self) -> str:
28
38
  """
29
- Get the name of the module where the underlying function is defined.
39
+ Get the name of the module where the callable is defined.
40
+
30
41
  Returns
31
42
  -------
32
43
  str
@@ -37,11 +48,16 @@ class IReflectionCallable(ABC):
37
48
  @abstractmethod
38
49
  def getModuleWithCallableName(self) -> str:
39
50
  """
40
- Get the fully qualified name of the callable, including its module.
51
+ Get the fully qualified name of the callable.
52
+
53
+ Combines the module name and callable name to create a complete
54
+ identifier for the function.
55
+
41
56
  Returns
42
57
  -------
43
58
  str
44
- A string consisting of the module name and the callable name, separated by a dot.
59
+ A string consisting of the module name and the callable name,
60
+ separated by a dot (e.g., 'module.function').
45
61
  """
46
62
  pass
47
63
 
@@ -49,10 +65,12 @@ class IReflectionCallable(ABC):
49
65
  def getDocstring(self) -> str:
50
66
  """
51
67
  Retrieve the docstring of the callable function.
68
+
52
69
  Returns
53
70
  -------
54
71
  str
55
- The docstring associated with the function. Returns an empty string if no docstring is present.
72
+ The docstring associated with the function. Returns an empty
73
+ string if no docstring is present.
56
74
  """
57
75
  pass
58
76
 
@@ -60,48 +78,58 @@ class IReflectionCallable(ABC):
60
78
  def getSourceCode(self) -> str:
61
79
  """
62
80
  Retrieve the source code of the wrapped callable.
81
+
63
82
  Returns
64
83
  -------
65
84
  str
66
- The source code of the callable function as a string. If the source code
67
- cannot be retrieved, a ReflectionAttributeError is raised.
85
+ The source code of the callable function as a string.
86
+
68
87
  Raises
69
88
  ------
70
89
  ReflectionAttributeError
71
- If the source code cannot be obtained due to an OSError.
90
+ If the source code cannot be obtained due to an OSError or
91
+ if the callable is built-in without accessible source.
72
92
  """
73
93
  pass
74
94
 
75
95
  @abstractmethod
76
96
  def getFile(self) -> str:
77
97
  """
78
- Retrieve the filename where the underlying callable function is defined.
98
+ Retrieve the filename where the callable is defined.
99
+
79
100
  Returns
80
101
  -------
81
102
  str
82
103
  The absolute path to the source file containing the callable.
104
+
83
105
  Raises
84
106
  ------
85
107
  TypeError
86
- If the underlying object is a built-in function or method, or if its source file cannot be determined.
108
+ If the underlying object is a built-in function or method,
109
+ or if its source file cannot be determined.
87
110
  """
88
111
  pass
89
112
 
90
113
  @abstractmethod
91
114
  def call(self, *args, **kwargs):
92
115
  """
93
- Call the wrapped function with the provided arguments.
94
- If the wrapped function is asynchronous, it will be executed using `asyncio.run`.
116
+ Execute the wrapped function with the provided arguments.
117
+
118
+ Handles both synchronous and asynchronous callables, automatically
119
+ running coroutines when necessary.
120
+
95
121
  Parameters
96
122
  ----------
97
123
  *args : tuple
98
124
  Positional arguments to pass to the function.
99
125
  **kwargs : dict
100
126
  Keyword arguments to pass to the function.
127
+
101
128
  Returns
102
129
  -------
103
130
  Any
104
131
  The result returned by the function call.
132
+
105
133
  Raises
106
134
  ------
107
135
  Exception
@@ -113,29 +141,44 @@ class IReflectionCallable(ABC):
113
141
  def getSignature(self):
114
142
  """
115
143
  Retrieve the signature of the callable function.
144
+
116
145
  Returns
117
146
  -------
118
147
  inspect.Signature
119
- An `inspect.Signature` object representing the callable's signature.
148
+ An `inspect.Signature` object representing the callable's signature,
149
+ including parameter names, default values, and type annotations.
150
+
120
151
  Notes
121
152
  -----
122
153
  This method provides detailed information about the parameters of the callable,
123
- including their names, default values, and annotations.
154
+ enabling runtime inspection and validation of function arguments.
124
155
  """
125
156
  pass
126
157
 
127
158
  @abstractmethod
128
159
  def getDependencies(self):
129
160
  """
130
- Analyzes the callable associated with this instance and retrieves its dependencies.
161
+ Analyze the callable and retrieve its dependency information.
162
+
163
+ Examines the callable's parameters to determine which dependencies
164
+ can be resolved (have default values or type annotations) and which
165
+ remain unresolved.
166
+
167
+ Returns
168
+ -------
131
169
  CallableDependency
132
- An object containing information about the callable's dependencies, including:
133
- - resolved: dict
134
- A dictionary mapping parameter names to their resolved values (e.g., default values or injected dependencies).
135
- - unresolved: list of str
136
- A list of parameter names that could not be resolved (i.e., parameters without default values or missing annotations).
170
+ An object containing information about the callable's dependencies:
171
+ - resolved : dict
172
+ A dictionary mapping parameter names to their resolved values
173
+ (e.g., default values or injected dependencies).
174
+ - unresolved : list of str
175
+ A list of parameter names that could not be resolved
176
+ (parameters without default values or missing annotations).
177
+
137
178
  Notes
138
179
  -----
139
- This method leverages the `ReflectDependencies` utility to inspect the callable and determine which dependencies are satisfied and which remain unresolved.
180
+ This method leverages the `ReflectDependencies` utility to inspect
181
+ the callable and determine which dependencies are satisfied and
182
+ which remain unresolved for dependency injection purposes.
140
183
  """
141
184
  pass
@@ -9,29 +9,60 @@ from orionis.services.introspection.exceptions import (
9
9
  )
10
10
 
11
11
  class ReflectionCallable(IReflectionCallable):
12
+ """
13
+ Concrete implementation of callable reflection operations.
14
+
15
+ This class provides comprehensive introspection capabilities for callable objects,
16
+ including functions, methods, and lambdas. It enables runtime analysis of callable
17
+ properties, dependency injection, and execution management for both synchronous
18
+ and asynchronous callables.
19
+
20
+ Parameters
21
+ ----------
22
+ fn : callable
23
+ The function, method, or lambda to be wrapped for reflection operations.
24
+
25
+ Raises
26
+ ------
27
+ ReflectionTypeError
28
+ If `fn` is not a function, method, or lambda with the required attributes.
29
+ """
12
30
 
13
31
  def __init__(self, fn: callable) -> None:
14
32
  """
33
+ Initialize the reflection wrapper with a callable object.
34
+
35
+ Validates that the provided object is a valid callable (function, method,
36
+ or lambda) and stores it for reflection operations.
37
+
15
38
  Parameters
16
39
  ----------
17
40
  fn : callable
18
41
  The function, method, or lambda to be wrapped.
42
+
19
43
  Raises
20
44
  ------
21
45
  ReflectionTypeError
22
46
  If `fn` is not a function, method, or lambda.
47
+
23
48
  Notes
24
49
  -----
25
- This constructor initializes the ReflectionCallable with the provided callable object.
26
- It ensures that the input is a valid function, method, or lambda, and raises an error otherwise.
50
+ This constructor performs type validation to ensure that only valid
51
+ callable objects are wrapped. Built-in functions and objects without
52
+ the `__code__` attribute are rejected.
27
53
  """
54
+
55
+ # Validate that the input is a proper callable with introspectable attributes
28
56
  if not (inspect.isfunction(fn) or inspect.ismethod(fn) or (callable(fn) and hasattr(fn, "__code__"))):
29
57
  raise ReflectionTypeError(f"Expected a function, method, or lambda, got {type(fn).__name__}")
58
+
59
+ # Store the callable for reflection operations
30
60
  self.__function = fn
31
61
 
32
62
  def getCallable(self) -> callable:
33
63
  """
34
64
  Retrieve the callable function associated with this instance.
65
+
35
66
  Returns
36
67
  -------
37
68
  callable
@@ -41,16 +72,19 @@ class ReflectionCallable(IReflectionCallable):
41
72
 
42
73
  def getName(self) -> str:
43
74
  """
75
+ Get the name of the callable function.
76
+
44
77
  Returns
45
78
  -------
46
79
  str
47
- The name of the function.
80
+ The name of the function as defined in its declaration.
48
81
  """
49
82
  return self.__function.__name__
50
83
 
51
84
  def getModuleName(self) -> str:
52
85
  """
53
- Get the name of the module where the underlying function is defined.
86
+ Get the name of the module where the callable is defined.
87
+
54
88
  Returns
55
89
  -------
56
90
  str
@@ -60,104 +94,145 @@ class ReflectionCallable(IReflectionCallable):
60
94
 
61
95
  def getModuleWithCallableName(self) -> str:
62
96
  """
63
- Get the fully qualified name of the callable, including its module.
97
+ Get the fully qualified name of the callable.
98
+
99
+ Combines the module name and callable name to create a complete
100
+ identifier for the function.
101
+
64
102
  Returns
65
103
  -------
66
104
  str
67
- A string consisting of the module name and the callable name, separated by a dot.
105
+ A string consisting of the module name and the callable name,
106
+ separated by a dot (e.g., 'module.function').
68
107
  """
69
108
  return f"{self.getModuleName()}.{self.getName()}"
70
109
 
71
110
  def getDocstring(self) -> str:
72
111
  """
73
112
  Retrieve the docstring of the callable function.
113
+
74
114
  Returns
75
115
  -------
76
116
  str
77
- The docstring associated with the function. Returns an empty string if no docstring is present.
117
+ The docstring associated with the function. Returns an empty
118
+ string if no docstring is present.
78
119
  """
79
120
  return self.__function.__doc__ or ""
80
121
 
81
122
  def getSourceCode(self) -> str:
82
123
  """
83
124
  Retrieve the source code of the wrapped callable.
125
+
126
+ Uses Python's inspect module to extract the complete source code
127
+ of the callable function from its definition file.
128
+
84
129
  Returns
85
130
  -------
86
131
  str
87
- The source code of the callable function as a string. If the source code
88
- cannot be retrieved, a ReflectionAttributeError is raised.
132
+ The source code of the callable function as a string.
133
+
89
134
  Raises
90
135
  ------
91
136
  ReflectionAttributeError
92
- If the source code cannot be obtained due to an OSError.
137
+ If the source code cannot be obtained due to an OSError or
138
+ if the callable is built-in without accessible source.
93
139
  """
94
140
  try:
95
141
  return inspect.getsource(self.__function)
96
142
  except OSError as e:
143
+ # Re-raise as a more specific reflection error for better error handling
97
144
  raise ReflectionAttributeError(f"Could not retrieve source code: {e}")
98
145
 
99
146
  def getFile(self) -> str:
100
147
  """
101
- Retrieve the filename where the underlying callable function is defined.
148
+ Retrieve the filename where the callable is defined.
149
+
102
150
  Returns
103
151
  -------
104
152
  str
105
153
  The absolute path to the source file containing the callable.
154
+
106
155
  Raises
107
156
  ------
108
157
  TypeError
109
- If the underlying object is a built-in function or method, or if its source file cannot be determined.
158
+ If the underlying object is a built-in function or method,
159
+ or if its source file cannot be determined.
110
160
  """
111
161
  return inspect.getfile(self.__function)
112
162
 
113
163
  def call(self, *args, **kwargs):
114
164
  """
115
- Call the wrapped function with the provided arguments.
116
- If the wrapped function is asynchronous, it will be executed using `asyncio.run`.
165
+ Execute the wrapped function with the provided arguments.
166
+
167
+ Automatically detects whether the callable is synchronous or asynchronous
168
+ and handles execution appropriately. For coroutine functions, uses the
169
+ Coroutine wrapper to manage async execution.
170
+
117
171
  Parameters
118
172
  ----------
119
173
  *args : tuple
120
174
  Positional arguments to pass to the function.
121
175
  **kwargs : dict
122
176
  Keyword arguments to pass to the function.
177
+
123
178
  Returns
124
179
  -------
125
180
  Any
126
181
  The result returned by the function call.
182
+
127
183
  Raises
128
184
  ------
129
185
  Exception
130
186
  Propagates any exception raised by the called function.
131
187
  """
188
+
189
+ # Check if the function is a coroutine and handle async execution
132
190
  if inspect.iscoroutinefunction(self.__function):
133
191
  return Coroutine(self.__function(*args, **kwargs)).run()
192
+
193
+ # For regular functions, call directly
134
194
  return self.__function(*args, **kwargs)
135
195
 
136
196
  def getSignature(self) -> inspect.Signature:
137
197
  """
138
198
  Retrieve the signature of the callable function.
199
+
139
200
  Returns
140
201
  -------
141
202
  inspect.Signature
142
- An `inspect.Signature` object representing the callable's signature.
203
+ An `inspect.Signature` object representing the callable's signature,
204
+ including parameter names, default values, and type annotations.
205
+
143
206
  Notes
144
207
  -----
145
208
  This method provides detailed information about the parameters of the callable,
146
- including their names, default values, and annotations.
209
+ enabling runtime inspection and validation of function arguments.
147
210
  """
148
211
  return inspect.signature(self.__function)
149
212
 
150
213
  def getDependencies(self) -> CallableDependency:
151
214
  """
152
- Analyzes the callable associated with this instance and retrieves its dependencies.
215
+ Analyze the callable and retrieve its dependency information.
216
+
217
+ Examines the callable's parameters to determine which dependencies
218
+ can be resolved (have default values or type annotations) and which
219
+ remain unresolved for dependency injection purposes.
220
+
221
+ Returns
222
+ -------
153
223
  CallableDependency
154
- An object containing information about the callable's dependencies, including:
155
- - resolved: dict
156
- A dictionary mapping parameter names to their resolved values (e.g., default values or injected dependencies).
157
- - unresolved: list of str
158
- A list of parameter names that could not be resolved (i.e., parameters without default values or missing annotations).
224
+ An object containing information about the callable's dependencies:
225
+ - resolved : dict
226
+ A dictionary mapping parameter names to their resolved values
227
+ (e.g., default values or injected dependencies).
228
+ - unresolved : list of str
229
+ A list of parameter names that could not be resolved
230
+ (parameters without default values or missing annotations).
231
+
159
232
  Notes
160
233
  -----
161
- This method leverages the `ReflectDependencies` utility to inspect the callable and determine which dependencies are satisfied and which remain unresolved.
234
+ This method leverages the `ReflectDependencies` utility to inspect
235
+ the callable and determine which dependencies are satisfied and
236
+ which remain unresolved for dependency injection purposes.
162
237
  """
163
238
  return ReflectDependencies().getCallableDependencies(self.__function)