orionis 0.435.0__py3-none-any.whl → 0.437.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 (59) 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 +5 -9
  21. orionis/services/asynchrony/coroutines.py +10 -23
  22. orionis/services/asynchrony/exceptions/exception.py +3 -3
  23. orionis/services/environment/contracts/caster.py +8 -9
  24. orionis/services/environment/contracts/env.py +9 -9
  25. orionis/services/environment/core/dot_env.py +56 -71
  26. orionis/services/environment/dynamic/caster.py +215 -215
  27. orionis/services/environment/enums/__init__.py +5 -0
  28. orionis/services/environment/enums/value_type.py +22 -25
  29. orionis/services/environment/env.py +28 -12
  30. orionis/services/environment/exceptions/exception.py +6 -2
  31. orionis/services/environment/exceptions/value.py +6 -2
  32. orionis/services/environment/helpers/functions.py +5 -3
  33. orionis/services/environment/key/key_generator.py +8 -11
  34. orionis/services/environment/validators/__init__.py +7 -0
  35. orionis/services/environment/validators/key_name.py +5 -5
  36. orionis/services/environment/validators/types.py +29 -9
  37. orionis/services/introspection/abstract/contracts/reflection.py +188 -221
  38. orionis/services/introspection/abstract/reflection.py +311 -178
  39. orionis/services/introspection/callables/contracts/reflection.py +64 -21
  40. orionis/services/introspection/callables/reflection.py +98 -23
  41. orionis/services/introspection/concretes/reflection.py +278 -181
  42. orionis/services/introspection/dependencies/contracts/reflection.py +21 -18
  43. orionis/services/introspection/dependencies/entities/callable_dependencies.py +15 -16
  44. orionis/services/introspection/dependencies/entities/class_dependencies.py +24 -16
  45. orionis/services/introspection/dependencies/entities/known_dependencies.py +19 -13
  46. orionis/services/introspection/dependencies/entities/method_dependencies.py +22 -16
  47. orionis/services/introspection/dependencies/reflection.py +0 -3
  48. orionis/services/introspection/instances/reflection.py +16 -6
  49. orionis/services/log/contracts/log_service.py +4 -0
  50. orionis/services/log/handlers/filename.py +2 -0
  51. orionis/services/paths/contracts/resolver.py +0 -3
  52. orionis/services/paths/resolver.py +0 -3
  53. {orionis-0.435.0.dist-info → orionis-0.437.0.dist-info}/METADATA +1 -1
  54. {orionis-0.435.0.dist-info → orionis-0.437.0.dist-info}/RECORD +59 -59
  55. /orionis/services/introspection/concretes/contracts/{concrete.py → reflection.py} +0 -0
  56. {orionis-0.435.0.dist-info → orionis-0.437.0.dist-info}/WHEEL +0 -0
  57. {orionis-0.435.0.dist-info → orionis-0.437.0.dist-info}/licenses/LICENCE +0 -0
  58. {orionis-0.435.0.dist-info → orionis-0.437.0.dist-info}/top_level.txt +0 -0
  59. {orionis-0.435.0.dist-info → orionis-0.437.0.dist-info}/zip-safe +0 -0
@@ -7,19 +7,19 @@ class IEnv(ABC):
7
7
  @abstractmethod
8
8
  def get(key: str, default: Any = None) -> Any:
9
9
  """
10
- Retrieve the value of an environment variable by key.
10
+ Retrieves the value of the specified environment variable.
11
11
 
12
12
  Parameters
13
13
  ----------
14
14
  key : str
15
15
  The name of the environment variable to retrieve.
16
16
  default : Any, optional
17
- The value to return if the key is not found. Default is None.
17
+ The value to return if the environment variable is not found. Defaults to None.
18
18
 
19
19
  Returns
20
20
  -------
21
21
  Any
22
- The value of the environment variable if found, otherwise the default value.
22
+ The value of the environment variable if it exists, otherwise the default value.
23
23
  """
24
24
  pass
25
25
 
@@ -27,7 +27,7 @@ class IEnv(ABC):
27
27
  @abstractmethod
28
28
  def set(key: str, value: str, type: str = None) -> bool:
