orionis 0.691.0__py3-none-any.whl → 0.692.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.
@@ -6,7 +6,7 @@
6
6
  NAME = "orionis"
7
7
 
8
8
  # Current version of the framework
9
- VERSION = "0.691.0"
9
+ VERSION = "0.692.0"
10
10
 
11
11
  # Full name of the author or maintainer of the project
12
12
  AUTHOR = "Raul Mauricio Uñate Castro"
@@ -1,5 +1,5 @@
1
- from abc import ABC, abstractmethod
2
1
  import asyncio
2
+ from abc import ABC, abstractmethod
3
3
  from typing import TypeVar, Union
4
4
 
5
5
  T = TypeVar("T")
@@ -9,11 +9,12 @@ class ICoroutine(ABC):
9
9
  @abstractmethod
10
10
  def invoke(self, *args, **kwargs) -> Union[T, asyncio.Task, None]:
11
11
  """
12
- Invoke the callable coroutine function with the provided arguments.
12
+ Invokes the wrapped coroutine or callable function with the provided arguments.
13
13
 
14
- This method executes a callable coroutine function or regular function with the given
15
- arguments and keyword arguments. It automatically detects the execution context and
16
- handles both synchronous and asynchronous execution appropriately.
14
+ This method determines whether the target is a coroutine or a regular callable,
15
+ and executes it accordingly. It adapts to the current event loop context,
16
+ handling both synchronous and asynchronous execution. Exceptions are wrapped
17
+ with context information for easier debugging.
17
18
 
18
19
  Parameters
19
20
  ----------
@@ -25,9 +26,8 @@ class ICoroutine(ABC):
25
26
  Returns
26
27
  -------
27
28
  Union[T, asyncio.Task, None]
28
- - T: The result of the coroutine if executed synchronously
29
- - asyncio.Task: A task object if scheduled for asynchronous execution
30
- - None: If the callable is not a coroutine function
29
+ The result of the coroutine if executed synchronously, an asyncio.Task if scheduled
30
+ for asynchronous execution, or None if the callable is not a coroutine function.
31
31
 
32
32
  Raises
33
33
  ------
@@ -38,18 +38,12 @@ class ICoroutine(ABC):
38
38
 
39
39
  Notes
40
40
  -----
41
- - Only callable objects can be invoked with this method
42
- - For coroutine functions, execution context is automatically detected
43
- - Non-coroutine callables are executed directly and return None
44
- - Exceptions are wrapped with appropriate context information
45
-
46
- Examples
47
- --------
48
- >>> async def my_coro(x, y):
49
- ... return x + y
50
- >>> coro = Coroutine(my_coro)
51
- >>> result = coro.invoke(1, 2) # Returns Task or result depending on context
41
+ - Only callable objects can be invoked with this method.
42
+ - For coroutine functions, execution context is automatically detected.
43
+ - Non-coroutine callables are executed directly and return None.
44
+ - Exceptions are wrapped with appropriate context information.
52
45
  """
46
+ # This method should be implemented by subclasses to handle invocation logic.
53
47
  pass
54
48
 
55
49
  @abstractmethod
@@ -57,10 +51,16 @@ class ICoroutine(ABC):
57
51
  """
58
52
  Executes the wrapped coroutine, adapting to the current event loop context.
59
53
 
54
+ This method determines whether to execute the coroutine synchronously or schedule it
55
+ asynchronously based on the presence of an active event loop. It ensures that the coroutine
56
+ is executed in the most appropriate manner for the current context, handling event loop
57
+ issues gracefully.
58
+
60
59
  Returns
61
60
  -------
62
- T or asyncio.Future
63
- The result of the coroutine if executed synchronously, or an asyncio.Future if scheduled asynchronously.
61
+ Union[T, asyncio.Future]
62
+ The result of the coroutine if executed synchronously, or an asyncio.Future if scheduled
63
+ for asynchronous execution.
64
64
 
65
65
  Raises
66
66
  ------
@@ -69,8 +69,9 @@ class ICoroutine(ABC):
69
69
 
70
70
  Notes
71
71
  -----
72
- - If called outside an active event loop, the coroutine is executed synchronously and its result is returned.
73
- - If called within an active event loop, the coroutine is scheduled for asynchronous execution and a Future is returned.
74
- - The method automatically detects the execution context and chooses the appropriate execution strategy.
72
+ - Executes synchronously if called outside an active event loop and returns the result.
73
+ - Schedules asynchronously if called within an active event loop and returns a Future.
74
+ - Automatically detects the execution context and chooses the appropriate strategy.
75
75
  """
