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
@@ -0,0 +1,5 @@
1
+ from .value_type import EnvironmentValueType
2
+
3
+ __all__ = [
4
+ 'EnvironmentValueType'
5
+ ]
@@ -2,33 +2,30 @@ from enum import Enum
2
2
 
3
3
  class EnvironmentValueType(Enum):
4
4
  """
5
- Enum representing supported environment variable cast types.
5
+ Enum representing the supported types for casting environment variable values.
6
6
 
7
7
  Attributes
8
8
  ----------
9
- PATH : EnvCastType
10
- Cast to a file system path.
11
- STR : EnvCastType
12
- Cast to a string.
13
- INT : EnvCastType
14
- Cast to an integer.
15
- FLOAT : EnvCastType
16
- Cast to a floating-point number.
17
- BOOL : EnvCastType
18
- Cast to a boolean value.
19
- LIST : EnvCastType
20
- Cast to a list.
21
- DICT : EnvCastType
22
- Cast to a dictionary.
23
- TUPLE : EnvCastType
24
- Cast to a tuple.
25
- SET : EnvCastType
26
- Cast to a set.
27
-
28
- Returns
29
- -------
30
- EnvCastType
31
- An enumeration member representing the desired cast type.
9
+ BASE64 : str
10
+ Represents a base64 encoded value.
11
+ PATH : str
12
+ Represents a file system path.
13
+ STR : str
14
+ Represents a string value.
15
+ INT : str
16
+ Represents an integer value.
17
+ FLOAT : str
18
+ Represents a floating-point value.
19
+ BOOL : str
20
+ Represents a boolean value.
21
+ LIST : str
22
+ Represents a list value.
23
+ DICT : str
24
+ Represents a dictionary value.
25
+ TUPLE : str
26
+ Represents a tuple value.
27
+ SET : str
28
+ Represents a set value.
32
29
  """
33
30
 
34
31
  BASE64 = 'base64' # Represents a base64 encoded type
@@ -40,4 +37,4 @@ class EnvironmentValueType(Enum):
40
37
  LIST = 'list' # Represents a list type
41
38
  DICT = 'dict' # Represents a dictionary type
42
39
  TUPLE = 'tuple' # Represents a tuple type
43
- SET = 'set' # Represents a set type
40
+ SET = 'set' # Represents a set type
@@ -7,72 +7,88 @@ class Env(IEnv):
7
7
  @staticmethod
8
8
  def get(key: str, default: Any = None) -> Any:
9
9
  """
10
- Retrieve the value of an environment variable by key.
10
+ Retrieve the value of an environment variable by its key.
11
11
 
12
12
  Parameters
13
13
  ----------
14
14
  key : str
15
- The name of the environment variable to retrieve.
15
+ The environment variable name to look up.
16
16
  default : Any, optional
17
- The value to return if the key is not found. Default is None.
17
+ Value to return if the key 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 present, otherwise `default`.
23
23
  """
24
+
25
+ # Create a new DotEnv instance to access environment variables
24
26
  dotenv = DotEnv()
27
+
28
+ # Retrieve the value for the given key, or return default if not found
25
29
  return dotenv.get(key, default)
26
30
 
27
31
  @staticmethod
28
32
  def set(key: str, value: str, type_hint: str = None) -> bool:
29
33
  """
30
- Set an environment variable in the .env file.
34
+ Set or update an environment variable in the .env file.
31
35
 
32
36
  Parameters
33
37
  ----------
34
38
  key : str
35
- The name of the environment variable to set.
39
+ The environment variable name to set.
36
40
  value : str
37
41
  The value to assign to the environment variable.
38
42
  type_hint : str, optional
39
- The type of the environment variable (e.g., 'str', 'int'). Default is None.
43
+ Optional type hint for the variable (e.g., 'str', 'int'). Defaults to None.
40
44
 
41
45
  Returns
42
46
  -------
43
47
  bool
44
48
  True if the variable was set successfully, False otherwise.
45
49
  """
50
+
51
+ # Create a new DotEnv instance to modify environment variables
46
52
  dotenv = DotEnv()
53
+
54
+ # Set the environment variable with the specified key, value, and optional type hint
47
55
  return dotenv.set(key, value, type_hint)
48
56
 
49
57
  @staticmethod
50
58
  def unset(key: str) -> bool:
51
59
  """
52
- Remove the specified environment variable from the .env file.
60
+ Remove an environment variable from the .env file.
53
61
 
54
62
  Parameters
55
63
  ----------
56
64
  key : str
57
- The name of the environment variable to remove.
65
+ The environment variable name to remove.
58
66
 
59
67
  Returns
60
68
  -------
61
69
  bool
62
- True if the variable was successfully removed, False otherwise.
70
+ True if the variable was removed successfully, False otherwise.
63
71
  """
