orionis 0.286.0__py3-none-any.whl → 0.287.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 (57) hide show
  1. orionis/metadata/framework.py +1 -1
  2. orionis/services/environment/contracts/env.py +45 -50
  3. orionis/services/environment/dot_env.py +205 -181
  4. orionis/services/environment/env.py +68 -85
  5. orionis/services/environment/exceptions/environment_value_error.py +18 -0
  6. orionis/services/environment/exceptions/environment_value_exception.py +23 -0
  7. orionis/services/environment/type_hint.py +559 -0
  8. orionis/test/logs/history.py +3 -5
  9. {orionis-0.286.0.dist-info → orionis-0.287.0.dist-info}/METADATA +1 -1
  10. {orionis-0.286.0.dist-info → orionis-0.287.0.dist-info}/RECORD +56 -54
  11. tests/example/test_example.py +5 -2
  12. tests/foundation/config/app/test_app.py +13 -3
  13. tests/foundation/config/auth/test_auth.py +9 -4
  14. tests/foundation/config/cache/test_cache.py +60 -15
  15. tests/foundation/config/cache/test_cache_file.py +62 -14
  16. tests/foundation/config/cache/test_cache_stores.py +74 -14
  17. tests/foundation/config/cors/test_cors.py +102 -33
  18. tests/foundation/config/database/test_database.py +38 -14
  19. tests/foundation/config/database/test_database_connections.py +79 -5
  20. tests/foundation/config/database/test_database_mysql.py +138 -15
  21. tests/foundation/config/database/test_database_oracle.py +110 -26
  22. tests/foundation/config/database/test_database_pgsql.py +96 -26
  23. tests/foundation/config/database/test_database_sqlite.py +56 -2
  24. tests/foundation/config/exceptions/test_exceptions_integrity.py +44 -10
  25. tests/foundation/config/filesystems/test_filesystems.py +64 -14
  26. tests/foundation/config/filesystems/test_filesystems_aws.py +45 -7
  27. tests/foundation/config/filesystems/test_filesystems_disks.py +78 -8
  28. tests/foundation/config/filesystems/test_filesystems_local.py +66 -18
  29. tests/foundation/config/filesystems/test_filesystems_public.py +37 -0
  30. tests/foundation/config/logging/test_logging.py +75 -11
  31. tests/foundation/config/logging/test_logging_channels.py +79 -2
  32. tests/foundation/config/logging/test_logging_chunked.py +85 -12
  33. tests/foundation/config/logging/test_logging_daily.py +79 -12
  34. tests/foundation/config/logging/test_logging_hourly.py +68 -2
  35. tests/foundation/config/logging/test_logging_monthly.py +48 -2
  36. tests/foundation/config/logging/test_logging_stack.py +49 -14
  37. tests/foundation/config/logging/test_logging_weekly.py +92 -2
  38. tests/foundation/config/mail/test_mail.py +87 -15
  39. tests/foundation/config/mail/test_mail_file.py +40 -4
  40. tests/foundation/config/mail/test_mail_mailers.py +56 -8
  41. tests/foundation/config/mail/test_mail_smtp.py +58 -14
  42. tests/foundation/config/queue/test_queue.py +62 -9
  43. tests/foundation/config/queue/test_queue_brokers.py +27 -10
  44. tests/foundation/config/queue/test_queue_database.py +53 -15
  45. tests/foundation/config/root/test_root_paths.py +69 -2
  46. tests/foundation/config/session/test_session.py +30 -1
  47. tests/foundation/config/startup/test_config_startup.py +77 -7
  48. tests/foundation/config/testing/test_testing.py +68 -0
  49. tests/patterns/singleton/test_singleton.py +10 -1
  50. tests/services/environment/test_env.py +3 -4
  51. tests/testing/test_testing_result.py +56 -19
  52. tests/testing/test_testing_unit.py +93 -24
  53. orionis/services/environment/exceptions/value_exception.py +0 -27
  54. {orionis-0.286.0.dist-info → orionis-0.287.0.dist-info}/WHEEL +0 -0
  55. {orionis-0.286.0.dist-info → orionis-0.287.0.dist-info}/licenses/LICENCE +0 -0
  56. {orionis-0.286.0.dist-info → orionis-0.287.0.dist-info}/top_level.txt +0 -0
  57. {orionis-0.286.0.dist-info → orionis-0.287.0.dist-info}/zip-safe +0 -0