29
29
  """
30
- Set an environment variable in the .env file.
30
+ Sets the value of an environment variable in the .env file.
31
31
 
32
32
  Parameters
33
33
  ----------
@@ -36,12 +36,12 @@ class IEnv(ABC):
36
36
  value : str
37
37
  The value to assign to the environment variable.
38
38
  type : str, optional
39
- The type of the environment variable (e.g., 'str', 'int'). Default is None.
39
+ The type of the environment variable (e.g., 'str', 'int'). Defaults to None.
40
40
 
41
41
  Returns
42
42
  -------
43
43
  bool
44
- True if the variable was set successfully, False otherwise.
44
+ True if the environment variable was set successfully, False otherwise.
45
45
  """
46
46
  pass
47
47
 
@@ -49,7 +49,7 @@ class IEnv(ABC):
49
49
  @abstractmethod
50
50
  def unset(key: str) -> bool:
51
51
  """
52
- Remove the specified environment variable from the .env file.
52
+ Removes the specified environment variable from the .env file.
53
53
 
54
54
  Parameters
55
55
  ----------
@@ -59,7 +59,7 @@ class IEnv(ABC):
59
59
  Returns
60
60
  -------
61
61
  bool
62
- True if the variable was successfully removed, False otherwise.
62
+ True if the environment variable was removed successfully, False otherwise.
63
63
  """
64
64
  pass
65
65
 
@@ -67,7 +67,7 @@ class IEnv(ABC):
67
67
  @abstractmethod
68
68
  def all() -> Dict[str, Any]:
69
69
  """
70
- Retrieve all environment variables as a dictionary.
70
+ Retrieves all environment variables as a dictionary.
71
71
 
72
72
  Returns
73
73
  -------
@@ -4,9 +4,8 @@ import threading
4
4
  from pathlib import Path
5
5
  from typing import Any, Optional, Union
6
6
  from dotenv import dotenv_values, load_dotenv, set_key, unset_key
7
- from orionis.services.environment.enums.value_type import EnvironmentValueType
8
- from orionis.services.environment.validators.key_name import ValidateKeyName
9
- from orionis.services.environment.validators.types import ValidateTypes
7
+ from orionis.services.environment.enums import EnvironmentValueType
8
+ from orionis.services.environment.validators import ValidateKeyName, ValidateTypes
10
9
  from orionis.support.patterns.singleton import Singleton
11
10
  from orionis.services.environment.dynamic.caster import EnvironmentCaster
12
11
 
@@ -22,20 +21,10 @@ class DotEnv(metaclass=Singleton):
22
21
  """
23
22
  Initialize the DotEnv service and prepare the `.env` file for environment variable management.
24
23
 
25
- This constructor determines the location of the `.env` file, ensures its existence,
26
- and loads its contents into the current process environment. If a custom path is provided,
27
- it is resolved and used; otherwise, a `.env` file in the current working directory is used.
28
-
29
24
  Parameters
30
25
  ----------
31
26
  path : str, optional
32
- The path to the `.env` file. If not specified, defaults to a `.env` file
33
- in the current working directory.
34
-
35
- Returns
36
- -------
37
- None
38
- This method does not return any value.
27
+ Path to the `.env` file. If not provided, defaults to `.env` in the current working directory.
39
28
 
40
29
  Raises
41
30
  ------
@@ -44,16 +33,16 @@ class DotEnv(metaclass=Singleton):
44
33
 
45
34
  Notes
46
35
  -----
47
- - Ensures thread safety during initialization.
48
- - If the specified `.env` file does not exist, it is created automatically.
49
- - Loads environment variables from the `.env` file into the process environment.
36
+ Ensures thread safety during initialization. If the specified `.env` file does not exist, it is created.
37
+ Loads environment variables from the `.env` file into the process environment.
50
38
  """
39
+
51
40
  try:
52
41
 
53
- # Ensure thread-safe initialization
42
+ # Ensure thread-safe initialization to avoid race conditions
54
43
  with self._lock:
55
44
 
56
- # Set default .env file path to current working directory
45
+ # Set the default .env file path to the current working directory
57
46
  self.__resolved_path = Path(os.getcwd()) / ".env"
58
47
 
59
48
  # If a custom path is provided, resolve and use it
@@ -72,6 +61,11 @@ class DotEnv(metaclass=Singleton):
72
61
  # Raise an error if the .env file cannot be created or accessed
73
62
  raise OSError(f"Failed to create or access the .env file at {self.__resolved_path}: {e}")
74
63
 
64
+ except Exception as e:
65
+
66
+ # Raise a general error for any other exceptions during initialization
67
+ raise Exception(f"An unexpected error occurred while initializing DotEnv: {e}")
68
+
75
69
  def set(
76
70
  self,
77
71
  key: str,
@@ -81,41 +75,49 @@ class DotEnv(metaclass=Singleton):
81
75
  """
