orionis 0.692.0__py3-none-any.whl → 0.694.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 +46 -13
- orionis/services/environment/core/dot_env.py +42 -0
- orionis/services/environment/dynamic/caster.py +73 -24
- orionis/services/environment/env.py +101 -45
- orionis/services/environment/helpers/functions.py +4 -4
- {orionis-0.692.0.dist-info → orionis-0.694.0.dist-info}/METADATA +1 -1
- {orionis-0.692.0.dist-info → orionis-0.694.0.dist-info}/RECORD +11 -11
- {orionis-0.692.0.dist-info → orionis-0.694.0.dist-info}/WHEEL +0 -0
- {orionis-0.692.0.dist-info → orionis-0.694.0.dist-info}/licenses/LICENCE +0 -0
- {orionis-0.692.0.dist-info → orionis-0.694.0.dist-info}/top_level.txt +0 -0
orionis/metadata/framework.py
CHANGED
|
@@ -3,40 +3,57 @@ from abc import ABC, abstractmethod
|
|
|
3
3
|
|
|
4
4
|
class IEnv(ABC):
|
|
5
5
|
|
|
6
|
-
@
|
|
6
|
+
@classmethod
|
|
7
7
|
@abstractmethod
|
|
8
|
-
def get(key: str, default: Any = None) -> Any:
|
|
8
|
+
def get(cls, key: str, default: Any = None) -> Any:
|
|
9
9
|
"""
|
|
10
10
|
Retrieves the value of the specified environment variable.
|
|
11
11
|
|
|
12
12
|
Parameters
|
|
13
13
|
----------
|
|
14
14
|
key : str
|
|
15
|
-
The name of the environment variable to retrieve.
|
|
15
|
+
The name of the environment variable to retrieve. Must be a valid
|
|
16
|
+
environment variable name (uppercase, numbers, underscores).
|
|
16
17
|
default : Any, optional
|
|
17
|
-
The value to return if the environment variable is not found.
|
|
18
|
+
The value to return if the environment variable is not found.
|
|
19
|
+
Can be any type (str, int, bool, list, etc.). Defaults to None.
|
|
18
20
|
|
|
19
21
|
Returns
|
|
20
22
|
-------
|
|
21
23
|
Any
|
|
22
|
-
The value of the environment variable if it exists,
|
|
24
|
+
The value of the environment variable if it exists, automatically
|
|
25
|
+
parsed to its appropriate Python type (str, int, float, bool, list, dict, etc.),
|
|
26
|
+
otherwise the default value.
|
|
23
27
|
"""
|
|
24
28
|
pass
|
|
25
29
|
|
|
26
|
-
@
|
|
30
|
+
@classmethod
|
|
27
31
|
@abstractmethod
|
|
28
|
-
def set(key: str, value: str, type: str = None) -> bool:
|
|
32
|
+
def set(cls, key: str, value: str, type: str = None) -> bool:
|
|
29
33
|
"""
|
|
30
34
|
Sets the value of 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 name of the environment variable to set. Must follow the pattern:
|
|
40
|
+
uppercase letters, numbers, and underscores only, starting with a letter.
|
|
41
|
+
Example: 'DATABASE_URL', 'MAX_CONNECTIONS', 'FEATURE_FLAGS'
|
|
36
42
|
value : str
|
|
37
43
|
The value to assign to the environment variable.
|
|
38
44
|
type : str, optional
|
|
39
|
-
|
|
45
|
+
Optional type hint for explicit type casting. Supported types:
|
|
46
|
+
- 'str': String values
|
|
47
|
+
- 'int': Integer values
|
|
48
|
+
- 'float': Floating-point values
|
|
49
|
+
- 'bool': Boolean values (true/false)
|
|
50
|
+
- 'list': List/array values
|
|
51
|
+
- 'dict': Dictionary/object values
|
|
52
|
+
- 'tuple': Tuple values
|
|
53
|
+
- 'set': Set values
|
|
54
|
+
- 'base64': Base64 encoded values
|
|
55
|
+
- 'path': File system path values
|
|
56
|
+
Defaults to None (automatic type detection).
|
|
40
57
|
|
|
41
58
|
Returns
|
|
42
59
|
-------
|
|
@@ -45,9 +62,9 @@ class IEnv(ABC):
|
|
|
45
62
|
"""
|
|
46
63
|
pass
|
|
47
64
|
|
|
48
|
-
@
|
|
65
|
+
@classmethod
|
|
49
66
|
@abstractmethod
|
|
50
|
-
def unset(key: str) -> bool:
|
|
67
|
+
def unset(cls, key: str) -> bool:
|
|
51
68
|
"""
|
|
52
69
|
Removes the specified environment variable from the .env file.
|
|
53
70
|
|
|
@@ -63,9 +80,9 @@ class IEnv(ABC):
|
|
|
63
80
|
"""
|
|
64
81
|
pass
|
|
65
82
|
|
|
66
|
-
@
|
|
83
|
+
@classmethod
|
|
67
84
|
@abstractmethod
|
|
68
|
-
def all() -> Dict[str, Any]:
|
|
85
|
+
def all(cls) -> Dict[str, Any]:
|
|
69
86
|
"""
|
|
70
87
|
Retrieves all environment variables as a dictionary.
|
|
71
88
|
|
|
@@ -74,4 +91,20 @@ class IEnv(ABC):
|
|
|
74
91
|
dict of str to Any
|
|
75
92
|
A dictionary containing all environment variables loaded by DotEnv.
|
|
76
93
|
"""
|
|
94
|
+
pass
|
|
95
|
+
|
|
96
|
+
@classmethod
|
|
97
|
+
@abstractmethod
|
|
98
|
+
def reload(cls) -> bool:
|
|
99
|
+
"""
|
|
100
|
+
Reload environment variables from the .env file.
|
|
101
|
+
|
|
102
|
+
This method forces a refresh of all environment variables from the .env file,
|
|
103
|
+
useful when the file has been modified externally.
|
|
104
|
+
|
|
105
|
+
Returns
|
|
106
|
+
-------
|
|
107
|
+
bool
|
|
108
|
+
True if the reload was successful, False otherwise.
|
|
109
|
+
"""
|
|
77
110
|
pass
|
|
@@ -352,3 +352,45 @@ class DotEnv(metaclass=Singleton):
|
|
|
352
352
|
# Return the original string if parsing fails
|
|
353
353
|
except (ValueError, SyntaxError):
|
|
354
354
|
return value_str
|
|
355
|
+
|
|
356
|
+
def reload(self) -> bool:
|
|
357
|
+
"""
|
|
358
|
+
Reload environment variables from the `.env` file into the current process environment.
|
|
359
|
+
|
|
360
|
+
This method forces a refresh of all environment variables from the `.env` file,
|
|
361
|
+
which is useful when the file has been modified externally and the changes need to be
|
|
362
|
+
reflected in the running process.
|
|
363
|
+
|
|
364
|
+
Returns
|
|
365
|
+
-------
|
|
366
|
+
bool
|
|
367
|
+
Returns True if the environment variables were successfully reloaded from the `.env` file.
|
|
368
|
+
Raises OrionisEnvironmentException if an error occurs during the reload process.
|
|
369
|
+
|
|
370
|
+
Raises
|
|
371
|
+
------
|
|
372
|
+
OrionisEnvironmentException
|
|
373
|
+
If an error occurs while reloading environment variables from the `.env` file.
|
|
374
|
+
|
|
375
|
+
Notes
|
|
376
|
+
-----
|
|
377
|
+
Ensures thread safety during the reload operation by acquiring a lock.
|
|
378
|
+
Uses the `load_dotenv` function with `override=True` to update existing environment variables.
|
|
379
|
+
"""
|
|
380
|
+
try:
|
|
381
|
+
# Ensure thread-safe operation during the reload process
|
|
382
|
+
with self._lock:
|
|
383
|
+
|
|
384
|
+
# Reload environment variables from the .env file into the process environment,
|
|
385
|
+
# overriding any existing values in os.environ
|
|
386
|
+
load_dotenv(self.__resolved_path, override=True)
|
|
387
|
+
|
|
388
|
+
# Indicate successful operation
|
|
389
|
+
return True
|
|
390
|
+
|
|
391
|
+
except Exception as e:
|
|
392
|
+
|
|
393
|
+
# Raise a general error for any exceptions during reload
|
|
394
|
+
raise OrionisEnvironmentException(
|
|
395
|
+
f"An error occurred while reloading environment variables: {e}"
|
|
396
|
+
)
|
|
@@ -483,6 +483,8 @@ class EnvironmentCaster(IEnvironmentCaster):
|
|
|
483
483
|
"""
|
|
484
484
|
Converts the internal value to a string representation with the integer type hint prefix.
|
|
485
485
|
|
|
486
|
+
Now supports conversion from string values to integers for better usability.
|
|
487
|
+
|
|
486
488
|
Returns
|
|
487
489
|
-------
|
|
488
490
|
str
|
|
@@ -492,20 +494,33 @@ class EnvironmentCaster(IEnvironmentCaster):
|
|
|
492
494
|
Raises
|
|
493
495
|
------
|
|
494
496
|
OrionisEnvironmentValueError
|
|
495
|
-
If the internal value
|
|
497
|
+
If the internal value cannot be converted to an integer.
|
|
496
498
|
"""
|
|
497
499
|
|
|
498
|
-
#
|
|
499
|
-
if
|
|
500
|
+
# If the internal value is already an integer, use it directly
|
|
501
|
+
if isinstance(self.__value_raw, int):
|
|
502
|
+
return f"{self.__type_hint}:{str(self.__value_raw)}"
|
|
503
|
+
|
|
504
|
+
# If the internal value is a string, try to convert it to an integer
|
|
505
|
+
if isinstance(self.__value_raw, str):
|
|
506
|
+
try:
|
|
507
|
+
# Strip whitespace and attempt conversion
|
|
508
|
+
converted_value = int(self.__value_raw.strip())
|
|
509
|
+
return f"{self.__type_hint}:{str(converted_value)}"
|
|
510
|
+
except ValueError:
|
|
511
|
+
raise OrionisEnvironmentValueError(
|
|
512
|
+
f"Cannot convert string '{self.__value_raw}' to integer. Value must be a valid integer representation."
|
|
513
|
+
)
|
|
500
514
|
|
|
501
|
-
|
|
515
|
+
# For other types, try direct conversion
|
|
516
|
+
try:
|
|
517
|
+
converted_value = int(self.__value_raw)
|
|
518
|
+
return f"{self.__type_hint}:{str(converted_value)}"
|
|
519
|
+
except (ValueError, TypeError):
|
|
502
520
|
raise OrionisEnvironmentValueError(
|
|
503
|
-
f"Value must be
|
|
521
|
+
f"Value must be convertible to integer, got {type(self.__value_raw).__name__} with value '{self.__value_raw}'."
|
|
504
522
|
)
|
|
505
523
|
|
|
506
|
-
# Return the formatted string with type hint and integer value
|
|
507
|
-
return f"{self.__type_hint}:{str(self.__value_raw)}"
|
|
508
|
-
|
|
509
524
|
def __parseFloat(self):
|
|
510
525
|
"""
|
|
511
526
|
Convert the internal raw value to a float.
|
|
@@ -539,6 +554,8 @@ class EnvironmentCaster(IEnvironmentCaster):
|
|
|
539
554
|
"""
|
|
540
555
|
Converts the internal value to a string representation with the float type hint prefix.
|
|
541
556
|
|
|
557
|
+
Now supports conversion from string values to floats for better usability.
|
|
558
|
+
|
|
542
559
|
Returns
|
|
543
560
|
-------
|
|
544
561
|
str
|
|
@@ -548,20 +565,33 @@ class EnvironmentCaster(IEnvironmentCaster):
|
|
|
548
565
|
Raises
|
|
549
566
|
------
|
|
550
567
|
OrionisEnvironmentValueError
|
|
551
|
-
If the internal value
|
|
568
|
+
If the internal value cannot be converted to a float.
|
|
552
569
|
"""
|
|
553
570
|
|
|
554
|
-
#
|
|
555
|
-
if
|
|
571
|
+
# If the internal value is already a float, use it directly
|
|
572
|
+
if isinstance(self.__value_raw, float):
|
|
573
|
+
return f"{self.__type_hint}:{str(self.__value_raw)}"
|
|
574
|
+
|
|
575
|
+
# If the internal value is a string, try to convert it to a float
|
|
576
|
+
if isinstance(self.__value_raw, str):
|
|
577
|
+
try:
|
|
578
|
+
# Strip whitespace and attempt conversion
|
|
579
|
+
converted_value = float(self.__value_raw.strip())
|
|
580
|
+
return f"{self.__type_hint}:{str(converted_value)}"
|
|
581
|
+
except ValueError:
|
|
582
|
+
raise OrionisEnvironmentValueError(
|
|
583
|
+
f"Cannot convert string '{self.__value_raw}' to float. Value must be a valid floating-point representation."
|
|
584
|
+
)
|
|
556
585
|
|
|
557
|
-
|
|
586
|
+
# For other types (like int), try direct conversion
|
|
587
|
+
try:
|
|
588
|
+
converted_value = float(self.__value_raw)
|
|
589
|
+
return f"{self.__type_hint}:{str(converted_value)}"
|
|
590
|
+
except (ValueError, TypeError):
|
|
558
591
|
raise OrionisEnvironmentValueError(
|
|
559
|
-
f"Value must be
|
|
592
|
+
f"Value must be convertible to float, got {type(self.__value_raw).__name__} with value '{self.__value_raw}'."
|
|
560
593
|
)
|
|
561
594
|
|
|
562
|
-
# Return the formatted string with type hint and float value
|
|
563
|
-
return f"{self.__type_hint}:{str(self.__value_raw)}"
|
|
564
|
-
|
|
565
595
|
def __parseBool(self):
|
|
566
596
|
"""
|
|
567
597
|
Convert the internal raw value to a boolean.
|
|
@@ -601,6 +631,8 @@ class EnvironmentCaster(IEnvironmentCaster):
|
|
|
601
631
|
"""
|
|
602
632
|
Convert the internal value to a string representation with the boolean type hint prefix.
|
|
603
633
|
|
|
634
|
+
Now supports conversion from string values to booleans for better usability.
|
|
635
|
+
|
|
604
636
|
Returns
|
|
605
637
|
-------
|
|
606
638
|
str
|
|
@@ -610,20 +642,37 @@ class EnvironmentCaster(IEnvironmentCaster):
|
|
|
610
642
|
Raises
|
|
611
643
|
------
|
|
612
644
|
OrionisEnvironmentValueError
|
|
613
|
-
If the internal value
|
|
645
|
+
If the internal value cannot be converted to a boolean.
|
|
614
646
|
"""
|
|
615
647
|
|
|
616
|
-
#
|
|
617
|
-
if
|
|
648
|
+
# If the internal value is already a boolean, use it directly
|
|
649
|
+
if isinstance(self.__value_raw, bool):
|
|
650
|
+
return f"{self.__type_hint}:{str(self.__value_raw).lower()}"
|
|
618
651
|
|
|
619
|
-
|
|
652
|
+
# If the internal value is a string, try to convert it to a boolean
|
|
653
|
+
if isinstance(self.__value_raw, str):
|
|
654
|
+
# Strip whitespace and check common boolean representations
|
|
655
|
+
str_value = self.__value_raw.strip().lower()
|
|
656
|
+
|
|
657
|
+
if str_value in ('true', '1', 'yes', 'on', 'enabled'):
|
|
658
|
+
return f"{self.__type_hint}:true"
|
|
659
|
+
elif str_value in ('false', '0', 'no', 'off', 'disabled'):
|
|
660
|
+
return f"{self.__type_hint}:false"
|
|
661
|
+
else:
|
|
662
|
+
raise OrionisEnvironmentValueError(
|
|
663
|
+
f"Cannot convert string '{self.__value_raw}' to boolean. "
|
|
664
|
+
f"Valid representations: true/false, 1/0, yes/no, on/off, enabled/disabled."
|
|
665
|
+
)
|
|
666
|
+
|
|
667
|
+
# For other types, try direct conversion using Python's truthiness
|
|
668
|
+
try:
|
|
669
|
+
boolean_value = bool(self.__value_raw)
|
|
670
|
+
return f"{self.__type_hint}:{str(boolean_value).lower()}"
|
|
671
|
+
except Exception:
|
|
620
672
|
raise OrionisEnvironmentValueError(
|
|
621
|
-
f"Value must be
|
|
673
|
+
f"Value must be convertible to boolean, got {type(self.__value_raw).__name__} with value '{self.__value_raw}'."
|
|
622
674
|
)
|
|
623
675
|
|
|
624
|
-
# Return the formatted string with type hint and boolean value in lowercase
|
|
625
|
-
return f"{self.__type_hint}:{str(self.__value_raw).lower()}"
|
|
626
|
-
|
|
627
676
|
def __parseList(self):
|
|
628
677
|
"""
|
|
629
678
|
Parses the internal raw value and converts it to a Python list.
|
|
@@ -4,91 +4,121 @@ from typing import Any, Dict
|
|
|
4
4
|
|
|
5
5
|
class Env(IEnv):
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
# Shared singleton instance for DotEnv
|
|
8
|
+
_dotenv_instance = None
|
|
9
|
+
|
|
10
|
+
@classmethod
|
|
11
|
+
def _getSingletonInstance(cls):
|
|
12
|
+
"""
|
|
13
|
+
Retrieve the shared DotEnv singleton instance.
|
|
14
|
+
|
|
15
|
+
This method ensures that only one instance of DotEnv is created and reused
|
|
16
|
+
throughout the Env class. If the instance does not exist, it will be created.
|
|
17
|
+
|
|
18
|
+
Returns
|
|
19
|
+
-------
|
|
20
|
+
DotEnv
|
|
21
|
+
The shared DotEnv instance used for environment variable operations.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
# Check if the singleton instance has already been created
|
|
25
|
+
if cls._dotenv_instance is None:
|
|
26
|
+
# Create a new DotEnv instance if it does not exist
|
|
27
|
+
cls._dotenv_instance = DotEnv()
|
|
28
|
+
# Return the existing or newly created DotEnv instance
|
|
29
|
+
return cls._dotenv_instance
|
|
30
|
+
|
|
31
|
+
@classmethod
|
|
32
|
+
def get(cls, key: str, default: Any = None) -> Any:
|
|
9
33
|
"""
|
|
10
34
|
Retrieve the value of an environment variable by its key.
|
|
11
35
|
|
|
12
36
|
Parameters
|
|
13
37
|
----------
|
|
14
38
|
key : str
|
|
15
|
-
The environment variable
|
|
39
|
+
The name of the environment variable to retrieve.
|
|
16
40
|
default : Any, optional
|
|
17
|
-
|
|
41
|
+
The value to return if the environment variable is not found. Defaults to None.
|
|
18
42
|
|
|
19
43
|
Returns
|
|
20
44
|
-------
|
|
21
45
|
Any
|
|
22
|
-
The value of the environment variable if
|
|
46
|
+
The value of the environment variable if it exists, otherwise the provided default value.
|
|
23
47
|
"""
|
|
24
48
|
|
|
25
|
-
#
|
|
26
|
-
dotenv =
|
|
49
|
+
# Get the shared DotEnv singleton instance to access environment variables
|
|
50
|
+
dotenv = cls._getSingletonInstance()
|
|
27
51
|
|
|
28
|
-
#
|
|
52
|
+
# Return the value for the specified key, or the default if the key is not present
|
|
29
53
|
return dotenv.get(key, default)
|
|
30
54
|
|
|
31
|
-
@
|
|
32
|
-
def set(key: str, value: str,
|
|
55
|
+
@classmethod
|
|
56
|
+
def set(cls, key: str, value: str, type: str = None) -> bool:
|
|
33
57
|
"""
|
|
34
58
|
Set or update an environment variable in the .env file.
|
|
35
59
|
|
|
36
60
|
Parameters
|
|
37
61
|
----------
|
|
38
62
|
key : str
|
|
39
|
-
The environment variable
|
|
63
|
+
The name of the environment variable to set or update.
|
|
40
64
|
value : str
|
|
41
65
|
The value to assign to the environment variable.
|
|
42
|
-
|
|
43
|
-
|
|
66
|
+
type : str, optional
|
|
67
|
+
Type hint for the variable. Supported types include 'str', 'int', 'float',
|
|
68
|
+
'bool', 'list', 'dict', 'tuple', 'set', 'base64', and 'path'. Defaults to None.
|
|
44
69
|
|
|
45
70
|
Returns
|
|
46
71
|
-------
|
|
47
72
|
bool
|
|
48
|
-
True if the variable was set successfully,
|
|
73
|
+
Returns True if the environment variable was set or updated successfully,
|
|
74
|
+
otherwise returns False.
|
|
49
75
|
"""
|
|
50
76
|
|
|
51
|
-
#
|
|
52
|
-
dotenv =
|
|
77
|
+
# Retrieve the shared DotEnv singleton instance to access environment variable operations
|
|
78
|
+
dotenv = cls._getSingletonInstance()
|
|
53
79
|
|
|
54
80
|
# Set the environment variable with the specified key, value, and optional type hint
|
|
55
|
-
return dotenv.set(key, value,
|
|
81
|
+
return dotenv.set(key, value, type)
|
|
56
82
|
|
|
57
|
-
@
|
|
58
|
-
def unset(key: str) -> bool:
|
|
83
|
+
@classmethod
|
|
84
|
+
def unset(cls, key: str) -> bool:
|
|
59
85
|
"""
|
|
60
86
|
Remove an environment variable from the .env file.
|
|
61
87
|
|
|
62
88
|
Parameters
|
|
63
89
|
----------
|
|
64
90
|
key : str
|
|
65
|
-
The environment variable
|
|
91
|
+
The name of the environment variable to remove.
|
|
66
92
|
|
|
67
93
|
Returns
|
|
68
94
|
-------
|
|
69
95
|
bool
|
|
70
|
-
True if the variable was removed successfully, False otherwise.
|
|
96
|
+
True if the environment variable was removed successfully, False otherwise.
|
|
71
97
|
"""
|
|
72
98
|
|
|
73
|
-
#
|
|
74
|
-
dotenv =
|
|
99
|
+
# Retrieve the shared DotEnv singleton instance to access environment variable operations
|
|
100
|
+
dotenv = cls._getSingletonInstance()
|
|
75
101
|
|
|
76
|
-
#
|
|
102
|
+
# Attempt to remove the environment variable with the specified key
|
|
77
103
|
return dotenv.unset(key)
|
|
78
104
|
|
|
79
|
-
@
|
|
80
|
-
def all() -> Dict[str, Any]:
|
|
105
|
+
@classmethod
|
|
106
|
+
def all(cls) -> Dict[str, Any]:
|
|
81
107
|
"""
|
|
82
|
-
|
|
108
|
+
Retrieve all environment variables as a dictionary.
|
|
109
|
+
|
|
110
|
+
This method accesses the shared DotEnv singleton instance and returns all loaded
|
|
111
|
+
environment variables in a dictionary format. It is useful for inspecting the
|
|
112
|
+
current environment configuration.
|
|
83
113
|
|
|
84
114
|
Returns
|
|
85
115
|
-------
|
|
86
116
|
dict of str to Any
|
|
87
|
-
|
|
117
|
+
A dictionary containing all environment variables loaded by DotEnv.
|
|
88
118
|
"""
|
|
89
119
|
|
|
90
|
-
#
|
|
91
|
-
dotenv =
|
|
120
|
+
# Retrieve the shared DotEnv singleton instance to access environment variables
|
|
121
|
+
dotenv = cls._getSingletonInstance()
|
|
92
122
|
|
|
93
123
|
# Return all environment variables as a dictionary
|
|
94
124
|
return dotenv.all()
|
|
@@ -96,38 +126,64 @@ class Env(IEnv):
|
|
|
96
126
|
@staticmethod
|
|
97
127
|
def isVirtual() -> bool:
|
|
98
128
|
"""
|
|
99
|
-
|
|
129
|
+
Check if the current Python interpreter is running inside a virtual environment.
|
|
130
|
+
|
|
131
|
+
This method detects whether the Python process is executing within a virtual environment
|
|
132
|
+
by inspecting environment variables, configuration files, and interpreter prefixes.
|
|
100
133
|
|
|
101
134
|
Returns
|
|
102
135
|
-------
|
|
103
136
|
bool
|
|
104
|
-
True if running inside a virtual environment, False
|
|
105
|
-
|
|
106
|
-
Notes
|
|
107
|
-
-----
|
|
108
|
-
This method checks for the presence of common virtual environment indicators:
|
|
109
|
-
- The 'VIRTUAL_ENV' environment variable.
|
|
110
|
-
- The presence of 'pyvenv.cfg' in the parent directories of the Python executable.
|
|
111
|
-
- Differences between sys.prefix and sys.base_prefix (for venv and virtualenv).
|
|
112
|
-
|
|
113
|
-
This approach works for most virtual environment tools, including venv and virtualenv.
|
|
137
|
+
Returns True if the interpreter is running inside a virtual environment, otherwise False.
|
|
114
138
|
"""
|
|
139
|
+
|
|
115
140
|
import sys
|
|
116
141
|
import os
|
|
117
142
|
from pathlib import Path
|
|
118
143
|
|
|
119
|
-
# Check for 'VIRTUAL_ENV' environment variable
|
|
144
|
+
# Check for the 'VIRTUAL_ENV' environment variable, which is set by virtualenv
|
|
120
145
|
if 'VIRTUAL_ENV' in os.environ:
|
|
121
146
|
return True
|
|
122
147
|
|
|
123
|
-
#
|
|
148
|
+
# Search for 'pyvenv.cfg' in the parent directories of the Python executable (used by venv)
|
|
124
149
|
executable = Path(sys.executable).resolve()
|
|
125
150
|
for parent in executable.parents:
|
|
151
|
+
|
|
152
|
+
# If 'pyvenv.cfg' exists in any parent directory, it's likely a venv
|
|
126
153
|
if (parent / 'pyvenv.cfg').exists():
|
|
127
154
|
return True
|
|
128
155
|
|
|
129
|
-
# Compare sys.prefix and sys.base_prefix
|
|
156
|
+
# Compare sys.prefix and sys.base_prefix to detect venv or virtualenv usage
|
|
130
157
|
if hasattr(sys, 'base_prefix') and sys.prefix != sys.base_prefix:
|
|
131
158
|
return True
|
|
132
159
|
|
|
133
|
-
return False
|
|
160
|
+
# If none of the checks indicate a virtual environment, return False
|
|
161
|
+
return False
|
|
162
|
+
|
|
163
|
+
@classmethod
|
|
164
|
+
def reload(cls) -> bool:
|
|
165
|
+
"""
|
|
166
|
+
Reload environment variables from the .env file.
|
|
167
|
+
|
|
168
|
+
This method resets the DotEnv singleton instance and reloads all environment variables
|
|
169
|
+
from the .env file. It is useful when the .env file has been modified externally and
|
|
170
|
+
the latest values need to be reflected in the application.
|
|
171
|
+
|
|
172
|
+
Returns
|
|
173
|
+
-------
|
|
174
|
+
bool
|
|
175
|
+
True if the environment variables were reloaded successfully, False otherwise.
|
|
176
|
+
"""
|
|
177
|
+
|
|
178
|
+
# Reset the singleton instance to ensure a fresh reload of environment variables
|
|
179
|
+
cls._dotenv_instance = None
|
|
180
|
+
|
|
181
|
+
# Create a new DotEnv instance and load the .env file
|
|
182
|
+
dotenv = cls._getSingletonInstance()
|
|
183
|
+
|
|
184
|
+
# Attempt to reload environment variables from the .env file
|
|
185
|
+
try:
|
|
186
|
+
return dotenv.reload()
|
|
187
|
+
except Exception:
|
|
188
|
+
# Return False if an error occurs during reload
|
|
189
|
+
return False
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
from typing import Any
|
|
2
|
-
from orionis.services.environment.
|
|
2
|
+
from orionis.services.environment.env import Env
|
|
3
3
|
|
|
4
4
|
def env(key: str, default: Any = None) -> Any:
|
|
5
5
|
"""
|
|
6
|
-
|
|
6
|
+
Retrieve the value of an environment variable using the Env facade.
|
|
7
7
|
|
|
8
8
|
Parameters
|
|
9
9
|
----------
|
|
@@ -18,5 +18,5 @@ def env(key: str, default: Any = None) -> Any:
|
|
|
18
18
|
The value of the environment variable if it exists, otherwise the specified default value.
|
|
19
19
|
"""
|
|
20
20
|
|
|
21
|
-
#
|
|
22
|
-
return
|
|
21
|
+
# Retrieve the environment variable using the Env singleton instance.
|
|
22
|
+
return Env.get(key, default)
|
|
@@ -207,7 +207,7 @@ orionis/foundation/providers/scheduler_provider.py,sha256=IrPQJwvQVLRm5Qnz0Cxon4
|
|
|
207
207
|
orionis/foundation/providers/testing_provider.py,sha256=eI1p2lUlxl25b5Z487O4nmqLE31CTDb4c3Q21xFadkE,1615
|
|
208
208
|
orionis/foundation/providers/workers_provider.py,sha256=GdHENYV_yGyqmHJHn0DCyWmWId5xWjD48e6Zq2PGCWY,1674
|
|
209
209
|
orionis/metadata/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
210
|
-
orionis/metadata/framework.py,sha256=
|
|
210
|
+
orionis/metadata/framework.py,sha256=2gerr2_ZYR3ENbjFLCLYUUdsc6aKqIik0LL0GAppLmA,4570
|
|
211
211
|
orionis/metadata/package.py,sha256=s1JeGJPwdVh4jO3IOfmpwMuJ_oX6Vf9NL7jgPEQNf5Y,16050
|
|
212
212
|
orionis/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
213
213
|
orionis/services/asynchrony/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -218,20 +218,20 @@ orionis/services/asynchrony/exceptions/__init__.py,sha256=LXjn7TFOVBaHbPFtV87hZ3
|
|
|
218
218
|
orionis/services/asynchrony/exceptions/asynchrony.py,sha256=2MbqDBA5uGtnlXSmJAs6-1Lb4b8cHDXCKrnyRyucby0,407
|
|
219
219
|
orionis/services/encrypter/encrypter.py,sha256=iOR8_rgyye_Mdlp9OY9Zs9UlnA4sfWvItiDWP_7Q4Vg,4073
|
|
220
220
|
orionis/services/environment/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
221
|
-
orionis/services/environment/env.py,sha256=
|
|
221
|
+
orionis/services/environment/env.py,sha256=QOn7g17wITB6rqhObg6MT0ZJ9XyyTqK8YcyIvODHBWw,6733
|
|
222
222
|
orionis/services/environment/contracts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
223
223
|
orionis/services/environment/contracts/caster.py,sha256=OPi82zrvnvVSoOuDfZ89JTYd7cmfW4wSJejTW1azDsc,1180
|
|
224
|
-
orionis/services/environment/contracts/env.py,sha256=
|
|
224
|
+
orionis/services/environment/contracts/env.py,sha256=qpTeP_BAGR70lig2H9wU5yn-kllYp0kSP7zWdyXjelw,3492
|
|
225
225
|
orionis/services/environment/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
226
|
-
orionis/services/environment/core/dot_env.py,sha256=
|
|
226
|
+
orionis/services/environment/core/dot_env.py,sha256=2wr9X_LiHIHYjG3RBffeOgR5FKlVYBLdv90Ud9HyF3s,14350
|
|
227
227
|
orionis/services/environment/dynamic/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
228
|
-
orionis/services/environment/dynamic/caster.py,sha256=
|
|
228
|
+
orionis/services/environment/dynamic/caster.py,sha256=pCR8qj95tFLMcM2AQMFcQMpsw5QuJ6nbMINEi0EvkrM,37066
|
|
229
229
|
orionis/services/environment/enums/__init__.py,sha256=lV7sRtjZk3pUvqp21A_GZFkKPYSY6UHZzlQarkQOBjA,90
|
|
230
230
|
orionis/services/environment/enums/value_type.py,sha256=s-tTLgJLhI-ISmDNRpmEdj69DSmL3mDO1nrjRWAO7fU,1262
|
|
231
231
|
orionis/services/environment/exceptions/__init__.py,sha256=7gTD23tiwO3iUKVlcMWlj5ni3nhl6doDqUSynmaoUDA,415
|
|
232
232
|
orionis/services/environment/exceptions/environment.py,sha256=vTqBtuP-0oF5bpuSnvTLHt0B2dxRsf4P4aqndXMJGT8,3981
|
|
233
233
|
orionis/services/environment/helpers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
234
|
-
orionis/services/environment/helpers/functions.py,sha256=
|
|
234
|
+
orionis/services/environment/helpers/functions.py,sha256=djWeAFVOMi_iWjiej0btYtAz9ao0nyop-JTyTSPQPQA,689
|
|
235
235
|
orionis/services/environment/key/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
236
236
|
orionis/services/environment/key/key_generator.py,sha256=cYf97aPfQZgG-YsTH4H-4uLrD3C8d2fBqZAFp-cEEK0,1746
|
|
237
237
|
orionis/services/environment/validators/__init__.py,sha256=S0Us4_BtKPuOMQZf4uFFqUINB8l6Eb9vJbbxUCzIhfc,135
|
|
@@ -394,8 +394,8 @@ orionis/test/validators/workers.py,sha256=rWcdRexINNEmGaO7mnc1MKUxkHKxrTsVuHgbnI
|
|
|
394
394
|
orionis/test/view/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
395
395
|
orionis/test/view/render.py,sha256=arysoswhkV2vUd2aVMZRPpmH317jaWbgjDpQ_AWQ5AE,5663
|
|
396
396
|
orionis/test/view/report.stub,sha256=QLqqCdRoENr3ECiritRB3DO_MOjRQvgBh5jxZ3Hs1r0,28189
|
|
397
|
-
orionis-0.
|
|
398
|
-
orionis-0.
|
|
399
|
-
orionis-0.
|
|
400
|
-
orionis-0.
|
|
401
|
-
orionis-0.
|
|
397
|
+
orionis-0.694.0.dist-info/licenses/LICENCE,sha256=JhC-z_9mbpUrCfPjcl3DhDA8trNDMzb57cvRSam1avc,1463
|
|
398
|
+
orionis-0.694.0.dist-info/METADATA,sha256=ESXXJBVATkJzTQZLYrlv-7ERbjDQCHGLvi4VrQ4MtJ8,4772
|
|
399
|
+
orionis-0.694.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
400
|
+
orionis-0.694.0.dist-info/top_level.txt,sha256=lyXi6jArpqJ-0zzNqd_uwsH-z9TCEBVBL-pC3Ekv7hU,8
|
|
401
|
+
orionis-0.694.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|