@@ -1,114 +1,97 @@
1
1
  from orionis.services.environment.contracts.env import IEnv
2
2
  from orionis.services.environment.dot_env import DotEnv
3
- from typing import Any, Optional, Dict
3
+ from typing import Any, Dict
4
4
 
5
- def env(key: str, default: Any = None, is_path: bool = False) -> Any:
5
+ def env(key: str, default: Any = None) -> Any:
6
6
  """
7
- Retrieve the value of an environment variable by key.
8
-
9
- Args:
10
- key (str): The name of the environment variable to retrieve.
11
- default (Any, optional): The value to return if the key is not found. Defaults to None.
12
- is_path (bool, optional): If True, the value will be treated as a file path. Defaults to False.
13
-
14
- Returns:
15
- Any: The value of the environment variable if found, otherwise the default value.
7
+ Retrieve the value of an environment variable.
8
+
9
+ Parameters
10
+ ----------
11
+ key : str
12
+ The name of the environment variable to retrieve.
13
+ default : Any, optional
14
+ The value to return if the environment variable is not found. Default is None.
15
+
16
+ Returns
17
+ -------
18
+ Any
19
+ The value of the environment variable if it exists, otherwise the default value.
16
20
  """
17
- return DotEnv().get(key, default, is_path)
21
+ dotenv = DotEnv()
22
+ return dotenv.get(key, default)
18
23
 
19
24
  class Env(IEnv):
20
- """
21
- Env is a utility class that provides static methods for managing environment variables
22
- using the DotEnv class. It allows getting, setting, unsetting, listing, destroying,
23
- and serializing environment variables.
24
- """
25
-
26
- _dotenv_instance: Optional[DotEnv] = None
27
-
28
- @classmethod
29
- def _dotenv(cls) -> DotEnv:
30
- """
31
- Returns a singleton instance of the DotEnv class.
32
-
33
- If the instance does not exist, it creates a new one and stores it in the class attribute.
34
- Subsequent calls will return the same instance.
35
-
36
- Returns:
37
- DotEnv: The singleton instance of the DotEnv class.
38
- """
39
- if cls._dotenv_instance is None:
40
- cls._dotenv_instance = DotEnv()
41
- return cls._dotenv_instance
42
25
 
43
26
  @staticmethod
44
- def get(key: str, default: Any = None, is_path: bool = False) -> Any:
27
+ def get(key: str, default: Any = None) -> Any:
45
28
  """
46
- Retrieve the value of an environment variable.
47
-
48
- Args:
49
- key (str): The name of the environment variable to retrieve.
50
- default (Any, optional): The value to return if the environment variable is not found. Defaults to None.
51
- is_path (bool, optional): If True, treat the value as a filesystem path. Defaults to False.
52
-
53
- Returns:
54
- Any: The value of the environment variable if found, otherwise the default value.
29
+ Retrieve the value of an environment variable by key.
30
+
31
+ Parameters
32
+ ----------
33
+ key : str
34
+ The name of the environment variable to retrieve.
35
+ default : Any, optional
36
+ The value to return if the key is not found. Default is None.
37
+
38
+ Returns
39
+ -------
40
+ Any
41
+ The value of the environment variable if found, otherwise the default value.
55
42
  """
56
- return Env._dotenv().get(key, default, is_path)
43
+ dotenv = DotEnv()
44
+ return dotenv.get(key, default)
57
45
 
58
46
  @staticmethod