82
76
  Set an environment variable in both the `.env` file and the current process environment.
83
77
 
84
- This method serializes the provided value (optionally using a type hint), validates the key,
85
- and updates the corresponding entry in the `.env` file as well as the process's environment
86
- variables. Thread safety is ensured during the operation.
87
-
88
78
  Parameters
89
79
  ----------
90
80
  key : str
91
81
  The name of the environment variable to set. Must be a valid environment variable name.
92
- value : Union[str, int, float, bool, list, dict, tuple, set]
93
- The value to assign to the environment variable. Supported types include string, integer,
94
- float, boolean, list, dictionary, tuple, and set.
82
+ value : str, int, float, bool, list, dict, tuple, or set
83
+ The value to assign to the environment variable.
95
84
  type_hint : str or EnvironmentValueType, optional
96
- An explicit type hint to guide serialization. If provided, the value is serialized
97
- according to the specified type.
85
+ An explicit type hint to guide the serialization of the value.
98
86
 
99
87
  Returns
100
88
  -------
101
89
  bool
102
- Returns True if the environment variable was successfully set in both the `.env` file
103
- and the current process environment.
90
+ True if the environment variable was successfully set.
104
91
 
105
92
  Raises
106
93
  ------
107
94
  OrionisEnvironmentValueError
108
95
  If the provided key is not a valid environment variable name.
96
+
97
+ Notes
98
+ -----
99
+ This method ensures thread safety during the set operation. It validates the key name,
100
+ serializes the value (optionally using a type hint), writes the variable to the `.env` file,
101
+ and updates the variable in the current process environment.
109
102
  """
103
+
104
+ # Ensure thread-safe operation during the set process.
110
105
  with self._lock:
106
+
111
107
  # Validate the environment variable key name.
112
108
  __key = ValidateKeyName(key)
113
109
 
114
110
  # If a type hint is provided, validate and serialize the value accordingly.
115
111
  if type_hint is not None:
112
+
113
+ # Validate the value against the provided type hint.
116
114
  __type = ValidateTypes(value, type_hint)
115
+
116
+ # Serialize the value using the validated type.
117
117
  __value = self.__serializeValue(value, __type)
118
+
118
119
  else:
120
+
119
121
  # Serialize the value without a type hint.
120
122
  __value = self.__serializeValue(value)
121
123
 
@@ -134,7 +136,7 @@ class DotEnv(metaclass=Singleton):
134
136
  default: Optional[Any] = None
135
137
  ) -> Any:
136
138
  """
137
- Get the value of an environment variable.
139
+ Retrieve the value of an environment variable.
138
140
 
139
141
  Parameters
140
142
  ----------
@@ -153,6 +155,8 @@ class DotEnv(metaclass=Singleton):
153
155
  OrionisEnvironmentValueError
154
156
  If `key` is not a string.
155
157
  """
158
+
159
+ # Ensure thread-safe operation while retrieving the environment variable.
156
160
  with self._lock:
157
161
 
158
162
  # Ensure the key is a string.
@@ -172,20 +176,15 @@ class DotEnv(metaclass=Singleton):
172
176
  """
173
177
  Remove an environment variable from both the `.env` file and the current process environment.
174
178
 
175
- This method deletes the specified environment variable from the resolved `.env` file
176
- and removes it from the current process's environment variables. The operation is
177
- performed in a thread-safe manner. The key is validated before removal.
178
-
179
179
  Parameters
180
180
  ----------
181
181
  key : str
182
- The name of the environment variable to remove. Must be a valid environment variable name.
182
+ Name of the environment variable to remove.
183
183
 
184
184
  Returns
185
185
  -------
186
186
  bool
187
- Returns True if the environment variable was successfully removed from both the `.env` file
188
- and the process environment. Returns True even if the variable does not exist.
187
+ True if the environment variable was successfully removed.
189
188
 
190
189
  Raises
191
190
  ------
@@ -194,9 +193,10 @@ class DotEnv(metaclass=Singleton):
194
193
 
195
194
  Notes
196
195
  -----
197
- - The method is thread-safe.
198
- - If the environment variable does not exist, the method has no effect and returns True.
196
+ If the environment variable does not exist, the method has no effect and returns True.
199
197
  """
198
+
199
+ # Ensure thread-safe operation during the unset process.
200
200
  with self._lock:
201
201
 
202
202
  # Validate the environment variable key name.
@@ -215,24 +215,19 @@ class DotEnv(metaclass=Singleton):
215
215
  """