72
+
73
+ # Create a new DotEnv instance to remove environment variables
64
74
  dotenv = DotEnv()
75
+
76
+ # Remove the environment variable with the specified key
65
77
  return dotenv.unset(key)
66
78
 
67
79
  @staticmethod
68
80
  def all() -> Dict[str, Any]:
69
81
  """
70
- Retrieve all environment variables as a dictionary.
82
+ Get all environment variables as a dictionary.
71
83
 
72
84
  Returns
73
85
  -------
74
86
  dict of str to Any
75
- A dictionary containing all environment variables loaded by DotEnv.
87
+ Dictionary containing all environment variables loaded by DotEnv.
76
88
  """
89
+
90
+ # Create a new DotEnv instance to access all environment variables
77
91
  dotenv = DotEnv()
92
+
93
+ # Return all environment variables as a dictionary
78
94
  return dotenv.all()
@@ -2,18 +2,22 @@ class OrionisEnvironmentValueException(Exception):
2
2
 
3
3
  def __init__(self, msg: str):
4
4
  """
5
+ Initialize the OrionisEnvironmentValueException.
6
+
5
7
  Parameters
6
8
  ----------
7
9
  msg : str
8
- Descriptive error message explaining the cause of the exception.
10
+ A descriptive error message that explains the cause of the exception.
9
11
  """
10
12
  super().__init__(msg)
11
13
 
12
14
  def __str__(self) -> str:
13
15
  """
16
+ Return the string representation of the exception.
17
+
14
18
  Returns
15
19
  -------
16
20
  str
17
- Formatted string describing the exception.
21
+ The error message associated with the exception.
18
22
  """
19
23
  return str(self.args[0])
@@ -2,18 +2,22 @@ class OrionisEnvironmentValueError(Exception):
2
2
 
3
3
  def __init__(self, msg: str):
4
4
  """
5
+ Initialize the OrionisEnvironmentValueError exception.
6
+
5
7
  Parameters
6
8
  ----------
7
9
  msg : str
8
- Descriptive error message explaining the cause of the exception.
10
+ A descriptive error message explaining the cause of the exception.
9
11
  """
10
12
  super().__init__(msg)
11
13
 
12
14
  def __str__(self) -> str:
13
15
  """
16
+ Return a formatted string describing the exception.
17
+
14
18
  Returns
15
19
  -------
16
20
  str
17
- Formatted string describing the exception.
21
+ The error message associated with the exception.
18
22
  """
19
23
  return str(self.args[0])
@@ -3,18 +3,20 @@ from orionis.services.environment.core.dot_env import DotEnv
3
3
 
4
4
  def env(key: str, default: Any = None) -> Any:
5
5
  """
6
- Retrieve the value of an environment variable.
6
+ Retrieves the value of an environment variable.
7
7
 
8
8
  Parameters
9
9
  ----------
10
10
  key : str
11
11
  The name of the environment variable to retrieve.
12
12
  default : Any, optional
13
- The value to return if the environment variable is not found. Default is None.
13
+ The value to return if the environment variable is not found. Defaults to None.
14
14
 
15
15
  Returns
16
16
  -------
17
17
  Any
18
- The value of the environment variable if it exists, otherwise the default value.
18
+ The value of the environment variable if it exists, otherwise the specified default value.
19
19
  """
20
+
21
+ # Instantiate DotEnv and retrieve the environment variable by key
20
22
  return DotEnv().get(key, default)
@@ -2,28 +2,25 @@ import os
2
2
 
3
3
  class SecureKeyGenerator:
4
4
  """
5
- Provides static methods for generating secure random keys in base64 format.
5
+ Static utility class for generating cryptographically secure random keys.
6
6
 
7
- Methods
8
- -------
9
- generate_key() : str
10
- Generates a secure random key encoded in base64.
7
+ This class provides a static method to generate a secure random key,
8
+ encoded as a hexadecimal string, suitable for use in security-sensitive
9
+ applications such as cryptographic secrets or tokens.
11
10
  """
12
11
 
13
12
  @staticmethod
14
13
  def generate() -> str:
15
14
  """
16
- Generates a cryptographically secure random key and encodes it in hexadecimal format.
17
-
18
- This method uses the operating system's cryptographic random number generator to
19
- produce a 32-byte random value, which is then encoded as a hexadecimal string.
15
+ Generate a cryptographically secure random key encoded in hexadecimal.
20
16
 
21
17
  Returns
22
18
  -------
23
19
  str
24
- A 64-character hexadecimal string representing a 32-byte secure random key.
20
+ A 64-character hexadecimal string representing a 32-byte
21
+ cryptographically secure random key.
25
22
  """