59
- def set(key: str, value: str, is_path: bool = False) -> bool:
47
+ def set(key: str, value: str, type_hint: str = None) -> bool:
60
48
  """
61
- Sets an environment variable with the specified key and value.
62
-
63
- Args:
64
- key (str): The name of the environment variable to set.
65
- value (str): The value to assign to the environment variable.
66
- is_path (bool, optional): If True, treats the value as a file system path. Defaults to False.
67
-
68
- Returns:
69
- bool: True if the environment variable was set successfully, False otherwise.
49
+ Set an environment variable in the .env file.
50
+
51
+ Parameters
52
+ ----------
53
+ key : str
54
+ The name of the environment variable to set.
55
+ value : str
56
+ The value to assign to the environment variable.
57
+ type_hint : str, optional
58
+ The type of the environment variable (e.g., 'str', 'int'). Default is None.
59
+
60
+ Returns
61
+ -------
62
+ bool
63
+ True if the variable was set successfully, False otherwise.
70
64
  """
71
- return Env._dotenv().set(key, value, is_path)
65
+ dotenv = DotEnv()
66
+ return dotenv.set(key, value, type_hint)
72
67
 
73
68
  @staticmethod
74
69
  def unset(key: str) -> bool:
75
70
  """
76
- Removes the specified environment variable from the environment.
71
+ Remove the specified environment variable from the .env file.
77
72
 
78
- Args:
79
- key (str): The name of the environment variable to remove.
73
+ Parameters
74
+ ----------
75
+ key : str
76
+ The name of the environment variable to remove.
80
77
 
81
- Returns:
82
- bool: True if the variable was successfully removed, False otherwise.
78
+ Returns
79
+ -------
80
+ bool
81
+ True if the variable was successfully removed, False otherwise.
83
82
  """
84
- return Env._dotenv().unset(key)
83
+ dotenv = DotEnv()
84
+ return dotenv.unset(key)
85
85
 
86
86
  @staticmethod
87
87
  def all() -> Dict[str, Any]:
88
88
  """
89
89
  Retrieve all environment variables as a dictionary.
90
90
 
91
- Returns:
92
- Dict[str, Any]: A dictionary containing all environment variables loaded by the dotenv configuration.
93
- """
94
- return Env._dotenv().all()
95
-
96
- @staticmethod
97
- def toJson() -> str:
98
- """
99
- Serializes the environment variables managed by the Env class into a JSON-formatted string.
100
-
101
- Returns:
102
- str: A JSON string representation of the environment variables.
103
- """
104
- return Env._dotenv().toJson()
105
-
106
- @staticmethod
107
- def toBase64() -> str:
108
- """
109
- Converts the environment variables loaded by the dotenv instance to a Base64-encoded string.
110
-
111
- Returns:
112
- str: The Base64-encoded representation of the environment variables.
91
+ Returns
92
+ -------
93
+ dict of str to Any
94
+ A dictionary containing all environment variables loaded by DotEnv.
113
95
  """
114
- return Env._dotenv().toBase64()
96
+ dotenv = DotEnv()
97
+ return dotenv.all()
@@ -0,0 +1,18 @@
1
+ class OrionisEnvironmentValueError(Exception):
2
+
3
+ def __init__(self, msg: str):
4
+ """
5
+ Initializes the exception with a custom error message.
6
+ Args:
7
+ msg (str): The error message describing the exception.
8
+ """
9
+ super().__init__(msg)
10
+
11
+ def __str__(self) -> str:
12
+ """
13
+ Return a string representation of the exception, including the class name and the first argument.
14
+
15
+ Returns:
16
+ str: A formatted string with the exception class name and its first argument.
17
+ """
18
+ return f"{self.__class__.__name__}: {self.args[0]}"
@@ -0,0 +1,23 @@
1
+ class OrionisEnvironmentValueException(Exception):
2
+
3
+ def __init__(self, msg: str):
4
+ """
5
+ Exception raised for errors related to environment values.
6
+
7
+ Parameters
8
+ ----------
9
+ msg : str
10
+ The error message describing the exception.
11
+ """
12
+ super().__init__(msg)
13
+
14
+ def __str__(self) -> str:
15
+ """
16
+ Returns a string representation of the exception.
17
+
18
+ Returns
19
+ -------
20
+ str
21
+ A formatted string with the exception class name and its first argument.
22
+ """
23
+ return f"{self.__class__.__name__}: {self.args[0]}"