216
216
  Retrieve all environment variables from the resolved `.env` file as a dictionary.
217
217
 
218
- This method reads all key-value pairs from the currently resolved `.env` file and
219
- parses each value into its appropriate Python type using the internal `__parseValue`
220
- method. The returned dictionary contains environment variable names as keys and their
221
- parsed values as values.
222
-
223
218
  Returns
224
219
  -------
225
220
  dict
226
- A dictionary where each key is an environment variable name (str) and each value
227
- is the parsed Python representation of the variable as determined by `__parseValue`.
228
- If the `.env` file is empty, an empty dictionary is returned.
221
+ Dictionary where each key is an environment variable name (str) and each value
222
+ is the parsed Python representation of the variable.
229
223
 
230
224
  Notes
231
225
  -----
232
- - Thread safety is ensured during the read operation.
233
- - Only variables present in the `.env` file are returned; variables set only in the
234
- process environment are not included.
226
+ Only variables present in the `.env` file are returned; variables set only in the
227
+ process environment are not included.
235
228
  """
229
+
230
+ # Ensure thread-safe operation while reading and parsing environment variables.
236
231
  with self._lock:
237
232
 
238
233
  # Read all raw key-value pairs from the .env file
@@ -249,24 +244,18 @@ class DotEnv(metaclass=Singleton):
249
244
  """
250
245
  Serialize a Python value into a string suitable for storage in a .env file.
251
246
 
252
- This method converts the provided value into a string representation that can be
253
- safely written to a .env file. If a type hint is provided, the value is serialized
254
- according to the specified type using the EnvTypes utility. Otherwise, the method
255
- infers the serialization strategy based on the value's type.
256
-
257
247
  Parameters
258
248
  ----------
259
249
  value : Any
260
- The value to serialize. Supported types include None, str, int, float, bool,
250
+ Value to serialize. Supported types include None, str, int, float, bool,
261
251
  list, dict, tuple, and set.
262
252
  type_hint : str or EnvironmentValueType, optional
263
- An explicit type hint to guide serialization. If provided, the value is
264
- serialized using EnvTypes.
253
+ Explicit type hint to guide serialization.
265
254
 
266
255
  Returns
267
256
  -------
268
257
  str
269
- The serialized string representation of the input value, suitable for storage
258
+ Serialized string representation of the input value, suitable for storage
270
259
  in a .env file. Returns "null" for None values.
271
260
  """
272
261
 
@@ -308,28 +297,24 @@ class DotEnv(metaclass=Singleton):
308
297
  """
309
298
  Parse a string or raw value from the .env file into its appropriate Python type.
310
299
 
311
- This method attempts to convert the input value, which may be a string or already a Python object,
312
- into its most suitable Python type. It handles common representations of null, booleans, and
313
- attempts to parse collections and literals. If parsing fails, the original string is returned.
314
-
315
300
  Parameters
316
301
  ----------
317
302
  value : Any
318
- The value to parse, typically a string read from the .env file, but may also be a Python object.
303
+ Value to parse, typically a string read from the .env file, but may also be a Python object.
319
304
 
320
305
  Returns
321
306
  -------
322
307
  Any
323
- The parsed Python value. Returns `None` for recognized null representations, a boolean for
308
+ Parsed Python value. Returns `None` for recognized null representations, a boolean for
324
309
  "true"/"false" strings, a Python literal (list, dict, int, etc.) if possible, or the original
325
310
  string if no conversion is possible.
326
311
 
327
312
  Notes
328
313
  -----
329
- - Recognizes 'none', 'null', 'nan', 'nil' (case-insensitive) as null values.
330
- - Attempts to use `EnvironmentCaster` for advanced type parsing.
331
- - Falls back to `ast.literal_eval` for literal evaluation.
332
- - Returns the original string if all parsing attempts fail.
314
+ Recognizes 'none', 'null', 'nan', 'nil' (case-insensitive) as null values.
315
+ Attempts to use `EnvironmentCaster` for advanced type parsing.
316
+ Falls back to `ast.literal_eval` for literal evaluation.
317
+ Returns the original string if all parsing attempts fail.
333
318
  """
334
319
 
335
320
  # Early return for None values
@@ -365,4 +350,4 @@ class DotEnv(metaclass=Singleton):
365
350
 
366
351
  # Return the original string if parsing fails
367
352
  except (ValueError, SyntaxError):
368
- return value_str
353
+ return value_str