76
+ # This method should be implemented by subclasses to handle coroutine execution logic.
76
77
  pass
@@ -10,28 +10,25 @@ class Coroutine(ICoroutine):
10
10
 
11
11
  def __init__(self, func: Union[TypingCoroutine[Any, Any, T], Callable[..., TypingCoroutine[Any, Any, T]]]) -> None:
12
12
  """
13
- Initialize a Coroutine wrapper for managing and executing coroutine objects.
13
+ Initializes a Coroutine wrapper to manage and execute coroutine objects or functions.
14
14
 
15
- This constructor accepts either a coroutine object directly or a callable that
16
- returns a coroutine when invoked. The wrapped coroutine can later be executed
17
- using the run() method with automatic context detection.
15
+ This constructor accepts either a coroutine object or a callable that returns a coroutine.
16
+ The wrapped coroutine or function can be executed later using the run() or invoke() methods.
18
17
 
19
18
  Parameters
20
19
  ----------
21
20
  func : Union[TypingCoroutine[Any, Any, T], Callable[..., TypingCoroutine[Any, Any, T]]]
22
- The coroutine object to be wrapped and managed, or a callable that returns
23
- a coroutine. This will be stored internally for later execution.
21
+ The coroutine object or a callable that returns a coroutine to be managed.
24
22
 
25
23
  Returns
26
24
  -------
27
25
  None
28
- This is a constructor method and does not return any value.
26
+ This method does not return any value.
29
27
 
30
28
  Notes
31
29
  -----
32
- - The coroutine type validation is performed during execution in the run() method,
33
- not during initialization.
34
- - Both coroutine objects and coroutine functions are accepted as valid input.
30
+ - Type validation is deferred until execution.
31
+ - Accepts both coroutine objects and coroutine functions.
35
32
  """
36
33
 
37
34
  # Store the coroutine object or callable for later execution
@@ -39,11 +36,12 @@ class Coroutine(ICoroutine):
39
36
 
40
37
  def invoke(self, *args, **kwargs) -> Union[T, asyncio.Task, None]:
41
38
  """
42
- Invoke the callable coroutine function with the provided arguments.
39
+ Invokes the callable coroutine function or regular function with the provided arguments.
43
40
 
44
- This method executes a callable coroutine function or regular function with the given
45
- arguments and keyword arguments. It automatically detects the execution context and
46
- handles both synchronous and asynchronous execution appropriately.
41
+ This method executes a callable coroutine function or a regular function using the given
42
+ positional and keyword arguments. It automatically detects whether the function is asynchronous
43
+ and adapts execution to the current event loop context. Exceptions are handled and wrapped
44
+ appropriately.
47
45
 
48
46
  Parameters
49
47
  ----------
@@ -55,77 +53,67 @@ class Coroutine(ICoroutine):
55
53
  Returns
56
54
  -------
57
55
  Union[T, asyncio.Task, None]
58
- - T: The result of the coroutine if executed synchronously
59
- - asyncio.Task: A task object if scheduled for asynchronous execution
60
- - None: If the callable is not a coroutine function
56
+ The result of the coroutine if executed synchronously,
57
+ an asyncio.Task if scheduled for asynchronous execution,
58
+ or the result of a regular callable.
61
59
 
62
60
  Raises
63
61
  ------
64
62
  OrionisCoroutineException
65
63
  If an error occurs during coroutine execution.
66
64
  RuntimeError
67
- If an error occurs during callable execution that is not coroutine-related.
65
+ If an unexpected error occurs during callable execution.
68
66
 
69
67
  Notes
70
68
  -----
71
- - Only callable objects can be invoked with this method
72
- - For coroutine functions, execution context is automatically detected
73
- - Non-coroutine callables are executed directly and return None
74
- - Exceptions are wrapped with appropriate context information
75
-
76
- Examples
77
- --------
78
- >>> async def my_coro(x, y):
79
- ... return x + y
80
- >>> coro = Coroutine(my_coro)
81
- >>> result = coro.invoke(1, 2) # Returns Task or result depending on context
69
+ - Only callable objects can be invoked with this method.
70
+ - For coroutine functions, execution context is automatically detected.
71
+ - Non-coroutine callables are executed directly.
72
+ - Exceptions are wrapped with appropriate context information.
82
73
  """