26
23
 
27
24
  # Generate 32 random bytes using a cryptographically secure RNG
28
25
  # Encode the bytes as a hexadecimal string and return
29
- return os.urandom(32).hex()
26
+ return os.urandom(32).hex()
@@ -0,0 +1,7 @@
1
+ from .key_name import ValidateKeyName
2
+ from .types import ValidateTypes
3
+
4
+ __all__ = [
5
+ 'ValidateKeyName',
6
+ 'ValidateTypes',
7
+ ]
@@ -8,7 +8,7 @@ class __ValidateKeyName:
8
8
 
9
9
  def __call__(self, key: object) -> str:
10
10
  """
11
- Validates that the provided environment variable name meets the required format.
11
+ Validates that the provided environment variable name is a string and matches the required format.
12
12
 
13
13
  Parameters
14
14
  ----------
@@ -26,21 +26,21 @@ class __ValidateKeyName:
26
26
  If the provided key is not a string or does not match the required format.
27
27
  """
28
28
 
29
- # Check if the key is a string
29
+ # Ensure the key is of type string
30
30
  if not isinstance(key, str):
31
31
  raise OrionisEnvironmentValueError(
32
32
  f"Environment variable name must be a string, got {type(key).__name__}."
33
33
  )
34
34
 
35
- # Validate the key against the pattern
35
+ # Check if the key matches the required pattern for environment variable names
36
36
  if not self._pattern.fullmatch(key):
37
37
  raise OrionisEnvironmentValueError(
38
38
  f"Invalid environment variable name '{key}'. It must start with an uppercase letter, "
39
39
  "contain only uppercase letters, numbers, or underscores. Example: 'MY_ENV_VAR'."
40
40
  )
41
41
 
42
- # Return the validated key
42
+ # Return the validated key if all checks pass
43
43
  return key
44
44
 
45
45
  # Instance to be used for key name validation
46
- ValidateKeyName = __ValidateKeyName()
46
+ ValidateKeyName = __ValidateKeyName()
@@ -1,4 +1,3 @@
1
- import re
2
1
  from typing import Union
3
2
  from orionis.services.environment.enums.value_type import EnvironmentValueType
4
3
  from orionis.services.environment.exceptions.value import OrionisEnvironmentValueError
@@ -6,7 +5,26 @@ from orionis.services.environment.exceptions.value import OrionisEnvironmentValu
6
5
  class __ValidateTypes:
7
6
 
8
7
  def __call__(self, value: Union[str, int, float, bool, list, dict, tuple, set], type_hint: str | EnvironmentValueType = None) -> str:
8
+ """
9
+ Validates and determines the type of a given value, optionally using a provided type hint.
9
10
 
11
+ Parameters
12
+ ----------
13
+ value : str, int, float, bool, list, dict, tuple, or set
14
+ The value whose type is to be validated and determined.
15
+ type_hint : str or EnvironmentValueType, optional
16
+ An optional type hint specifying the expected type. Can be a string or an EnvironmentValueType.
17
+
18
+ Returns
19
+ -------
20
+ str
21
+ The determined type as a string, either from the type hint or inferred from the value.
22
+
23
+ Raises
24
+ ------
25
+ OrionisEnvironmentValueError
26
+ If the value is not of a supported type or if the type hint is invalid.
27
+ """
10
28
  # Ensure the value is a valid type.
11
29
  if not isinstance(value, (str, int, float, bool, list, dict, tuple, set)):
12
30
  raise OrionisEnvironmentValueError(
@@ -23,15 +41,17 @@ class __ValidateTypes:
23
41
  if type_hint:
24
42
 
25
43
  # If type_hint is a string, convert it to EnvironmentValueType if valid.
26
- if isinstance(type_hint, str):
27
- try:
44
+ try:
45
+ if isinstance(type_hint, str):
28
46
  type_hint = EnvironmentValueType[type_hint.upper()].value
29
- except KeyError:
30
- raise OrionisEnvironmentValueError(
31
- f"Invalid type hint: {type_hint}. Allowed types are: {[e.value for e in EnvironmentValueType]}"
32
- )
33
- elif isinstance(type_hint, EnvironmentValueType):
34
- type_hint = type_hint.value
47
+ elif isinstance(type_hint, EnvironmentValueType):
48
+ type_hint = type_hint.value
49
+
50
+ # If type_hint is not a valid EnvironmentValueType, raise an error.
51
+ except KeyError:
52
+ raise OrionisEnvironmentValueError(
53
+ f"Invalid type hint: {type_hint}. Allowed types are: {[e.value for e in EnvironmentValueType]}"
54
+ )
35
55
 
36
56
  # If no type hint is provided, use the type of the value.
37
57
  else: