orionis 0.287.0__py3-none-any.whl → 0.288.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/types.py +70 -0
- orionis/services/environment/dot_env.py +11 -13
- orionis/services/environment/{type_hint.py → types.py} +64 -45
- orionis/services/paths/exceptions/not_found_exceptions.py +15 -12
- orionis/services/paths/exceptions/path_value_exceptions.py +13 -10
- orionis/services/standard/contracts/std.py +1 -1
- orionis/services/standard/exceptions/std_value_exception.py +23 -0
- orionis/services/standard/std.py +2 -2
- orionis/services/system/contracts/imports.py +27 -7
- orionis/services/system/contracts/workers.py +8 -3
- orionis/services/system/imports.py +31 -12
- orionis/services/system/runtime_imports.py +33 -23
- orionis/services/system/workers.py +6 -8
- orionis/services/wrapper/dicts/dot_dict.py +82 -41
- orionis/unittesting.py +12 -12
- {orionis-0.287.0.dist-info → orionis-0.288.0.dist-info}/METADATA +1 -1
- {orionis-0.287.0.dist-info → orionis-0.288.0.dist-info}/RECORD +70 -66
- tests/foundation/config/app/{test_app.py → test_foundation_config_app.py} +1 -1
- tests/foundation/config/auth/{test_auth.py → test_foundation_config_auth.py} +1 -1
- tests/foundation/config/cache/{test_cache.py → test_foundation_config_cache.py} +1 -1
- tests/foundation/config/cache/{test_cache_file.py → test_foundation_config_cache_file.py} +1 -1
- tests/foundation/config/cache/{test_cache_stores.py → test_foundation_config_cache_stores.py} +1 -1
- tests/foundation/config/cors/{test_cors.py → test_foundation_config_cors.py} +1 -1
- tests/foundation/config/database/{test_database.py → test_foundation_config_database.py} +1 -1
- tests/foundation/config/database/{test_database_connections.py → test_foundation_config_database_connections.py} +1 -1
- tests/foundation/config/database/{test_database_mysql.py → test_foundation_config_database_mysql.py} +1 -1
- tests/foundation/config/database/{test_database_oracle.py → test_foundation_config_database_oracle.py} +1 -1
- tests/foundation/config/database/{test_database_pgsql.py → test_foundation_config_database_pgsql.py} +1 -1
- tests/foundation/config/database/{test_database_sqlite.py → test_foundation_config_database_sqlite.py} +1 -1
- tests/foundation/config/exceptions/{test_exceptions_integrity.py → test_foundation_config_exceptions.py} +1 -1
- tests/foundation/config/filesystems/{test_filesystems.py → test_foundation_config_filesystems.py} +1 -1
- tests/foundation/config/filesystems/{test_filesystems_aws.py → test_foundation_config_filesystems_aws.py} +1 -1
- tests/foundation/config/filesystems/{test_filesystems_disks.py → test_foundation_config_filesystems_disks.py} +1 -1
- tests/foundation/config/filesystems/{test_filesystems_local.py → test_foundation_config_filesystems_local.py} +1 -1
- tests/foundation/config/filesystems/{test_filesystems_public.py → test_foundation_config_filesystems_public.py} +1 -1
- tests/foundation/config/logging/{test_logging.py → test_foundation_config_logging.py} +1 -1
- tests/foundation/config/logging/{test_logging_channels.py → test_foundation_config_logging_channels.py} +1 -1
- tests/foundation/config/logging/{test_logging_chunked.py → test_foundation_config_logging_chunked.py} +1 -1
- tests/foundation/config/logging/{test_logging_daily.py → test_foundation_config_logging_daily.py} +1 -1
- tests/foundation/config/logging/{test_logging_hourly.py → test_foundation_config_logging_hourly.py} +1 -1
- tests/foundation/config/logging/{test_logging_monthly.py → test_foundation_config_logging_monthly.py} +1 -1
- tests/foundation/config/logging/{test_logging_stack.py → test_foundation_config_logging_stack.py} +1 -1
- tests/foundation/config/logging/{test_logging_weekly.py → test_foundation_config_logging_weekly.py} +1 -1
- tests/foundation/config/mail/{test_mail.py → test_foundation_config_mail.py} +1 -1
- tests/foundation/config/mail/{test_mail_file.py → test_foundation_config_mail_file.py} +1 -1
- tests/foundation/config/mail/{test_mail_mailers.py → test_foundation_config_mail_mailers.py} +1 -1
- tests/foundation/config/mail/{test_mail_smtp.py → test_foundation_config_mail_smtp.py} +1 -1
- tests/foundation/config/queue/{test_queue.py → test_foundation_config_queue.py} +1 -1
- tests/foundation/config/queue/{test_queue_brokers.py → test_foundation_config_queue_brokers.py} +1 -1
- tests/foundation/config/queue/{test_queue_database.py → test_foundation_config_queue_database.py} +1 -1
- tests/foundation/config/root/{test_root_paths.py → test_foundation_config_root_paths.py} +1 -1
- tests/foundation/config/session/{test_session.py → test_foundation_config_session.py} +1 -1
- tests/foundation/config/startup/{test_config_startup.py → test_foundation_config_startup.py} +14 -14
- tests/foundation/config/testing/{test_testing.py → test_foundation_config_testing.py} +1 -1
- tests/patterns/singleton/{test_singleton.py → test_patterns_singleton.py} +1 -1
- tests/services/asynchrony/{test_async_io.py → test_services_asynchrony_coroutine.py} +1 -1
- tests/services/environment/test_services_environment.py +93 -0
- tests/services/path/{test_resolver.py → test_services_resolver.py} +51 -12
- tests/services/standard/{test_std.py → test_services_std.py} +45 -22
- tests/services/system/__init__.py +0 -0
- tests/services/system/test_services_system_imports.py +101 -0
- tests/services/system/test_services_system_workers.py +89 -0
- tests/services/wrapper/{test_wrapper_doc_dict.py → test_services_wrapper_docdict.py} +28 -16
- tests/testing/test_testing_result.py +1 -1
- tests/testing/test_testing_unit.py +16 -16
- orionis/services/standard/exceptions/path_value_exceptions.py +0 -28
- tests/services/environment/test_env.py +0 -154
- {orionis-0.287.0.dist-info → orionis-0.288.0.dist-info}/WHEEL +0 -0
- {orionis-0.287.0.dist-info → orionis-0.288.0.dist-info}/licenses/LICENCE +0 -0
- {orionis-0.287.0.dist-info → orionis-0.288.0.dist-info}/top_level.txt +0 -0
- {orionis-0.287.0.dist-info → orionis-0.288.0.dist-info}/zip-safe +0 -0
orionis/metadata/framework.py
CHANGED
@@ -0,0 +1,70 @@
|
|
1
|
+
from abc import ABC, abstractmethod
|
2
|
+
|
3
|
+
class IEnvTypes(ABC):
|
4
|
+
|
5
|
+
@abstractmethod
|
6
|
+
def to(self, type_hint: str):
|
7
|
+
"""
|
8
|
+
Set the type hint for the Type instance.
|
9
|
+
|
10
|
+
Parameters
|
11
|
+
----------
|
12
|
+
type_hint : str
|
13
|
+
The type hint to set, which must be one of the valid options defined in OPTIONS.
|
14
|
+
|
15
|
+
Raises
|
16
|
+
------
|
17
|
+
OrionisEnvironmentValueError
|
18
|
+
If the provided type hint is not one of the valid options.
|
19
|
+
"""
|
20
|
+
pass
|
21
|
+
|
22
|
+
@abstractmethod
|
23
|
+
def hasValidTypeHint(self) -> bool:
|
24
|
+
"""
|
25
|
+
Check if the type hint is valid.
|
26
|
+
|
27
|
+
Returns
|
28
|
+
-------
|
29
|
+
bool
|
30
|
+
True if the type hint is valid (exists in the OPTIONS set), False otherwise.
|
31
|
+
"""
|
32
|
+
pass
|
33
|
+
|
34
|
+
@abstractmethod
|
35
|
+
def explode(self) -> tuple:
|
36
|
+
"""
|
37
|
+
Returns a tuple containing the type hint and value string.
|
38
|
+
|
39
|
+
Returns
|
40
|
+
-------
|
41
|
+
tuple
|
42
|
+
A tuple (type_hint, value_str) where:
|
43
|
+
type_hint : str or None
|
44
|
+
The extracted type hint in lowercase, or None if not provided.
|
45
|
+
value_str : str or None
|
46
|
+
The extracted value string, or None if not provided.
|
47
|
+
"""
|
48
|
+
pass
|
49
|
+
|
50
|
+
@abstractmethod
|
51
|
+
def get(self):
|
52
|
+
"""
|
53
|
+
Returns the value corresponding to the specified type hint.
|
54
|
+
|
55
|
+
Checks if the provided type hint is valid and then dispatches the call to the appropriate
|
56
|
+
method for handling the type.
|
57
|
+
|
58
|
+
Supported type hints include: 'path:', 'str:', 'int:', 'float:', 'bool:', 'list:', 'dict:', 'tuple:', and 'set:'.
|
59
|
+
|
60
|
+
Returns
|
61
|
+
-------
|
62
|
+
Any
|
63
|
+
The value converted or processed according to the specified type hint.
|
64
|
+
|
65
|
+
Raises
|
66
|
+
------
|
67
|
+
OrionisEnvironmentValueError
|
68
|
+
If the type hint is not one of the supported options.
|
69
|
+
"""
|
70
|
+
pass
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import os
|
2
2
|
import ast
|
3
|
+
import re
|
3
4
|
import threading
|
4
5
|
from pathlib import Path
|
5
6
|
from typing import Any, Optional, Union
|
@@ -7,7 +8,7 @@ from dotenv import dotenv_values, load_dotenv, set_key, unset_key
|
|
7
8
|
from orionis.patterns.singleton.meta_class import Singleton
|
8
9
|
from orionis.services.environment.exceptions.environment_value_exception import OrionisEnvironmentValueException
|
9
10
|
from orionis.services.environment.exceptions.environment_value_error import OrionisEnvironmentValueError
|
10
|
-
from orionis.services.environment.
|
11
|
+
from orionis.services.environment.types import EnvTypes
|
11
12
|
|
12
13
|
class DotEnv(metaclass=Singleton):
|
13
14
|
|
@@ -114,7 +115,7 @@ class DotEnv(metaclass=Singleton):
|
|
114
115
|
return None
|
115
116
|
|
116
117
|
# Return immediately if already a basic type
|
117
|
-
if isinstance(value, (bool, int, float, dict, list, tuple)):
|
118
|
+
if isinstance(value, (bool, int, float, dict, list, tuple, set)):
|
118
119
|
return value
|
119
120
|
|
120
121
|
# Convert to string and clean
|
@@ -163,6 +164,11 @@ class DotEnv(metaclass=Singleton):
|
|
163
164
|
"""
|
164
165
|
with self._lock:
|
165
166
|
|
167
|
+
# Ensure the key is a string.
|
168
|
+
if not isinstance(key, str) or not re.match(r'^[A-Z][A-Z0-9_]*$', key):
|
169
|
+
raise OrionisEnvironmentValueError(
|
170
|
+
f"The environment variable name '{key}' is not valid. It must be an uppercase string, may contain numbers and underscores, and must always start with a letter. Example of a valid name: 'MY_ENV_VAR'."
|
171
|
+
)
|
166
172
|
|
167
173
|
# Ensure the value is a valid type.
|
168
174
|
if not isinstance(value, (str, int, float, bool, list, dict, tuple, set)):
|
@@ -170,17 +176,9 @@ class DotEnv(metaclass=Singleton):
|
|
170
176
|
f"Unsupported value type: {type(value).__name__}. Allowed types are str, int, float, bool, list, dict, tuple, set."
|
171
177
|
)
|
172
178
|
|
173
|
-
#
|
174
|
-
if
|
175
|
-
|
176
|
-
f"Type hint must be a string, got {type(value).__name__}."
|
177
|
-
)
|
178
|
-
|
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
|
-
)
|
179
|
+
# Dinamically determine the type hint if not provided.
|
180
|
+
if isinstance(value, (int, float, bool, list, dict, tuple, set)) and not type_hint:
|
181
|
+
type_hint = type(value).__name__.lower()
|
184
182
|
|
185
183
|
# Validate the type hint if provided.
|
186
184
|
options = EnvTypes.options()
|
@@ -1,7 +1,8 @@
|
|
1
|
+
from orionis.services.environment.contracts.types import IEnvTypes
|
1
2
|
from orionis.services.environment.exceptions.environment_value_error import OrionisEnvironmentValueError
|
2
3
|
from orionis.services.environment.exceptions.environment_value_exception import OrionisEnvironmentValueException
|
3
4
|
|
4
|
-
class EnvTypes:
|
5
|
+
class EnvTypes(IEnvTypes):
|
5
6
|
|
6
7
|
# Type class to handle different types of environment variables
|
7
8
|
OPTIONS = {
|
@@ -28,7 +29,7 @@ class EnvTypes:
|
|
28
29
|
"""
|
29
30
|
return EnvTypes.OPTIONS
|
30
31
|
|
31
|
-
def __init__(self, raw
|
32
|
+
def __init__(self, raw):
|
32
33
|
"""
|
33
34
|
Parse a raw string input into a type hint and value string.
|
34
35
|
|
@@ -46,13 +47,31 @@ class EnvTypes:
|
|
46
47
|
__value_str : str or None
|
47
48
|
The extracted value string, or None if not provided.
|
48
49
|
"""
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
|
51
|
+
# Default values for type hint and value string
|
52
|
+
self.__type_hint = None
|
53
|
+
self.__value_raw = None
|
54
|
+
|
55
|
+
# If raw is a string, parse it to extract type hint and value
|
56
|
+
if isinstance(raw, str):
|
57
|
+
|
58
|
+
# Strip whitespace and check for a colon to separate type hint and value
|
59
|
+
self.__value_raw = raw.strip()
|
60
|
+
|
61
|
+
# If a colon is present, split the string into type hint and value
|
62
|
+
if ':' in self.__value_raw:
|
63
|
+
|
64
|
+
# Split the string at the first colon
|
65
|
+
type_hint, value_str = raw.split(':', 1)
|
66
|
+
|
67
|
+
# If the type hint is valid, set it and the value
|
68
|
+
if type_hint.strip().lower() in self.OPTIONS:
|
69
|
+
self.__type_hint = type_hint.strip().lower()
|
70
|
+
self.__value_raw = value_str.strip() if value_str else None
|
53
71
|
else:
|
54
|
-
|
55
|
-
|
72
|
+
|
73
|
+
# If raw is not a string, treat it as a value with no type hint
|
74
|
+
self.__value_raw = raw
|
56
75
|
|
57
76
|
def to(self, type_hint: str):
|
58
77
|
"""
|
@@ -127,7 +146,7 @@ class EnvTypes:
|
|
127
146
|
value_str : str or None
|
128
147
|
The extracted value string, or None if not provided.
|
129
148
|
"""
|
130
|
-
return self.__type_hint, self.
|
149
|
+
return self.__type_hint, self.__value_raw
|
131
150
|
|
132
151
|
def __parsePath(self):
|
133
152
|
"""
|
@@ -147,7 +166,7 @@ class EnvTypes:
|
|
147
166
|
OrionisEnvironmentValueException
|
148
167
|
If the value cannot be processed as a path.
|
149
168
|
"""
|
150
|
-
return self.
|
169
|
+
return self.__value_raw.replace('\\', '/').strip()
|
151
170
|
|
152
171
|
def __toPath(self):
|
153
172
|
"""
|
@@ -163,9 +182,9 @@ class EnvTypes:
|
|
163
182
|
OrionisEnvironmentValueError
|
164
183
|
If the internal value is not a string.
|
165
184
|
"""
|
166
|
-
if not isinstance(self.
|
167
|
-
raise OrionisEnvironmentValueError(f"Value must be a string to convert to path, got {type(self.
|
168
|
-
value = self.
|
185
|
+
if not isinstance(self.__value_raw, str):
|
186
|
+
raise OrionisEnvironmentValueError(f"Value must be a string to convert to path, got {type(self.__value_raw).__name__} instead.")
|
187
|
+
value = self.__value_raw.replace('\\', '/').strip()
|
169
188
|
return f"{self.__type_hint}:{value}"
|
170
189
|
|
171
190
|
def __parseStr(self):
|
@@ -177,7 +196,7 @@ class EnvTypes:
|
|
177
196
|
str
|
178
197
|
The value string if the type hint is 'str:', otherwise raises an error.
|
179
198
|
"""
|
180
|
-
return self.
|
199
|
+
return self.__value_raw.strip()
|
181
200
|
|
182
201
|
def __toStr(self):
|
183
202
|
"""
|
@@ -193,9 +212,9 @@ class EnvTypes:
|
|
193
212
|
OrionisEnvironmentValueError
|
194
213
|
If the internal value is not a string.
|
195
214
|
"""
|
196
|
-
if not isinstance(self.
|
197
|
-
raise OrionisEnvironmentValueError(f"Value must be a string to convert to str, got {type(self.
|
198
|
-
return f"{self.__type_hint}:{self.
|
215
|
+
if not isinstance(self.__value_raw, str):
|
216
|
+
raise OrionisEnvironmentValueError(f"Value must be a string to convert to str, got {type(self.__value_raw).__name__} instead.")
|
217
|
+
return f"{self.__type_hint}:{self.__value_raw}"
|
199
218
|
|
200
219
|
def __parseInt(self):
|
201
220
|
"""
|
@@ -215,7 +234,7 @@ class EnvTypes:
|
|
215
234
|
OrionisEnvironmentValueException
|
216
235
|
If the value cannot be converted to an integer.
|
217
236
|
"""
|
218
|
-
value = self.
|
237
|
+
value = self.__value_raw.strip()
|
219
238
|
try:
|
220
239
|
return int(value)
|
221
240
|
except ValueError as e:
|
@@ -235,9 +254,9 @@ class EnvTypes:
|
|
235
254
|
OrionisEnvironmentValueError
|
236
255
|
If the internal value is not a string or cannot be converted to an integer.
|
237
256
|
"""
|
238
|
-
if not isinstance(self.
|
239
|
-
raise OrionisEnvironmentValueError(f"Value must be an integer to convert to int, got {type(self.
|
240
|
-
return f"{self.__type_hint}:{str(self.
|
257
|
+
if not isinstance(self.__value_raw, int):
|
258
|
+
raise OrionisEnvironmentValueError(f"Value must be an integer to convert to int, got {type(self.__value_raw).__name__} instead.")
|
259
|
+
return f"{self.__type_hint}:{str(self.__value_raw)}"
|
241
260
|
|
242
261
|
def __parseFloat(self):
|
243
262
|
"""
|
@@ -257,7 +276,7 @@ class EnvTypes:
|
|
257
276
|
OrionisEnvironmentValueException
|
258
277
|
If the value cannot be converted to a float.
|
259
278
|
"""
|
260
|
-
value = self.
|
279
|
+
value = self.__value_raw.strip()
|
261
280
|
try:
|
262
281
|
return float(value)
|
263
282
|
except ValueError as e:
|
@@ -277,9 +296,9 @@ class EnvTypes:
|
|
277
296
|
OrionisEnvironmentValueError
|
278
297
|
If the internal value is not a string or cannot be converted to a float.
|
279
298
|
"""
|
280
|
-
if not isinstance(self.
|
281
|
-
raise OrionisEnvironmentValueError(f"Value must be a float to convert to float, got {type(self.
|
282
|
-
return f"{self.__type_hint}:{str(self.
|
299
|
+
if not isinstance(self.__value_raw, float):
|
300
|
+
raise OrionisEnvironmentValueError(f"Value must be a float to convert to float, got {type(self.__value_raw).__name__} instead.")
|
301
|
+
return f"{self.__type_hint}:{str(self.__value_raw)}"
|
283
302
|
|
284
303
|
def __parseBool(self):
|
285
304
|
"""
|
@@ -299,7 +318,7 @@ class EnvTypes:
|
|
299
318
|
OrionisEnvironmentValueException
|
300
319
|
If the value cannot be converted to a boolean.
|
301
320
|
"""
|
302
|
-
value = self.
|
321
|
+
value = self.__value_raw.strip().lower()
|
303
322
|
if value in {'true', '1', 'yes', 'on'}:
|
304
323
|
return True
|
305
324
|
elif value in {'false', '0', 'no', 'off'}:
|
@@ -321,9 +340,9 @@ class EnvTypes:
|
|
321
340
|
OrionisEnvironmentValueError
|
322
341
|
If the internal value is not a boolean.
|
323
342
|
"""
|
324
|
-
if not isinstance(self.
|
325
|
-
raise OrionisEnvironmentValueError(f"Value must be a boolean to convert to bool, got {type(self.
|
326
|
-
return f"{self.__type_hint}:{str(self.
|
343
|
+
if not isinstance(self.__value_raw, bool):
|
344
|
+
raise OrionisEnvironmentValueError(f"Value must be a boolean to convert to bool, got {type(self.__value_raw).__name__} instead.")
|
345
|
+
return f"{self.__type_hint}:{str(self.__value_raw).lower()}"
|
327
346
|
|
328
347
|
def __parseList(self):
|
329
348
|
"""
|
@@ -341,7 +360,7 @@ class EnvTypes:
|
|
341
360
|
"""
|
342
361
|
import ast
|
343
362
|
|
344
|
-
value = self.
|
363
|
+
value = self.__value_raw.strip()
|
345
364
|
try:
|
346
365
|
parsed = ast.literal_eval(value)
|
347
366
|
if not isinstance(parsed, list):
|
@@ -364,9 +383,9 @@ class EnvTypes:
|
|
364
383
|
OrionisEnvironmentValueError
|
365
384
|
If the internal value is not a list.
|
366
385
|
"""
|
367
|
-
if not isinstance(self.
|
368
|
-
raise OrionisEnvironmentValueError(f"Value must be a list to convert to list, got {type(self.
|
369
|
-
return f"{self.__type_hint}:{repr(self.
|
386
|
+
if not isinstance(self.__value_raw, list):
|
387
|
+
raise OrionisEnvironmentValueError(f"Value must be a list to convert to list, got {type(self.__value_raw).__name__} instead.")
|
388
|
+
return f"{self.__type_hint}:{repr(self.__value_raw)}"
|
370
389
|
|
371
390
|
def __parseDict(self):
|
372
391
|
"""
|
@@ -388,7 +407,7 @@ class EnvTypes:
|
|
388
407
|
"""
|
389
408
|
import ast
|
390
409
|
|
391
|
-
value = self.
|
410
|
+
value = self.__value_raw.strip()
|
392
411
|
try:
|
393
412
|
parsed = ast.literal_eval(value)
|
394
413
|
if not isinstance(parsed, dict):
|
@@ -411,9 +430,9 @@ class EnvTypes:
|
|
411
430
|
OrionisEnvironmentValueError
|
412
431
|
If the internal value is not a dict.
|
413
432
|
"""
|
414
|
-
if not isinstance(self.
|
415
|
-
raise OrionisEnvironmentValueError(f"Value must be a dict to convert to dict, got {type(self.
|
416
|
-
return f"{self.__type_hint}:{repr(self.
|
433
|
+
if not isinstance(self.__value_raw, dict):
|
434
|
+
raise OrionisEnvironmentValueError(f"Value must be a dict to convert to dict, got {type(self.__value_raw).__name__} instead.")
|
435
|
+
return f"{self.__type_hint}:{repr(self.__value_raw)}"
|
417
436
|
|
418
437
|
def __parseTuple(self):
|
419
438
|
"""
|
@@ -435,7 +454,7 @@ class EnvTypes:
|
|
435
454
|
"""
|
436
455
|
import ast
|
437
456
|
|
438
|
-
value = self.
|
457
|
+
value = self.__value_raw.strip()
|
439
458
|
try:
|
440
459
|
parsed = ast.literal_eval(value)
|
441
460
|
if not isinstance(parsed, tuple):
|
@@ -458,9 +477,9 @@ class EnvTypes:
|
|
458
477
|
OrionisEnvironmentValueError
|
459
478
|
If the internal value is not a tuple.
|
460
479
|
"""
|
461
|
-
if not isinstance(self.
|
462
|
-
raise OrionisEnvironmentValueError(f"Value must be a tuple to convert to tuple, got {type(self.
|
463
|
-
return f"{self.__type_hint}:{repr(self.
|
480
|
+
if not isinstance(self.__value_raw, tuple):
|
481
|
+
raise OrionisEnvironmentValueError(f"Value must be a tuple to convert to tuple, got {type(self.__value_raw).__name__} instead.")
|
482
|
+
return f"{self.__type_hint}:{repr(self.__value_raw)}"
|
464
483
|
|
465
484
|
def __parseSet(self):
|
466
485
|
"""
|
@@ -482,7 +501,7 @@ class EnvTypes:
|
|
482
501
|
"""
|
483
502
|
import ast
|
484
503
|
|
485
|
-
value = self.
|
504
|
+
value = self.__value_raw.strip()
|
486
505
|
try:
|
487
506
|
parsed = ast.literal_eval(value)
|
488
507
|
if not isinstance(parsed, set):
|
@@ -505,9 +524,9 @@ class EnvTypes:
|
|
505
524
|
OrionisEnvironmentValueError
|
506
525
|
If the internal value is not a set.
|
507
526
|
"""
|
508
|
-
if not isinstance(self.
|
509
|
-
raise OrionisEnvironmentValueError(f"Value must be a set to convert to set, got {type(self.
|
510
|
-
return f"{self.__type_hint}:{repr(self.
|
527
|
+
if not isinstance(self.__value_raw, set):
|
528
|
+
raise OrionisEnvironmentValueError(f"Value must be a set to convert to set, got {type(self.__value_raw).__name__} instead.")
|
529
|
+
return f"{self.__type_hint}:{repr(self.__value_raw)}"
|
511
530
|
|
512
531
|
def get(self):
|
513
532
|
"""
|
@@ -1,28 +1,31 @@
|
|
1
1
|
class OrionisFileNotFoundException(Exception):
|
2
2
|
"""
|
3
|
-
Exception raised when a file is not found
|
3
|
+
Exception raised when a specified file is not found.
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
raise OrionisFileNotFoundException("File 'config.yaml' not found.")
|
5
|
+
Parameters
|
6
|
+
----------
|
7
|
+
msg : str
|
8
|
+
The error message describing the exception.
|
10
9
|
"""
|
11
10
|
|
12
11
|
def __init__(self, msg: str):
|
13
12
|
"""
|
14
|
-
|
13
|
+
Initialize the exception with a custom error message.
|
15
14
|
|
16
|
-
|
17
|
-
|
15
|
+
Parameters
|
16
|
+
----------
|
17
|
+
msg : str
|
18
|
+
The error message describing the exception.
|
18
19
|
"""
|
19
20
|
super().__init__(msg)
|
20
21
|
|
21
22
|
def __str__(self) -> str:
|
22
23
|
"""
|
23
|
-
Return a string representation of the exception
|
24
|
+
Return a string representation of the exception.
|
24
25
|
|
25
|
-
Returns
|
26
|
-
|
26
|
+
Returns
|
27
|
+
-------
|
28
|
+
str
|
29
|
+
A formatted string with the exception class name and the first argument.
|
27
30
|
"""
|
28
31
|
return f"{self.__class__.__name__}: {self.args[0]}"
|
@@ -2,19 +2,20 @@ class OrionisPathValueException(Exception):
|
|
2
2
|
"""
|
3
3
|
Exception raised when a file is not found in the Orionis framework.
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
raise OrionisFileNotFoundException("File 'config.yaml' not found.")
|
5
|
+
Parameters
|
6
|
+
----------
|
7
|
+
msg : str
|
8
|
+
A detailed message describing the missing file.
|
10
9
|
"""
|
11
10
|
|
12
11
|
def __init__(self, msg: str):
|
13
12
|
"""
|
14
|
-
|
13
|
+
Initialize the exception with a custom error message.
|
15
14
|
|
16
|
-
|
17
|
-
|
15
|
+
Parameters
|
16
|
+
----------
|
17
|
+
msg : str
|
18
|
+
The error message describing the exception.
|
18
19
|
"""
|
19
20
|
super().__init__(msg)
|
20
21
|
|
@@ -22,7 +23,9 @@ class OrionisPathValueException(Exception):
|
|
22
23
|
"""
|
23
24
|
Return a string representation of the exception, including the class name and the first argument.
|
24
25
|
|
25
|
-
Returns
|
26
|
-
|
26
|
+
Returns
|
27
|
+
-------
|
28
|
+
str
|
29
|
+
A formatted string with the exception class name and the first argument.
|
27
30
|
"""
|
28
31
|
return f"{self.__class__.__name__}: {self.args[0]}"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class OrionisStdValueException(Exception):
|
2
|
+
|
3
|
+
def __init__(self, msg: str):
|
4
|
+
"""
|
5
|
+
Initialize the exception with a custom error message.
|
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
|
+
Return a string representation of the exception, including the class name and the first argument.
|
17
|
+
|
18
|
+
Returns
|
19
|
+
-------
|
20
|
+
str
|
21
|
+
A formatted string with the exception class name and the first argument.
|
22
|
+
"""
|
23
|
+
return f"{self.__class__.__name__}: {self.args[0]}"
|
orionis/services/standard/std.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
from orionis.services.standard.contracts.std import IStdClass
|
2
|
-
from orionis.services.standard.exceptions.
|
2
|
+
from orionis.services.standard.exceptions.std_value_exception import OrionisStdValueException
|
3
3
|
|
4
4
|
class StdClass(IStdClass):
|
5
5
|
"""
|
@@ -112,7 +112,7 @@ class StdClass(IStdClass):
|
|
112
112
|
delattr(self, attr)
|
113
113
|
|
114
114
|
@classmethod
|
115
|
-
def
|
115
|
+
def fromDict(cls, dictionary):
|
116
116
|
"""
|
117
117
|
Creates a StdClass instance from a dictionary.
|
118
118
|
|
@@ -3,29 +3,49 @@ from abc import ABC, abstractmethod
|
|
3
3
|
class IImports(ABC):
|
4
4
|
"""
|
5
5
|
Interface for a utility to collect and display information about currently loaded Python modules.
|
6
|
+
|
7
|
+
Methods
|
8
|
+
-------
|
9
|
+
collect()
|
10
|
+
Collects information about user-defined Python modules currently loaded in sys.modules.
|
11
|
+
|
12
|
+
display()
|
13
|
+
Displays a formatted table of collected import statements.
|
14
|
+
|
15
|
+
clear()
|
16
|
+
Clears the collected imports list.
|
6
17
|
"""
|
7
18
|
|
8
19
|
@abstractmethod
|
9
20
|
def collect(self):
|
10
21
|
"""
|
11
|
-
|
12
|
-
|
13
|
-
|
22
|
+
Collect information about user-defined Python modules currently loaded in sys.modules.
|
23
|
+
|
24
|
+
Returns
|
25
|
+
-------
|
26
|
+
IImports
|
27
|
+
The current instance with updated imports information.
|
14
28
|
"""
|
15
29
|
pass
|
16
30
|
|
17
31
|
@abstractmethod
|
18
32
|
def display(self) -> None:
|
19
33
|
"""
|
20
|
-
|
21
|
-
|
22
|
-
|
34
|
+
Display a formatted table of collected import statements.
|
35
|
+
|
36
|
+
Returns
|
37
|
+
-------
|
38
|
+
None
|
23
39
|
"""
|
24
40
|
pass
|
25
41
|
|
26
42
|
@abstractmethod
|
27
43
|
def clear(self) -> None:
|
28
44
|
"""
|
29
|
-
|
45
|
+
Clear the collected imports list.
|
46
|
+
|
47
|
+
Returns
|
48
|
+
-------
|
49
|
+
None
|
30
50
|
"""
|
31
51
|
pass
|
@@ -2,17 +2,22 @@ from abc import ABC, abstractmethod
|
|
2
2
|
|
3
3
|
class IWorkers(ABC):
|
4
4
|
"""
|
5
|
-
Interface
|
5
|
+
Interface for calculating the optimal number of workers a machine can handle based on CPU and memory resources.
|
6
|
+
|
7
|
+
Notes
|
8
|
+
-----
|
9
|
+
Implementations should provide logic to determine the recommended number of worker processes
|
10
|
+
according to the available CPU and memory resources of the current machine.
|
6
11
|
"""
|
7
12
|
|
8
13
|
@abstractmethod
|
9
14
|
def calculate(self) -> int:
|
10
15
|
"""
|
11
|
-
|
16
|
+
Compute the maximum number of workers supported by the current machine.
|
12
17
|
|
13
18
|
Returns
|
14
19
|
-------
|
15
20
|
int
|
16
|
-
|
21
|
+
Recommended number of worker processes based on CPU and memory limits.
|
17
22
|
"""
|
18
23
|
pass
|