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.
- orionis/metadata/framework.py +1 -1
- orionis/services/environment/contracts/env.py +45 -50
- orionis/services/environment/dot_env.py +205 -181
- orionis/services/environment/env.py +68 -85
- orionis/services/environment/exceptions/environment_value_error.py +18 -0
- orionis/services/environment/exceptions/environment_value_exception.py +23 -0
- orionis/services/environment/type_hint.py +559 -0
- orionis/test/logs/history.py +3 -5
- {orionis-0.286.0.dist-info → orionis-0.287.0.dist-info}/METADATA +1 -1
- {orionis-0.286.0.dist-info → orionis-0.287.0.dist-info}/RECORD +56 -54
- tests/example/test_example.py +5 -2
- tests/foundation/config/app/test_app.py +13 -3
- tests/foundation/config/auth/test_auth.py +9 -4
- tests/foundation/config/cache/test_cache.py +60 -15
- tests/foundation/config/cache/test_cache_file.py +62 -14
- tests/foundation/config/cache/test_cache_stores.py +74 -14
- tests/foundation/config/cors/test_cors.py +102 -33
- tests/foundation/config/database/test_database.py +38 -14
- tests/foundation/config/database/test_database_connections.py +79 -5
- tests/foundation/config/database/test_database_mysql.py +138 -15
- tests/foundation/config/database/test_database_oracle.py +110 -26
- tests/foundation/config/database/test_database_pgsql.py +96 -26
- tests/foundation/config/database/test_database_sqlite.py +56 -2
- tests/foundation/config/exceptions/test_exceptions_integrity.py +44 -10
- tests/foundation/config/filesystems/test_filesystems.py +64 -14
- tests/foundation/config/filesystems/test_filesystems_aws.py +45 -7
- tests/foundation/config/filesystems/test_filesystems_disks.py +78 -8
- tests/foundation/config/filesystems/test_filesystems_local.py +66 -18
- tests/foundation/config/filesystems/test_filesystems_public.py +37 -0
- tests/foundation/config/logging/test_logging.py +75 -11
- tests/foundation/config/logging/test_logging_channels.py +79 -2
- tests/foundation/config/logging/test_logging_chunked.py +85 -12
- tests/foundation/config/logging/test_logging_daily.py +79 -12
- tests/foundation/config/logging/test_logging_hourly.py +68 -2
- tests/foundation/config/logging/test_logging_monthly.py +48 -2
- tests/foundation/config/logging/test_logging_stack.py +49 -14
- tests/foundation/config/logging/test_logging_weekly.py +92 -2
- tests/foundation/config/mail/test_mail.py +87 -15
- tests/foundation/config/mail/test_mail_file.py +40 -4
- tests/foundation/config/mail/test_mail_mailers.py +56 -8
- tests/foundation/config/mail/test_mail_smtp.py +58 -14
- tests/foundation/config/queue/test_queue.py +62 -9
- tests/foundation/config/queue/test_queue_brokers.py +27 -10
- tests/foundation/config/queue/test_queue_database.py +53 -15
- tests/foundation/config/root/test_root_paths.py +69 -2
- tests/foundation/config/session/test_session.py +30 -1
- tests/foundation/config/startup/test_config_startup.py +77 -7
- tests/foundation/config/testing/test_testing.py +68 -0
- tests/patterns/singleton/test_singleton.py +10 -1
- tests/services/environment/test_env.py +3 -4
- tests/testing/test_testing_result.py +56 -19
- tests/testing/test_testing_unit.py +93 -24
- orionis/services/environment/exceptions/value_exception.py +0 -27
- {orionis-0.286.0.dist-info → orionis-0.287.0.dist-info}/WHEEL +0 -0
- {orionis-0.286.0.dist-info → orionis-0.287.0.dist-info}/licenses/LICENCE +0 -0
- {orionis-0.286.0.dist-info → orionis-0.287.0.dist-info}/top_level.txt +0 -0
- {orionis-0.286.0.dist-info → orionis-0.287.0.dist-info}/zip-safe +0 -0
orionis/metadata/framework.py
CHANGED
@@ -1,36 +1,47 @@
|
|
1
|
-
from typing import Any, Dict
|
1
|
+
from typing import Any, Dict
|
2
2
|
from abc import ABC, abstractmethod
|
3
3
|
|
4
4
|
class IEnv(ABC):
|
5
|
-
"""Interface contract for environment management operations."""
|
6
5
|
|
7
6
|
@staticmethod
|
8
7
|
@abstractmethod
|
9
|
-
def get(key: str, default:
|
8
|
+
def get(key: str, default: Any = None) -> Any:
|
10
9
|
"""
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
The
|
10
|
+
Retrieve the value of an environment variable by key.
|
11
|
+
|
12
|
+
Parameters
|
13
|
+
----------
|
14
|
+
key : str
|
15
|
+
The name of the environment variable to retrieve.
|
16
|
+
default : Any, optional
|
17
|
+
The value to return if the key is not found. Default is None.
|
18
|
+
|
19
|
+
Returns
|
20
|
+
-------
|
21
|
+
Any
|
22
|
+
The value of the environment variable if found, otherwise the default value.
|
19
23
|
"""
|
20
24
|
pass
|
21
25
|
|
22
26
|
@staticmethod
|
23
27
|
@abstractmethod
|
24
|
-
def set(key: str, value: str) -> bool:
|
28
|
+
def set(key: str, value: str, type: str = None) -> bool:
|
25
29
|
"""
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
Set an environment variable in the .env file.
|
31
|
+
|
32
|
+
Parameters
|
33
|
+
----------
|
34
|
+
key : str
|
35
|
+
The name of the environment variable to set.
|
36
|
+
value : str
|
37
|
+
The value to assign to the environment variable.
|
38
|
+
type : str, optional
|
39
|
+
The type of the environment variable (e.g., 'str', 'int'). Default is None.
|
40
|
+
|
41
|
+
Returns
|
42
|
+
-------
|
43
|
+
bool
|
44
|
+
True if the variable was set successfully, False otherwise.
|
34
45
|
"""
|
35
46
|
pass
|
36
47
|
|
@@ -38,13 +49,17 @@ class IEnv(ABC):
|
|
38
49
|
@abstractmethod
|
39
50
|
def unset(key: str) -> bool:
|
40
51
|
"""
|
41
|
-
|
52
|
+
Remove the specified environment variable from the .env file.
|
42
53
|
|
43
|
-
|
44
|
-
|
54
|
+
Parameters
|
55
|
+
----------
|
56
|
+
key : str
|
57
|
+
The name of the environment variable to remove.
|
45
58
|
|
46
|
-
Returns
|
47
|
-
|
59
|
+
Returns
|
60
|
+
-------
|
61
|
+
bool
|
62
|
+
True if the variable was successfully removed, False otherwise.
|
48
63
|
"""
|
49
64
|
pass
|
50
65
|
|
@@ -52,31 +67,11 @@ class IEnv(ABC):
|
|
52
67
|
@abstractmethod
|
53
68
|
def all() -> Dict[str, Any]:
|
54
69
|
"""
|
55
|
-
|
56
|
-
|
57
|
-
Returns:
|
58
|
-
Dictionary of all key-value pairs
|
59
|
-
"""
|
60
|
-
pass
|
61
|
-
|
62
|
-
@staticmethod
|
63
|
-
@abstractmethod
|
64
|
-
def toJson() -> str:
|
65
|
-
"""
|
66
|
-
Serializes environment to JSON.
|
67
|
-
|
68
|
-
Returns:
|
69
|
-
JSON string representation
|
70
|
-
"""
|
71
|
-
pass
|
72
|
-
|
73
|
-
@staticmethod
|
74
|
-
@abstractmethod
|
75
|
-
def toBase64() -> str:
|
76
|
-
"""
|
77
|
-
Encodes environment to Base64.
|
70
|
+
Retrieve all environment variables as a dictionary.
|
78
71
|
|
79
|
-
Returns
|
80
|
-
|
72
|
+
Returns
|
73
|
+
-------
|
74
|
+
dict of str to Any
|
75
|
+
A dictionary containing all environment variables loaded by DotEnv.
|
81
76
|
"""
|
82
77
|
pass
|
@@ -5,243 +5,267 @@ 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
7
|
from orionis.patterns.singleton.meta_class import Singleton
|
8
|
-
from orionis.services.environment.exceptions.
|
8
|
+
from orionis.services.environment.exceptions.environment_value_exception import OrionisEnvironmentValueException
|
9
|
+
from orionis.services.environment.exceptions.environment_value_error import OrionisEnvironmentValueError
|
10
|
+
from orionis.services.environment.type_hint import EnvTypes
|
9
11
|
|
10
12
|
class DotEnv(metaclass=Singleton):
|
11
|
-
"""
|
12
|
-
DotEnv is a singleton class for managing environment variables using a `.env` file.
|
13
|
-
This class provides methods to load, get, set, unset, and list environment variables,
|
14
|
-
with automatic serialization and deserialization of common Python data types.
|
15
|
-
It ensures that changes to the `.env` file are reflected in the current process's
|
16
|
-
environment variables and vice versa.
|
17
|
-
"""
|
18
13
|
|
14
|
+
# Thread-safe singleton instance lock
|
19
15
|
_lock = threading.RLock()
|
20
16
|
|
21
17
|
def __init__(self, path: str = None) -> None:
|
22
18
|
"""
|
23
|
-
|
19
|
+
Initialize the environment service by resolving the path to the `.env` file, ensuring its existence,
|
24
20
|
and loading environment variables from it.
|
25
|
-
Args:
|
26
|
-
path (str, optional): The path to the `.env` file. If not provided, defaults to a `.env` file
|
27
|
-
in the current working directory.
|
28
|
-
Raises:
|
29
|
-
OSError: If the `.env` file cannot be created when it does not exist.
|
30
|
-
"""
|
31
|
-
|
32
|
-
with self._lock:
|
33
|
-
if path:
|
34
|
-
self._resolved_path = Path(path).expanduser().resolve()
|
35
|
-
else:
|
36
|
-
self._resolved_path = Path(os.getcwd()) / ".env"
|
37
21
|
|
38
|
-
|
39
|
-
|
22
|
+
Parameters
|
23
|
+
----------
|
24
|
+
path : str, optional
|
25
|
+
Path to the `.env` file. If not provided, defaults to a `.env` file
|
26
|
+
in the current working directory.
|
40
27
|
|
41
|
-
|
42
|
-
|
43
|
-
|
28
|
+
Raises
|
29
|
+
------
|
30
|
+
OSError
|
31
|
+
If the `.env` file cannot be created when it does not exist.
|
44
32
|
"""
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
33
|
+
try:
|
34
|
+
with self._lock:
|
35
|
+
if path:
|
36
|
+
self._resolved_path = Path(path).expanduser().resolve()
|
37
|
+
else:
|
38
|
+
self._resolved_path = Path(os.getcwd()) / ".env"
|
51
39
|
|
52
|
-
|
40
|
+
if not self._resolved_path.exists():
|
41
|
+
self._resolved_path.touch()
|
53
42
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
Defaults to None.
|
58
|
-
is_path (bool, optional): If True, the value is treated as a file path and backslashes are replaced with forward slashes.
|
59
|
-
This is useful for Windows paths. Defaults to False.
|
43
|
+
load_dotenv(self._resolved_path)
|
44
|
+
except OSError as e:
|
45
|
+
raise OSError(f"Failed to create or access the .env file at {self._resolved_path}: {e}")
|
60
46
|
|
61
|
-
|
62
|
-
|
47
|
+
def get(self, key: str, default: Optional[Any] = None) -> Any:
|
48
|
+
"""
|
49
|
+
Get the value of an environment variable.
|
50
|
+
|
51
|
+
Parameters
|
52
|
+
----------
|
53
|
+
key : str
|
54
|
+
Name of the environment variable to retrieve.
|
55
|
+
default : Any, optional
|
56
|
+
Value to return if the key is not found. Default is None.
|
57
|
+
|
58
|
+
Returns
|
59
|
+
-------
|
60
|
+
Any
|
61
|
+
Parsed value of the environment variable, or `default` if not found.
|
62
|
+
|
63
|
+
Raises
|
64
|
+
------
|
65
|
+
OrionisEnvironmentValueError
|
66
|
+
If `key` is not a string.
|
63
67
|
"""
|
64
68
|
with self._lock:
|
69
|
+
|
70
|
+
# Ensure the key is a string.
|
71
|
+
if not isinstance(key, str):
|
72
|
+
raise OrionisEnvironmentValueError(
|
73
|
+
f"Key must be a string, got {type(key).__name__}."
|
74
|
+
)
|
75
|
+
|
76
|
+
# Get the value from the .env file or the current environment.
|
65
77
|
value = dotenv_values(self._resolved_path).get(key)
|
78
|
+
|
79
|
+
# If the value is not found in the .env file, check the current environment variables.
|
66
80
|
if value is None:
|
67
81
|
value = os.getenv(key)
|
68
|
-
return self.__parseValue(value, is_path) if value is not None else default
|
69
82
|
|
70
|
-
|
71
|
-
|
72
|
-
Sets an environment variable with the specified key and value.
|
73
|
-
|
74
|
-
This method serializes the given value and updates both the .env file and the current process's environment variables.
|
75
|
-
|
76
|
-
Args:
|
77
|
-
key (str): The name of the environment variable to set.
|
78
|
-
value (Union[str, int, float, bool, list, dict]): The value to assign to the environment variable. Supported types include string, integer, float, boolean, list, and dictionary.
|
79
|
-
is_path (bool, optional): If True, the value is treated as a file path and backslashes are replaced with forward slashes.
|
80
|
-
This is useful for Windows paths. Defaults to False.
|
83
|
+
# Parse the value using the internal __parseValue method and return it
|
84
|
+
return self.__parseValue(value) if value is not None else default
|
81
85
|
|
82
|
-
|
83
|
-
bool: True if the environment variable was successfully set.
|
86
|
+
def __parseValue(self, value: Any) -> Any:
|
84
87
|
"""
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
88
|
+
Parse and convert the input value to an appropriate Python data type with enhanced features.
|
89
|
+
|
90
|
+
Parameters
|
91
|
+
----------
|
92
|
+
value : Any
|
93
|
+
The value to parse and convert.
|
94
|
+
|
95
|
+
Returns
|
96
|
+
-------
|
97
|
+
Any
|
98
|
+
The parsed value, which may be of type None, bool, int, float, list, dict, or str.
|
99
|
+
- Returns None for None, empty strings, or strings like 'none', 'null', 'nan' (case-insensitive).
|
100
|
+
- Returns a boolean for 'true'/'false' strings (case-insensitive) or 1/0.
|
101
|
+
- Returns an int if the string represents an integer.
|
102
|
+
- Returns a float if the string represents a float.
|
103
|
+
- Attempts to evaluate the string as a Python literal (e.g., list, dict, tuple).
|
104
|
+
- Handles type hints via 'type:' prefix (e.g., 'int:42', 'bool:true').
|
105
|
+
- Returns the original string if no conversion is possible.
|
106
|
+
|
107
|
+
Raises
|
108
|
+
------
|
109
|
+
OrionisEnvironmentValueException
|
110
|
+
If type conversion fails for explicitly typed values (e.g., 'abc::int').
|
93
111
|
"""
|
94
|
-
|
112
|
+
# Early return for None
|
113
|
+
if value is None:
|
114
|
+
return None
|
95
115
|
|
96
|
-
|
97
|
-
|
116
|
+
# Return immediately if already a basic type
|
117
|
+
if isinstance(value, (bool, int, float, dict, list, tuple)):
|
118
|
+
return value
|
98
119
|
|
99
|
-
|
100
|
-
|
101
|
-
"""
|
102
|
-
with self._lock:
|
103
|
-
unset_key(str(self._resolved_path), key)
|
104
|
-
os.environ.pop(key, None)
|
105
|
-
return True
|
120
|
+
# Convert to string and clean
|
121
|
+
value_str = str(value).strip()
|
106
122
|
|
107
|
-
|
108
|
-
|
109
|
-
|
123
|
+
# Handle empty strings and common null representations
|
124
|
+
# This includes 'none', 'null', 'nan', 'nil' (case-insensitive)
|
125
|
+
if not value_str or value_str.lower() in {'none', 'null', 'nan', 'nil'}:
|
126
|
+
return None
|
110
127
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
with self._lock:
|
116
|
-
raw_values = dotenv_values(self._resolved_path)
|
117
|
-
return {k: self.__parseValue(v) for k, v in raw_values.items()}
|
128
|
+
# Boolean detection (without type hint)
|
129
|
+
lower_val = value_str.lower()
|
130
|
+
if lower_val in ('true', 'false', 'yes', 'no', 'on', 'off', '1', '0'):
|
131
|
+
return lower_val in ('true', 'yes', 'on', '1')
|
118
132
|
|
119
|
-
|
120
|
-
|
121
|
-
|
133
|
+
# Handle type hints using the Type class
|
134
|
+
hints = EnvTypes(value_str)
|
135
|
+
if hints.hasValidTypeHint():
|
136
|
+
return hints.get()
|
122
137
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
return json.dumps(self.all(), indent=4)
|
138
|
+
# Try parseing to literal types, if failed, return the original value
|
139
|
+
try:
|
140
|
+
return ast.literal_eval(value_str)
|
141
|
+
except (ValueError, SyntaxError):
|
142
|
+
return value_str
|
129
143
|
|
130
|
-
def
|
144
|
+
def set(self, key: str, value: Union[str, int, float, bool, list, dict, tuple, set], type_hint: str = None) -> bool:
|
131
145
|
"""
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
146
|
+
Set an environment variable with the specified key and value.
|
147
|
+
|
148
|
+
Serializes the given value and updates both the .env file and the current process's environment variables.
|
149
|
+
|
150
|
+
Parameters
|
151
|
+
----------
|
152
|
+
key : str
|
153
|
+
The name of the environment variable to set.
|
154
|
+
value : Union[str, int, float, bool, list, dict]
|
155
|
+
The value to assign to the environment variable. Supported types include string, integer, float, boolean, list, and dictionary.
|
156
|
+
type_hint : str, optional
|
157
|
+
The type of the value being set. If provided, it can be (path, str, int, float, bool, list, dict, tuple, set).
|
158
|
+
|
159
|
+
Returns
|
160
|
+
-------
|
161
|
+
bool
|
162
|
+
True if the environment variable was successfully set.
|
136
163
|
"""
|
137
|
-
import base64
|
138
|
-
import json
|
139
164
|
with self._lock:
|
140
|
-
return base64.b64encode(json.dumps(self.all()).encode()).decode()
|
141
|
-
|
142
|
-
def __parseValue(self, value: Any, is_path:bool=False) -> Any:
|
143
|
-
"""
|
144
|
-
Parses and converts the input value to an appropriate Python data type.
|
145
|
-
|
146
|
-
Args:
|
147
|
-
value (Any): The value to parse and convert.
|
148
|
-
|
149
|
-
Returns:
|
150
|
-
Any: The parsed value, which may be of type None, bool, int, float, or the original string.
|
151
|
-
- Returns None for None, empty strings, or strings like 'none', 'null', 'nan' (case-insensitive).
|
152
|
-
- Returns a boolean for 'true'/'false' strings (case-insensitive).
|
153
|
-
- Returns an int if the string represents an integer.
|
154
|
-
- Returns a float if the string represents a float.
|
155
|
-
- Attempts to evaluate the string as a Python literal (e.g., list, dict, tuple).
|
156
|
-
- Returns the original string if no conversion is possible.
|
157
|
-
"""
|
158
|
-
if value is None:
|
159
|
-
return None
|
160
|
-
|
161
|
-
if isinstance(value, (bool, int, float)):
|
162
|
-
return value
|
163
165
|
|
164
|
-
value_str = str(value).strip()
|
165
|
-
if not value_str or value_str.lower() in {'none', 'null', 'nan'}:
|
166
|
-
return None
|
167
166
|
|
168
|
-
|
169
|
-
|
167
|
+
# Ensure the value is a valid type.
|
168
|
+
if not isinstance(value, (str, int, float, bool, list, dict, tuple, set)):
|
169
|
+
raise OrionisEnvironmentValueError(
|
170
|
+
f"Unsupported value type: {type(value).__name__}. Allowed types are str, int, float, bool, list, dict, tuple, set."
|
171
|
+
)
|
170
172
|
|
171
|
-
|
172
|
-
|
173
|
+
# Ensure the type is a string.
|
174
|
+
if not isinstance(type_hint, str):
|
175
|
+
raise OrionisEnvironmentValueError(
|
176
|
+
f"Type hint must be a string, got {type(value).__name__}."
|
177
|
+
)
|
173
178
|
|
174
|
-
|
175
|
-
|
179
|
+
# Ensure the key is a string.
|
180
|
+
if not isinstance(key, str):
|
181
|
+
raise OrionisEnvironmentValueError(
|
182
|
+
f"Key must be a string, got {type(key).__name__}."
|
183
|
+
)
|
176
184
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
pass
|
185
|
+
# Validate the type hint if provided.
|
186
|
+
options = EnvTypes.options()
|
187
|
+
if type_hint and type_hint not in options:
|
188
|
+
raise OrionisEnvironmentValueException(f"Invalid type hint: {type_hint}. Allowed types are {str(options)}.")
|
182
189
|
|
183
|
-
|
184
|
-
|
185
|
-
if '.' in value_str or 'e' in value_str.lower():
|
186
|
-
return float_val
|
187
|
-
except Exception:
|
188
|
-
pass
|
190
|
+
# Serialize the value based on its type.
|
191
|
+
serialized_value = self.__serializeValue(value, type_hint)
|
189
192
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
pass
|
193
|
+
# Set the environment variable in the .env file and the current process environment.
|
194
|
+
set_key(str(self._resolved_path), key, serialized_value)
|
195
|
+
os.environ[key] = str(value)
|
194
196
|
|
195
|
-
|
197
|
+
# Return True to indicate success.
|
198
|
+
return True
|
196
199
|
|
197
|
-
def __serializeValue(self, value: Any,
|
200
|
+
def __serializeValue(self, value: Any, type_hint: str = None) -> str:
|
198
201
|
"""
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
202
|
+
Parameters
|
203
|
+
----------
|
204
|
+
value : Any
|
205
|
+
The value to serialize.
|
206
|
+
type_hint : str, optional
|
207
|
+
An optional type hint to guide serialization.
|
208
|
+
Returns
|
209
|
+
-------
|
210
|
+
str
|
211
|
+
The serialized string representation of the value.
|
212
|
+
Notes
|
213
|
+
-----
|
214
|
+
- If `value` is None, returns "null".
|
215
|
+
- If `type_hint` is provided, uses `EnvTypes` to serialize.
|
216
|
+
- Uses `repr()` for lists, dicts, tuples, and sets.
|
217
|
+
- Falls back to `str()` for other types.
|
211
218
|
"""
|
212
|
-
if is_path:
|
213
|
-
return str(value).replace("\\", "/")
|
214
219
|
|
215
220
|
if value is None:
|
216
|
-
return "
|
221
|
+
return "null"
|
222
|
+
|
223
|
+
if type_hint:
|
224
|
+
return EnvTypes(value).to(type_hint)
|
217
225
|
|
218
226
|
if isinstance(value, str):
|
219
|
-
return value
|
227
|
+
return value.strip()
|
220
228
|
|
221
229
|
if isinstance(value, bool):
|
222
230
|
return str(value).lower()
|
223
231
|
|
224
|
-
if isinstance(value, int):
|
232
|
+
if isinstance(value, int, float):
|
225
233
|
return str(value)
|
226
234
|
|
227
|
-
if isinstance(value,
|
228
|
-
value = str(value)
|
229
|
-
if 'e' in value or 'E' in value:
|
230
|
-
raise OrionisEnvironmentValueException('scientific notation is not supported, use a string instead')
|
231
|
-
return value
|
232
|
-
|
233
|
-
if isinstance(value, (list, dict)):
|
235
|
+
if isinstance(value, (list, dict, tuple, set)):
|
234
236
|
return repr(value)
|
235
237
|
|
236
|
-
|
237
|
-
raise OrionisEnvironmentValueException(f"Type {type(value).__name__} is not serializable for .env")
|
238
|
+
return str(value)
|
238
239
|
|
239
|
-
|
240
|
-
|
240
|
+
def unset(self, key: str) -> bool:
|
241
|
+
"""
|
242
|
+
Remove the specified environment variable from both the .env file and the current process environment.
|
241
243
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
244
|
+
Parameters
|
245
|
+
----------
|
246
|
+
key : str
|
247
|
+
The name of the environment variable to unset.
|
246
248
|
|
247
|
-
|
249
|
+
Returns
|
250
|
+
-------
|
251
|
+
bool
|
252
|
+
True if the operation was successful.
|
253
|
+
"""
|
254
|
+
with self._lock:
|
255
|
+
unset_key(str(self._resolved_path), key)
|
256
|
+
os.environ.pop(key, None)
|
257
|
+
return True
|
258
|
+
|
259
|
+
def all(self) -> dict:
|
260
|
+
"""
|
261
|
+
Retrieve all environment variables from the resolved .env file.
|
262
|
+
|
263
|
+
Returns
|
264
|
+
-------
|
265
|
+
dict
|
266
|
+
Dictionary containing all environment variable key-value pairs,
|
267
|
+
with values parsed using the internal __parseValue method.
|
268
|
+
"""
|
269
|
+
with self._lock:
|
270
|
+
raw_values = dotenv_values(self._resolved_path)
|
271
|
+
return {k: self.__parseValue(v) for k, v in raw_values.items()}
|