74
+
75
+ # Ensure the stored object is callable before invocation
83
76
  if not callable(self.__func):
84
77
  raise OrionisCoroutineException(
85
78
  f"Cannot invoke non-callable object of type {type(self.__func).__name__}"
86
79
  )
87
80
 
88
81
  try:
89
-
90
82
  # Check if the callable is a coroutine function
91
83
  if asyncio.iscoroutinefunction(self.__func):
92
84
 
93
- # Create the coroutine object
85
+ # Create the coroutine object using provided arguments
94
86
  coroutine_obj = self.__func(*args, **kwargs)
95
87
 
96
88
  try:
97
-
98
- # Check if we're inside a running event loop
89
+ # Attempt to get the currently running event loop
99
90
  loop = asyncio.get_running_loop()
91
+
92
+ # Schedule the coroutine for asynchronous execution and return the Task
100
93
  return loop.create_task(coroutine_obj)
101
94
 
102
95
  except RuntimeError:
96
+ # No running event loop; execute the coroutine synchronously
103
97
 
104
- # No running event loop, execute synchronously
105
98
  try:
106
-
107
99
  # Use asyncio.run to execute the coroutine and return its result
108
100
  return asyncio.run(coroutine_obj)
109
101
 
110
102
  except Exception as e:
111
-
112
- # Wrap and raise any exceptions that occur during execution
103
+ # Wrap and raise any exceptions that occur during synchronous execution
113
104
  raise OrionisCoroutineException(
114
105
  f"Failed to execute coroutine synchronously: {str(e)}"
115
106
  ) from e
116
107
 
117
108
  else:
118
-
119
- # Execute regular callable directly
109
+ # Execute regular callable directly and return its result
120
110
  return self.__func(*args, **kwargs)
121
111
 
122
112
  except OrionisCoroutineException:
123
-
124
- # Re-raise our custom exceptions as-is
113
+ # Re-raise custom exceptions as-is
125
114
  raise
126
115
 
127
116
  except Exception as e:
128
-
129
117
  # Wrap and raise any other exceptions that occur during invocation
130
118
  raise RuntimeError(
131
119
  f"Unexpected error during callable invocation: {str(e)}"
@@ -133,15 +121,22 @@ class Coroutine(ICoroutine):
133
121
 
134
122
  def run(self) -> Union[T, asyncio.Future]:
135
123
  """
136
- Executes the wrapped coroutine, adapting to the current event loop context.
124
+ Executes the wrapped coroutine, adapting execution to the current event loop context.
125
+
126
+ This method determines whether to execute the coroutine synchronously or schedule it
127
+ for asynchronous execution based on the presence of an active event loop. It validates
128
+ that the stored object is a coroutine before execution.
137
129
 
138
130
  Returns
139
131
  -------
140
- T or asyncio.Future
141
- The result of the coroutine if executed synchronously, or an asyncio.Future if scheduled asynchronously.
132
+ Union[T, asyncio.Future]
133
+ The result of the coroutine if executed synchronously, or an asyncio.Future if scheduled
134
+ for asynchronous execution.
142
135
 
143
136
  Raises
144
137
  ------
138
+ OrionisCoroutineException
139
+ If the stored object is not a coroutine.
145
140
  RuntimeError
146
141
  If the coroutine cannot be executed due to event loop issues.
147
142
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: orionis
3
- Version: 0.691.0
3
+ Version: 0.692.0
4
4
  Summary: Orionis Framework – Elegant, Fast, and Powerful.
5
5
  Home-page: https://github.com/orionis-framework/framework
6
6
  Author: Raul Mauricio Uñate Castro
@@ -207,13 +207,13 @@ orionis/foundation/providers/scheduler_provider.py,sha256=IrPQJwvQVLRm5Qnz0Cxon4
207
207
  orionis/foundation/providers/testing_provider.py,sha256=eI1p2lUlxl25b5Z487O4nmqLE31CTDb4c3Q21xFadkE,1615
208
208
  orionis/foundation/providers/workers_provider.py,sha256=GdHENYV_yGyqmHJHn0DCyWmWId5xWjD48e6Zq2PGCWY,1674
209
209
  orionis/metadata/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
210
- orionis/metadata/framework.py,sha256=mozmW4PLxWofbBRZRC-v6uk1Xx8YNc-dYVsjFWv8DSc,4570
210
+ orionis/metadata/framework.py,sha256=c_azWwfBHtPi_aEzE--SleVFIUrsRmLw-FkxDUdeqB4,4570
211
211
  orionis/metadata/package.py,sha256=s1JeGJPwdVh4jO3IOfmpwMuJ_oX6Vf9NL7jgPEQNf5Y,16050
212
212
  orionis/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
213
213
  orionis/services/asynchrony/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
214
- orionis/services/asynchrony/coroutines.py,sha256=M1o4Al5dk8BR85CWHHUgymVQaD_6PgirenQMeITUoZQ,6863
214
+ orionis/services/asynchrony/coroutines.py,sha256=MUOi_ErAIMU_Jhc8hTLiqiRJTON1qpQpFjcZh4C328A,7038
215
215
  orionis/services/asynchrony/contracts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
216
- orionis/services/asynchrony/contracts/coroutines.py,sha256=Hjm-JOK-CjCDWa8sSaJZ7ccM_LxsVsYWFcYSSVciQ3U,2825
216
+ orionis/services/asynchrony/contracts/coroutines.py,sha256=c6gJ_thUSuZBZC2EX49YNkeCVdmlimfgQRTWfFU2AwQ,3088
217
217
  orionis/services/asynchrony/exceptions/__init__.py,sha256=LXjn7TFOVBaHbPFtV87hZ3HvkTziFqtdvzLSnOZDQfc,100
218
218
  orionis/services/asynchrony/exceptions/asynchrony.py,sha256=2MbqDBA5uGtnlXSmJAs6-1Lb4b8cHDXCKrnyRyucby0,407
219
219
  orionis/services/encrypter/encrypter.py,sha256=iOR8_rgyye_Mdlp9OY9Zs9UlnA4sfWvItiDWP_7Q4Vg,4073
@@ -394,8 +394,8 @@ orionis/test/validators/workers.py,sha256=rWcdRexINNEmGaO7mnc1MKUxkHKxrTsVuHgbnI
394
394
  orionis/test/view/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
395
395
  orionis/test/view/render.py,sha256=arysoswhkV2vUd2aVMZRPpmH317jaWbgjDpQ_AWQ5AE,5663
396
396
  orionis/test/view/report.stub,sha256=QLqqCdRoENr3ECiritRB3DO_MOjRQvgBh5jxZ3Hs1r0,28189
397
- orionis-0.691.0.dist-info/licenses/LICENCE,sha256=JhC-z_9mbpUrCfPjcl3DhDA8trNDMzb57cvRSam1avc,1463
398
- orionis-0.691.0.dist-info/METADATA,sha256=yYr4WLRPC_fk3XjhgdlK8XlE-A753XgIa0sOkdT58f8,4772
399
- orionis-0.691.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
400
- orionis-0.691.0.dist-info/top_level.txt,sha256=lyXi6jArpqJ-0zzNqd_uwsH-z9TCEBVBL-pC3Ekv7hU,8
401
- orionis-0.691.0.dist-info/RECORD,,
397
+ orionis-0.692.0.dist-info/licenses/LICENCE,sha256=JhC-z_9mbpUrCfPjcl3DhDA8trNDMzb57cvRSam1avc,1463
398
+ orionis-0.692.0.dist-info/METADATA,sha256=_6p6doO8b55N05r25pBWoZR_XXKpA9DIoF_d6QV2_5U,4772
399
+ orionis-0.692.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
400
+ orionis-0.692.0.dist-info/top_level.txt,sha256=lyXi6jArpqJ-0zzNqd_uwsH-z9TCEBVBL-pC3Ekv7hU,8
401
+ orionis-0.692.0.dist-info/RECORD,,