orionis 0.66.0__py3-none-any.whl → 0.70.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/contracts/services/environment/__init__.py +0 -0
- orionis/contracts/services/environment/i_environment_service.py +74 -0
- orionis/contracts/services/files/{i_path_service.py → i_path_resolver_service.py} +1 -3
- orionis/framework.py +1 -1
- orionis/luminate/app.py +21 -3
- orionis/luminate/bootstrap/environment_bootstrapper.py +4 -66
- orionis/luminate/bootstrap/service_providers_bootstrapper.py +10 -0
- orionis/luminate/facades/app.py +41 -0
- orionis/luminate/facades/config/config_facade.py +5 -7
- orionis/luminate/facades/environment/environment_facade.py +19 -62
- orionis/luminate/facades/files/path_facade.py +4 -3
- orionis/luminate/facades/log/log_facade.py +11 -6
- orionis/luminate/providers/config/config_service_provider.py +6 -13
- orionis/luminate/providers/environment/__init__.py +0 -0
- orionis/luminate/providers/environment/environment_provider.py +19 -0
- orionis/luminate/providers/log/log_service_provider.py +6 -13
- orionis/luminate/providers/service_provider.py +51 -0
- orionis/luminate/services/environment/__init__.py +0 -0
- orionis/luminate/services/environment/environment_service.py +131 -0
- orionis/luminate/services/files/path_resolver_service.py +59 -0
- {orionis-0.66.0.dist-info → orionis-0.70.0.dist-info}/METADATA +1 -1
- {orionis-0.66.0.dist-info → orionis-0.70.0.dist-info}/RECORD +26 -17
- orionis/luminate/services/files/path_service.py +0 -91
- {orionis-0.66.0.dist-info → orionis-0.70.0.dist-info}/LICENCE +0 -0
- {orionis-0.66.0.dist-info → orionis-0.70.0.dist-info}/WHEEL +0 -0
- {orionis-0.66.0.dist-info → orionis-0.70.0.dist-info}/entry_points.txt +0 -0
- {orionis-0.66.0.dist-info → orionis-0.70.0.dist-info}/top_level.txt +0 -0
File without changes
|
@@ -0,0 +1,74 @@
|
|
1
|
+
from abc import ABC, abstractmethod
|
2
|
+
|
3
|
+
class IEnvironmentService(ABC):
|
4
|
+
|
5
|
+
@abstractmethod
|
6
|
+
def _initialize(self, path: str = None):
|
7
|
+
"""
|
8
|
+
Initializes the instance by setting the path to the .env file.
|
9
|
+
If no path is provided, defaults to a `.env` file in the current directory.
|
10
|
+
|
11
|
+
Parameters
|
12
|
+
----------
|
13
|
+
path : str, optional
|
14
|
+
Path to the .env file. Defaults to None.
|
15
|
+
"""
|
16
|
+
pass
|
17
|
+
|
18
|
+
@abstractmethod
|
19
|
+
def get(self, key: str, default=None) -> str:
|
20
|
+
"""
|
21
|
+
Retrieves the value of an environment variable from the .env file
|
22
|
+
or from system environment variables if not found.
|
23
|
+
|
24
|
+
Parameters
|
25
|
+
----------
|
26
|
+
key : str
|
27
|
+
The key of the environment variable.
|
28
|
+
default : optional
|
29
|
+
Default value if the key does not exist. Defaults to None.
|
30
|
+
|
31
|
+
Returns
|
32
|
+
-------
|
33
|
+
str
|
34
|
+
The value of the environment variable or the default value.
|
35
|
+
"""
|
36
|
+
pass
|
37
|
+
|
38
|
+
@abstractmethod
|
39
|
+
def set(self, key: str, value: str) -> None:
|
40
|
+
"""
|
41
|
+
Sets the value of an environment variable in the .env file.
|
42
|
+
|
43
|
+
Parameters
|
44
|
+
----------
|
45
|
+
key : str
|
46
|
+
The key of the environment variable.
|
47
|
+
value : str
|
48
|
+
The value to set.
|
49
|
+
"""
|
50
|
+
pass
|
51
|
+
|
52
|
+
@abstractmethod
|
53
|
+
def unset(self, key: str) -> None:
|
54
|
+
"""
|
55
|
+
Removes an environment variable from the .env file.
|
56
|
+
|
57
|
+
Parameters
|
58
|
+
----------
|
59
|
+
key : str
|
60
|
+
The key of the environment variable to remove.
|
61
|
+
"""
|
62
|
+
pass
|
63
|
+
|
64
|
+
@abstractmethod
|
65
|
+
def all(self) -> dict:
|
66
|
+
"""
|
67
|
+
Retrieves all environment variable values from the .env file.
|
68
|
+
|
69
|
+
Returns
|
70
|
+
-------
|
71
|
+
dict
|
72
|
+
A dictionary of all environment variables and their values.
|
73
|
+
"""
|
74
|
+
pass
|
orionis/framework.py
CHANGED
orionis/luminate/app.py
CHANGED
@@ -1,33 +1,51 @@
|
|
1
|
-
import json
|
2
1
|
from orionis.luminate.container.container import Container
|
3
2
|
from orionis.luminate.bootstrap.config_bootstrapper import ConfigBootstrapper
|
4
3
|
from orionis.luminate.bootstrap.command_bootstrapper import CommandsBootstrapper
|
5
4
|
from orionis.luminate.bootstrap.environment_bootstrapper import EnvironmentBootstrapper
|
6
5
|
from orionis.luminate.patterns.singleton import SingletonMeta
|
6
|
+
from orionis.luminate.providers.environment.environment_provider import EnvironmentProvider
|
7
7
|
|
8
8
|
class Application(metaclass=SingletonMeta):
|
9
9
|
|
10
10
|
def __init__(self):
|
11
11
|
|
12
|
+
# Atributos de la clase
|
12
13
|
self._config = {}
|
13
14
|
self._commands = {}
|
15
|
+
self._environment = {}
|
14
16
|
|
17
|
+
# Inicializar el contenedor de la aplicacion
|
15
18
|
self.container = Container()
|
16
19
|
self.container.instance(self.container)
|
20
|
+
|
21
|
+
# Cargar el servidor de entorno
|
22
|
+
self._loadServiceProviderEnvironment()
|
23
|
+
|
24
|
+
# Cargar dinamicamente la configurcion de la aplicacion.
|
17
25
|
self._bootstraping()
|
18
26
|
|
27
|
+
def _loadServiceProviderEnvironment(self):
|
28
|
+
|
29
|
+
# Cargar el proveedor de entorno
|
30
|
+
_environment_provider = EnvironmentProvider(app=self.container)
|
31
|
+
_environment_provider.register()
|
32
|
+
_environment_provider.boot()
|
33
|
+
|
19
34
|
def _bootstraping(self):
|
35
|
+
|
36
|
+
# Cargar la configuracion de la aplicacion
|
20
37
|
config_bootstrapper_key = self.container.singleton(ConfigBootstrapper)
|
21
38
|
config_bootstrapper: ConfigBootstrapper = self.container.make(config_bootstrapper_key)
|
22
39
|
self._config = config_bootstrapper.get()
|
23
40
|
|
41
|
+
# Cargar los comandos propios y definidos por el desarrollador
|
24
42
|
commands_bootstrapper_key = self.container.singleton(CommandsBootstrapper)
|
25
43
|
commands_bootstrapper: CommandsBootstrapper = self.container.make(commands_bootstrapper_key)
|
26
44
|
self._commands = commands_bootstrapper.get()
|
27
45
|
|
46
|
+
# Cargar las variables de entorno solo desde el archivo .env (No se carga desde el sistema operativo, por seguridad)
|
28
47
|
environment_bootstrapper_key = self.container.singleton(EnvironmentBootstrapper)
|
29
48
|
environment_bootstrapper: EnvironmentBootstrapper = self.container.make(environment_bootstrapper_key)
|
30
49
|
self._environment = environment_bootstrapper.get()
|
31
50
|
|
32
|
-
|
33
|
-
return True
|
51
|
+
print(self._config)
|
@@ -1,10 +1,7 @@
|
|
1
|
-
import ast
|
2
|
-
import os
|
3
|
-
from pathlib import Path
|
4
1
|
from typing import Dict
|
5
|
-
from dotenv import dotenv_values
|
6
2
|
from orionis.contracts.bootstrap.i_environment_bootstrapper import IEnvironmentBootstrapper
|
7
|
-
from orionis.luminate.
|
3
|
+
from orionis.luminate.facades.app import app
|
4
|
+
from orionis.luminate.services.environment.environment_service import EnvironmentService
|
8
5
|
|
9
6
|
class EnvironmentBootstrapper(IEnvironmentBootstrapper):
|
10
7
|
"""
|
@@ -46,68 +43,9 @@ class EnvironmentBootstrapper(IEnvironmentBootstrapper):
|
|
46
43
|
This method checks if the `.env` file exists in the current working directory.
|
47
44
|
If the file does not exist, it creates an empty `.env` file. If the file exists,
|
48
45
|
it loads the environment variables into the `_environment_vars` dictionary.
|
49
|
-
|
50
|
-
Raises
|
51
|
-
------
|
52
|
-
PermissionError
|
53
|
-
If the `.env` file cannot be created or read due to insufficient permissions.
|
54
46
|
"""
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
# Create the `.env` file if it does not exist
|
59
|
-
if not path.exists():
|
60
|
-
try:
|
61
|
-
path.touch() # Create an empty `.env` file if it does not exist
|
62
|
-
except PermissionError as e:
|
63
|
-
raise PermissionError(f"Cannot create `.env` file at {path}: {str(e)}")
|
64
|
-
|
65
|
-
try:
|
66
|
-
all_vars = dotenv_values(path)
|
67
|
-
for key, value in all_vars.items():
|
68
|
-
self._environment_vars[key] = self._parse_value(value)
|
69
|
-
except Exception as e:
|
70
|
-
raise BootstrapRuntimeError(f"Error loading environment variables from {path}: {str(e)}")
|
71
|
-
|
72
|
-
def _parse_value(self, value):
|
73
|
-
"""
|
74
|
-
Parse and convert a string value into its appropriate Python data type.
|
75
|
-
|
76
|
-
This function handles conversion for common types such as `None`, booleans (`True`/`False`),
|
77
|
-
integers, and Python literals (e.g., lists, dictionaries). If the value cannot be parsed
|
78
|
-
into a specific type, it is returned as-is.
|
79
|
-
|
80
|
-
Parameters
|
81
|
-
----------
|
82
|
-
value : str or None
|
83
|
-
The value to be parsed. If `None`, it is returned as `None`.
|
84
|
-
|
85
|
-
Returns
|
86
|
-
-------
|
87
|
-
any
|
88
|
-
The parsed value. Possible return types include:
|
89
|
-
- `None` if the value is empty, `None`, `'None'`, or `'null'`.
|
90
|
-
- `bool` if the value is `'True'`, `'true'`, `'False'`, or `'false'`.
|
91
|
-
- `int` if the value is a digit string (e.g., `'123'`).
|
92
|
-
- Python literals (e.g., lists, dictionaries) if the value can be evaluated as such.
|
93
|
-
- The original value if no conversion is applicable.
|
94
|
-
"""
|
95
|
-
# Strip leading and trailing whitespace from the value
|
96
|
-
value = str(value).strip() if value is not None else None
|
97
|
-
|
98
|
-
# Parse common types and Python literals
|
99
|
-
if not value or value.lower() in {'none', 'null'}:
|
100
|
-
return None
|
101
|
-
if value.lower() in {'true', 'false'}:
|
102
|
-
return value.lower() == 'true'
|
103
|
-
if value.isdigit():
|
104
|
-
return int(value)
|
105
|
-
|
106
|
-
# Attempt to parse Python literals (e.g., lists, dictionaries)
|
107
|
-
try:
|
108
|
-
return ast.literal_eval(value)
|
109
|
-
except (ValueError, SyntaxError):
|
110
|
-
return value
|
47
|
+
environment_service : EnvironmentService = app(EnvironmentService)
|
48
|
+
self._environment_vars = environment_service.all()
|
111
49
|
|
112
50
|
def get(self, key: str = None) -> str:
|
113
51
|
"""
|
@@ -0,0 +1,41 @@
|
|
1
|
+
from typing import Any
|
2
|
+
from orionis.luminate.container.container import Container
|
3
|
+
from orionis.luminate.container.exception import OrionisContainerException, OrionisContainerTypeError
|
4
|
+
|
5
|
+
def app(concrete: Any = None):
|
6
|
+
"""
|
7
|
+
Retrieves the container instance or resolves a service from the container.
|
8
|
+
|
9
|
+
If a `concrete` class or service is passed, it will check if it is bound
|
10
|
+
to the container and return an instance of the service. If not bound,
|
11
|
+
an exception will be raised.
|
12
|
+
|
13
|
+
Parameters
|
14
|
+
----------
|
15
|
+
concrete : Any, optional
|
16
|
+
The concrete service or class to resolve from the container.
|
17
|
+
If None, returns the container instance itself.
|
18
|
+
|
19
|
+
Returns
|
20
|
+
-------
|
21
|
+
Container or Any
|
22
|
+
If `concrete` is provided and bound, returns the resolved service.
|
23
|
+
If `concrete` is None, returns the container instance.
|
24
|
+
|
25
|
+
Raises
|
26
|
+
------
|
27
|
+
OrionisContainerException
|
28
|
+
If `concrete` is not bound to the container.
|
29
|
+
"""
|
30
|
+
|
31
|
+
# Create a new container instance
|
32
|
+
container : Container = Container()
|
33
|
+
|
34
|
+
# If concrete is provided (not None), attempt to resolve it from the container
|
35
|
+
if concrete is not None:
|
36
|
+
if not isinstance(concrete, type):
|
37
|
+
raise OrionisContainerTypeError(f"The provided concrete must be a class or service, got {type(concrete)}.")
|
38
|
+
return container.make(concrete)
|
39
|
+
|
40
|
+
# If concrete is None, return the container instance
|
41
|
+
return container
|
@@ -1,6 +1,6 @@
|
|
1
1
|
from typing import Any, Optional
|
2
2
|
from orionis.contracts.facades.config.i_config_facade import IConfig
|
3
|
-
from orionis.luminate.
|
3
|
+
from orionis.luminate.facades.app import app
|
4
4
|
from orionis.luminate.services.config.config_service import ConfigService
|
5
5
|
|
6
6
|
class Config(IConfig):
|
@@ -17,9 +17,8 @@ class Config(IConfig):
|
|
17
17
|
value : Any
|
18
18
|
The value to set.
|
19
19
|
"""
|
20
|
-
|
21
|
-
|
22
|
-
config_service.set(key, value)
|
20
|
+
_config_service_provider : ConfigService = app(ConfigService)
|
21
|
+
return _config_service_provider.set(key, value)
|
23
22
|
|
24
23
|
@staticmethod
|
25
24
|
def get(key: str, default: Optional[Any] = None) -> Any:
|
@@ -38,6 +37,5 @@ class Config(IConfig):
|
|
38
37
|
Any
|
39
38
|
The configuration value or the default value if the key is not found.
|
40
39
|
"""
|
41
|
-
|
42
|
-
|
43
|
-
return config_service.get(key, default)
|
40
|
+
_config_service_provider : ConfigService = app(ConfigService)
|
41
|
+
return _config_service_provider.get(key, default)
|
@@ -1,8 +1,6 @@
|
|
1
|
-
import os
|
2
|
-
import threading
|
3
|
-
from pathlib import Path
|
4
|
-
from dotenv import set_key, unset_key, dotenv_values
|
5
1
|
from orionis.contracts.facades.environment.i_environment_facade import IEnv
|
2
|
+
from orionis.luminate.facades.app import app
|
3
|
+
from orionis.luminate.services.environment.environment_service import EnvironmentService
|
6
4
|
|
7
5
|
def env(key: str, default=None) -> str:
|
8
6
|
"""
|
@@ -26,55 +24,13 @@ def env(key: str, default=None) -> str:
|
|
26
24
|
The value of the environment variable, or the default value if the variable
|
27
25
|
does not exist.
|
28
26
|
"""
|
29
|
-
return Env
|
27
|
+
return Env.get(key, default)
|
30
28
|
|
31
29
|
class Env(IEnv):
|
32
|
-
"""
|
33
|
-
A thread-safe singleton class that manages environment variables from a .env file.
|
34
|
-
"""
|
35
|
-
|
36
|
-
_instance = None
|
37
|
-
_lock = threading.Lock()
|
38
|
-
|
39
|
-
def __new__(cls, path: str = None):
|
40
|
-
"""
|
41
|
-
Override the __new__ method to ensure only one instance of the class is created.
|
42
|
-
|
43
|
-
Parameters
|
44
|
-
----------
|
45
|
-
path : str, optional
|
46
|
-
The path to the .env file. Defaults to None.
|
47
|
-
|
48
|
-
Returns
|
49
|
-
-------
|
50
|
-
Environment
|
51
|
-
The singleton instance of the Environment class.
|
52
|
-
"""
|
53
|
-
# Use the lock to ensure thread-safe instantiation
|
54
|
-
with cls._lock:
|
55
|
-
if cls._instance is None:
|
56
|
-
cls._instance = super().__new__(cls)
|
57
|
-
cls._instance._initialize(path)
|
58
|
-
return cls._instance
|
59
|
-
|
60
|
-
def _initialize(self, path: str = None):
|
61
|
-
"""
|
62
|
-
Initializes the instance by setting the path to the .env file.
|
63
|
-
If no path is provided, defaults to a `.env` file in the current directory.
|
64
|
-
|
65
|
-
Parameters
|
66
|
-
----------
|
67
|
-
path : str, optional
|
68
|
-
Path to the .env file. Defaults to None.
|
69
|
-
"""
|
70
|
-
# Set the path to the .env file
|
71
|
-
self.path = Path(path) if path else Path(os.getcwd()) / ".env"
|
72
30
|
|
73
|
-
# Create the .env file if it does not exist
|
74
|
-
if not self.path.exists():
|
75
|
-
self.path.touch()
|
76
31
|
|
77
|
-
|
32
|
+
@staticmethod
|
33
|
+
def get(key: str, default=None) -> str:
|
78
34
|
"""
|
79
35
|
Retrieves the value of an environment variable from the .env file
|
80
36
|
or from system environment variables if not found.
|
@@ -91,13 +47,12 @@ class Env(IEnv):
|
|
91
47
|
str
|
92
48
|
The value of the environment variable or the default value.
|
93
49
|
"""
|
94
|
-
# Get the value from the .env file
|
95
|
-
value = dotenv_values(self.path).get(key)
|
96
50
|
|
97
|
-
|
98
|
-
return
|
51
|
+
_env_service : EnvironmentService = app(EnvironmentService)
|
52
|
+
return _env_service.get(key, default)
|
99
53
|
|
100
|
-
|
54
|
+
@staticmethod
|
55
|
+
def set(key: str, value: str) -> None:
|
101
56
|
"""
|
102
57
|
Sets the value of an environment variable in the .env file.
|
103
58
|
|
@@ -108,10 +63,11 @@ class Env(IEnv):
|
|
108
63
|
value : str
|
109
64
|
The value to set.
|
110
65
|
"""
|
111
|
-
|
112
|
-
|
66
|
+
_env_service : EnvironmentService = app(EnvironmentService)
|
67
|
+
return _env_service.set(key, value)
|
113
68
|
|
114
|
-
|
69
|
+
@staticmethod
|
70
|
+
def unset(key: str) -> None:
|
115
71
|
"""
|
116
72
|
Removes an environment variable from the .env file.
|
117
73
|
|
@@ -120,10 +76,11 @@ class Env(IEnv):
|
|
120
76
|
key : str
|
121
77
|
The key of the environment variable to remove.
|
122
78
|
"""
|
123
|
-
|
124
|
-
|
79
|
+
_env_service : EnvironmentService = app(EnvironmentService)
|
80
|
+
return _env_service.unset(key)
|
125
81
|
|
126
|
-
|
82
|
+
@staticmethod
|
83
|
+
def all() -> dict:
|
127
84
|
"""
|
128
85
|
Retrieves all environment variable values from the .env file.
|
129
86
|
|
@@ -132,5 +89,5 @@ class Env(IEnv):
|
|
132
89
|
dict
|
133
90
|
A dictionary of all environment variables and their values.
|
134
91
|
"""
|
135
|
-
|
136
|
-
return
|
92
|
+
_env_service : EnvironmentService = app(EnvironmentService)
|
93
|
+
return _env_service.all()
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import os
|
2
2
|
from orionis.contracts.facades.files.i_path_facade import IPath
|
3
|
-
from orionis.luminate.services.files.
|
3
|
+
from orionis.luminate.services.files.path_resolver_service import PathResolverService
|
4
4
|
|
5
5
|
class Path(IPath):
|
6
6
|
"""
|
@@ -64,8 +64,9 @@ class Path(IPath):
|
|
64
64
|
# Normalize path (removes redundant slashes)
|
65
65
|
route = os.path.normpath(route)
|
66
66
|
|
67
|
-
#
|
68
|
-
|
67
|
+
# Resolve path (Note: The service container is not used here)
|
68
|
+
path_resolver_service = PathResolverService()
|
69
|
+
return path_resolver_service.resolve(route)
|
69
70
|
|
70
71
|
@staticmethod
|
71
72
|
def app(file: str = None):
|
@@ -1,5 +1,5 @@
|
|
1
1
|
from orionis.contracts.facades.log.i_log_facade import ILog
|
2
|
-
from orionis.luminate.
|
2
|
+
from orionis.luminate.facades.app import app
|
3
3
|
from orionis.luminate.services.log.log_service import LogguerService
|
4
4
|
|
5
5
|
class Log(ILog):
|
@@ -34,7 +34,8 @@ class Log(ILog):
|
|
34
34
|
message : str
|
35
35
|
The message to log.
|
36
36
|
"""
|
37
|
-
|
37
|
+
_log_service : LogguerService = app(LogguerService)
|
38
|
+
return _log_service.info(message)
|
38
39
|
|
39
40
|
@staticmethod
|
40
41
|
def error(message: str) -> None:
|
@@ -46,7 +47,8 @@ class Log(ILog):
|
|
46
47
|
message : str
|
47
48
|
The message to log.
|
48
49
|
"""
|
49
|
-
|
50
|
+
_log_service : LogguerService = app(LogguerService)
|
51
|
+
return _log_service.error(message)
|
50
52
|
|
51
53
|
@staticmethod
|
52
54
|
def success(message: str) -> None:
|
@@ -58,7 +60,8 @@ class Log(ILog):
|
|
58
60
|
message : str
|
59
61
|
The message to log.
|
60
62
|
"""
|
61
|
-
|
63
|
+
_log_service : LogguerService = app(LogguerService)
|
64
|
+
return _log_service.success(message)
|
62
65
|
|
63
66
|
@staticmethod
|
64
67
|
def warning(message: str) -> None:
|
@@ -70,7 +73,8 @@ class Log(ILog):
|
|
70
73
|
message : str
|
71
74
|
The message to log.
|
72
75
|
"""
|
73
|
-
|
76
|
+
_log_service : LogguerService = app(LogguerService)
|
77
|
+
return _log_service.warning(message)
|
74
78
|
|
75
79
|
@staticmethod
|
76
80
|
def debug(message: str) -> None:
|
@@ -82,4 +86,5 @@ class Log(ILog):
|
|
82
86
|
message : str
|
83
87
|
The message to log.
|
84
88
|
"""
|
85
|
-
|
89
|
+
_log_service : LogguerService = app(LogguerService)
|
90
|
+
return _log_service.debug(message)
|
@@ -1,26 +1,19 @@
|
|
1
|
-
from orionis.
|
2
|
-
from orionis.luminate.container.container import Container
|
1
|
+
from orionis.luminate.providers.service_provider import ServiceProvider
|
3
2
|
from orionis.luminate.services.config.config_service import ConfigService
|
4
3
|
|
5
|
-
class ConfigServiceProvider(
|
4
|
+
class ConfigServiceProvider(ServiceProvider):
|
6
5
|
|
7
|
-
def register(self,
|
6
|
+
def register(self,) -> None:
|
8
7
|
"""
|
9
8
|
Registers services or bindings into the given container.
|
10
|
-
|
11
|
-
Args:
|
12
|
-
container (Container): The container to register services or bindings into.
|
13
9
|
"""
|
14
|
-
self.
|
10
|
+
self._container_id = self.app.scoped(ConfigService)
|
15
11
|
|
16
|
-
def boot(self,
|
12
|
+
def boot(self,) -> None:
|
17
13
|
"""
|
18
14
|
Boot the service provider.
|
19
15
|
|
20
16
|
This method is intended to be overridden by subclasses to perform
|
21
17
|
any necessary bootstrapping or initialization tasks.
|
22
|
-
|
23
|
-
Args:
|
24
|
-
container (Container): The service container instance.
|
25
18
|
"""
|
26
|
-
|
19
|
+
self.app.make(self._container_id)
|
File without changes
|
@@ -0,0 +1,19 @@
|
|
1
|
+
from orionis.luminate.providers.service_provider import ServiceProvider
|
2
|
+
from orionis.luminate.services.environment.environment_service import EnvironmentService
|
3
|
+
|
4
|
+
class EnvironmentProvider(ServiceProvider):
|
5
|
+
|
6
|
+
def register(self) -> None:
|
7
|
+
"""
|
8
|
+
Registers services or bindings into the given container.
|
9
|
+
"""
|
10
|
+
self._container_id = self.app.singleton(EnvironmentService)
|
11
|
+
|
12
|
+
def boot(self) -> None:
|
13
|
+
"""
|
14
|
+
Boot the service provider.
|
15
|
+
|
16
|
+
This method is intended to be overridden by subclasses to perform
|
17
|
+
any necessary bootstrapping or initialization tasks.
|
18
|
+
"""
|
19
|
+
self.app.make(self._container_id)
|
@@ -1,26 +1,19 @@
|
|
1
|
-
from orionis.
|
2
|
-
from orionis.luminate.container.container import Container
|
1
|
+
from orionis.luminate.providers.service_provider import ServiceProvider
|
3
2
|
from orionis.luminate.services.log.log_service import LogguerService
|
4
3
|
|
5
|
-
class LogServiceProvider(
|
4
|
+
class LogServiceProvider(ServiceProvider):
|
6
5
|
|
7
|
-
def register(self
|
6
|
+
def register(self) -> None:
|
8
7
|
"""
|
9
8
|
Registers services or bindings into the given container.
|
10
|
-
|
11
|
-
Args:
|
12
|
-
container (Container): The container to register services or bindings into.
|
13
9
|
"""
|
14
|
-
self.
|
10
|
+
self._container_id = self.app.singleton(LogguerService)
|
15
11
|
|
16
|
-
def boot(self
|
12
|
+
def boot(self) -> None:
|
17
13
|
"""
|
18
14
|
Boot the service provider.
|
19
15
|
|
20
16
|
This method is intended to be overridden by subclasses to perform
|
21
17
|
any necessary bootstrapping or initialization tasks.
|
22
|
-
|
23
|
-
Args:
|
24
|
-
container (Container): The service container instance.
|
25
18
|
"""
|
26
|
-
|
19
|
+
self.app.make(self._container_id)
|
@@ -0,0 +1,51 @@
|
|
1
|
+
from orionis.contracts.providers.i_service_provider import IServiceProvider
|
2
|
+
from orionis.luminate.container.container import Container
|
3
|
+
|
4
|
+
class ServiceProvider(IServiceProvider):
|
5
|
+
"""
|
6
|
+
Base class for service providers.
|
7
|
+
|
8
|
+
Parameters
|
9
|
+
----------
|
10
|
+
container : Container
|
11
|
+
The container instance to be used by the service provider.
|
12
|
+
"""
|
13
|
+
|
14
|
+
def __init__(self, app : Container) -> None:
|
15
|
+
"""
|
16
|
+
Initialize the service provider with the given container.
|
17
|
+
|
18
|
+
Parameters
|
19
|
+
----------
|
20
|
+
container : Container
|
21
|
+
The container instance to be used by the service provider.
|
22
|
+
"""
|
23
|
+
self.app = app
|
24
|
+
|
25
|
+
def register(self) -> None:
|
26
|
+
"""
|
27
|
+
Register services in the container.
|
28
|
+
|
29
|
+
This method should be overridden in the subclass to register
|
30
|
+
specific services.
|
31
|
+
|
32
|
+
Parameters
|
33
|
+
----------
|
34
|
+
container : Container
|
35
|
+
The container instance where services will be registered.
|
36
|
+
"""
|
37
|
+
raise NotImplementedError("This method should be overridden in the subclass")
|
38
|
+
|
39
|
+
def boot(self) -> None:
|
40
|
+
"""
|
41
|
+
Boot services in the container.
|
42
|
+
|
43
|
+
This method should be overridden in the subclass to boot
|
44
|
+
specific services.
|
45
|
+
|
46
|
+
Parameters
|
47
|
+
----------
|
48
|
+
container : Container
|
49
|
+
The container instance where services will be booted.
|
50
|
+
"""
|
51
|
+
raise NotImplementedError("This method should be overridden in the subclass")
|
File without changes
|
@@ -0,0 +1,131 @@
|
|
1
|
+
import ast
|
2
|
+
import os
|
3
|
+
from pathlib import Path
|
4
|
+
from typing import Any
|
5
|
+
from dotenv import set_key, unset_key, dotenv_values
|
6
|
+
from orionis.contracts.services.environment.i_environment_service import IEnvironmentService
|
7
|
+
|
8
|
+
class EnvironmentService(IEnvironmentService):
|
9
|
+
|
10
|
+
def __init__(self, path: str = None):
|
11
|
+
|
12
|
+
"""
|
13
|
+
Initializes the EnvironmentService instance.
|
14
|
+
|
15
|
+
Parameters
|
16
|
+
----------
|
17
|
+
path : str, optional
|
18
|
+
The path to the .env file. Defaults to None.
|
19
|
+
"""
|
20
|
+
self._initialize(path)
|
21
|
+
|
22
|
+
def _initialize(self, path: str = None):
|
23
|
+
"""
|
24
|
+
Initializes the instance by setting the path to the .env file.
|
25
|
+
If no path is provided, defaults to a `.env` file in the current directory.
|
26
|
+
|
27
|
+
Parameters
|
28
|
+
----------
|
29
|
+
path : str, optional
|
30
|
+
Path to the .env file. Defaults to None.
|
31
|
+
"""
|
32
|
+
# Set the path to the .env file
|
33
|
+
self.path = Path(path) if path else Path(os.getcwd()) / ".env"
|
34
|
+
|
35
|
+
# Create the .env file if it does not exist
|
36
|
+
if not self.path.exists():
|
37
|
+
self.path.touch()
|
38
|
+
|
39
|
+
def get(self, key: str, default=None) -> str:
|
40
|
+
"""
|
41
|
+
Retrieves the value of an environment variable from the .env file
|
42
|
+
or from system environment variables if not found.
|
43
|
+
|
44
|
+
Parameters
|
45
|
+
----------
|
46
|
+
key : str
|
47
|
+
The key of the environment variable.
|
48
|
+
default : optional
|
49
|
+
Default value if the key does not exist. Defaults to None.
|
50
|
+
|
51
|
+
Returns
|
52
|
+
-------
|
53
|
+
str
|
54
|
+
The value of the environment variable or the default value.
|
55
|
+
"""
|
56
|
+
|
57
|
+
# Get the value from the .env file
|
58
|
+
value = dotenv_values(self.path).get(key)
|
59
|
+
|
60
|
+
# Get the value from the system environment variables if not found
|
61
|
+
if value is None:
|
62
|
+
value = os.getenv(key)
|
63
|
+
|
64
|
+
# Parse the value and return it
|
65
|
+
return self._parse_value(value) if value is not None else default
|
66
|
+
|
67
|
+
def set(self, key: str, value: str) -> None:
|
68
|
+
"""
|
69
|
+
Sets the value of an environment variable in the .env file.
|
70
|
+
|
71
|
+
Parameters
|
72
|
+
----------
|
73
|
+
key : str
|
74
|
+
The key of the environment variable.
|
75
|
+
value : str
|
76
|
+
The value to set.
|
77
|
+
"""
|
78
|
+
# Set the value in the .env file
|
79
|
+
set_key(str(self.path), key, value)
|
80
|
+
|
81
|
+
def unset(self, key: str) -> None:
|
82
|
+
"""
|
83
|
+
Removes an environment variable from the .env file.
|
84
|
+
|
85
|
+
Parameters
|
86
|
+
----------
|
87
|
+
key : str
|
88
|
+
The key of the environment variable to remove.
|
89
|
+
"""
|
90
|
+
# Remove the key from the .env file
|
91
|
+
unset_key(str(self.path), key)
|
92
|
+
|
93
|
+
def all(self) -> dict:
|
94
|
+
"""
|
95
|
+
Retrieves all environment variable values from the .env file.
|
96
|
+
|
97
|
+
Returns
|
98
|
+
-------
|
99
|
+
dict
|
100
|
+
A dictionary of all environment variables and their values.
|
101
|
+
"""
|
102
|
+
# Return all environment variables
|
103
|
+
env_vars = {}
|
104
|
+
|
105
|
+
# Get all environment variables from the .env file
|
106
|
+
data = dotenv_values(self.path)
|
107
|
+
for key, value in data.items():
|
108
|
+
# Parse the value and add it to the dictionary
|
109
|
+
env_vars[key] = self._parse_value(value)
|
110
|
+
|
111
|
+
# Get all environment variables from the system environment variables
|
112
|
+
return env_vars
|
113
|
+
|
114
|
+
def _parse_value(self, value : Any):
|
115
|
+
|
116
|
+
# Strip leading and trailing whitespace from the value
|
117
|
+
value = str(value).strip() if value is not None else None
|
118
|
+
|
119
|
+
# Parse common types and Python literals
|
120
|
+
if not value or value.lower() in {'none', 'null'}:
|
121
|
+
return None
|
122
|
+
if value.lower() in {'true', 'false'}:
|
123
|
+
return value.lower() == 'true'
|
124
|
+
if value.isdigit():
|
125
|
+
return int(value)
|
126
|
+
|
127
|
+
# Attempt to parse Python literals (e.g., lists, dictionaries)
|
128
|
+
try:
|
129
|
+
return ast.literal_eval(value)
|
130
|
+
except (ValueError, SyntaxError):
|
131
|
+
return value
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import os
|
2
|
+
import threading
|
3
|
+
from pathlib import Path
|
4
|
+
from orionis.contracts.services.files.i_path_resolver_service import IPathResolverService
|
5
|
+
|
6
|
+
class PathResolverService(IPathResolverService):
|
7
|
+
|
8
|
+
_lock = threading.Lock()
|
9
|
+
_instance = None
|
10
|
+
|
11
|
+
def __new__(cls):
|
12
|
+
"""
|
13
|
+
Override the __new__ method to ensure only one instance of the class is created.
|
14
|
+
|
15
|
+
Returns
|
16
|
+
-------
|
17
|
+
PathResolverService
|
18
|
+
The singleton instance of the PathResolverService class.
|
19
|
+
"""
|
20
|
+
# Use the lock to ensure thread-safe instantiation
|
21
|
+
with cls._lock:
|
22
|
+
if cls._instance is None:
|
23
|
+
cls._instance = super().__new__(cls)
|
24
|
+
cls._instance.base_path = Path(os.getcwd())
|
25
|
+
return cls._instance
|
26
|
+
|
27
|
+
def resolve(self, route: str) -> str:
|
28
|
+
"""
|
29
|
+
Resolves and returns the absolute path as a string.
|
30
|
+
|
31
|
+
This method combines the base path (current working directory) with the provided
|
32
|
+
relative path, resolves it to an absolute path, and validates that it exists
|
33
|
+
and is either a directory or a file.
|
34
|
+
|
35
|
+
Parameters
|
36
|
+
----------
|
37
|
+
route : str
|
38
|
+
The relative directory or file path to be resolved.
|
39
|
+
|
40
|
+
Returns
|
41
|
+
-------
|
42
|
+
str
|
43
|
+
The absolute path to the directory or file.
|
44
|
+
|
45
|
+
Raises
|
46
|
+
------
|
47
|
+
PathNotFoundError
|
48
|
+
If the resolved path does not exist or is neither a directory nor a file.
|
49
|
+
"""
|
50
|
+
# Combine base path with the relative route
|
51
|
+
real_path = (self.base_path / route).resolve()
|
52
|
+
|
53
|
+
# Validate that the path exists and is either a directory or a file
|
54
|
+
if not real_path.exists():
|
55
|
+
raise Exception(f"The requested path does not exist or is invalid: {real_path}")
|
56
|
+
if not (real_path.is_dir() or real_path.is_file()):
|
57
|
+
raise Exception(f"The requested path does not exist or is invalid: {real_path}")
|
58
|
+
|
59
|
+
return str(real_path)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
orionis/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
2
|
orionis/cli_manager.py,sha256=0bM-hABXJSoPGuvEgnqeaj9qcLP8VjTQ3z9Mb0TSEUI,1381
|
3
|
-
orionis/framework.py,sha256=
|
3
|
+
orionis/framework.py,sha256=X0Emcz86KeiYNUZkHybLDkL0DA4OOjMEpgp6KquLfrw,1386
|
4
4
|
orionis/contracts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
5
|
orionis/contracts/bootstrap/i_command_bootstrapper.py,sha256=cfpYWSlNhOY1q_C9o0H7F381OoM0Oh0qaeqP-c85nzk,2457
|
6
6
|
orionis/contracts/bootstrap/i_config_bootstrapper.py,sha256=d2TXT74H2fCBbzWgrt9-ZG11S_H_YPQOEcJoIOrsgb0,4462
|
@@ -42,8 +42,10 @@ orionis/contracts/providers/i_service_provider.py,sha256=zoBAsGE-KrNfCsF3u876oxo
|
|
42
42
|
orionis/contracts/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
43
43
|
orionis/contracts/services/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
44
44
|
orionis/contracts/services/config/i_config_service.py,sha256=TdlEEsd8jvzBGozwaZtQ9KYHisY4ACL-VUOtydidHeE,989
|
45
|
+
orionis/contracts/services/environment/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
46
|
+
orionis/contracts/services/environment/i_environment_service.py,sha256=e-bod0MTq21WVvchlE7kyMQoFL_yhhN4ddRfzctDrz0,1959
|
45
47
|
orionis/contracts/services/files/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
46
|
-
orionis/contracts/services/files/
|
48
|
+
orionis/contracts/services/files/i_path_resolver_service.py,sha256=B53Qzei4o_jzehIF0zJVHXzI4S-h0XeQ5vMslxT8okM,837
|
47
49
|
orionis/contracts/services/log/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
48
50
|
orionis/contracts/services/log/i_log_service.py,sha256=1RD3u-a5ZDMbg7AYE8y2SW8QNRybAU3De0mEA0dAeNo,2167
|
49
51
|
orionis/contracts/support/i_exception_to_dict.py,sha256=LZpbCNDYQJs3j2mIM-NRFl0IfA8I0GFHExgRSO6K2FQ,780
|
@@ -54,13 +56,14 @@ orionis/installer/installer_manager.py,sha256=Hb6T0bmSl39T30maY-nUWkrLhG77JdrKe4
|
|
54
56
|
orionis/installer/installer_output.py,sha256=LeKxzuXpnHOKbKpUtx3tMGkCi2bGcPV1VNnfBxwfxUU,7161
|
55
57
|
orionis/installer/installer_setup.py,sha256=c2HtVklSa-2_-YVonc7fwtoK-RTDqBS2Ybvbekgfqtc,6970
|
56
58
|
orionis/luminate/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
57
|
-
orionis/luminate/app.py,sha256=
|
59
|
+
orionis/luminate/app.py,sha256=KHmx5YBiBX2LD-4k8YwUbwOEDv4Ke19rD-5aMLxvIx0,2286
|
58
60
|
orionis/luminate/app_context.py,sha256=XREVkOHU6aP8UB2daA2QbFcOCB8HRmcGXjVbrlW1AHQ,1827
|
59
61
|
orionis/luminate/bootstrap/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
60
62
|
orionis/luminate/bootstrap/command_bootstrapper.py,sha256=OU0hDMtG1xqVbvCneq4C5mlOUu9OmfkxqbvGH59QsUw,6919
|
61
63
|
orionis/luminate/bootstrap/config_bootstrapper.py,sha256=Gw83UtPAOggwzqmz062JfJcpIfmZvmIQyZJfgVFiIcQ,7474
|
62
|
-
orionis/luminate/bootstrap/environment_bootstrapper.py,sha256=
|
64
|
+
orionis/luminate/bootstrap/environment_bootstrapper.py,sha256=GTZ-mBumoNlxYcqsQksw4XyH3TRfPkWAU62mB3wFKLk,2777
|
63
65
|
orionis/luminate/bootstrap/exception_bootstrapper.py,sha256=wDKfEW295c7-bavr7YUHK2CLYcTSZgjT9ZRSBne6GOE,1356
|
66
|
+
orionis/luminate/bootstrap/service_providers_bootstrapper.py,sha256=bQK1yDLP9dqks3TQhTaJDnrnla_79Tw8wTOY2AsLuDQ,268
|
64
67
|
orionis/luminate/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
65
68
|
orionis/luminate/config/app.py,sha256=7teuVPuaV2ao0M5Bv-jhSgjEwb9DtVwde2saTRmYru4,1737
|
66
69
|
orionis/luminate/config/auth.py,sha256=CG8F0pfVjKz4DY3d1Wi7gscdhnp4TT-Q8SJ2sdsHh18,523
|
@@ -98,14 +101,15 @@ orionis/luminate/container/container.py,sha256=SKC7IyiAaeySiSvlRbTZRTTe4i_Jvm2N8
|
|
98
101
|
orionis/luminate/container/exception.py,sha256=ap1SqYEjQEEHXJJTNmL7V1jrmRjgT5_7geZ95MYkhMA,1691
|
99
102
|
orionis/luminate/container/types.py,sha256=BDcXN0__voRNHZ5Gr5dF0sWIYAQyNk4TxAwILBWyDAA,1735
|
100
103
|
orionis/luminate/facades/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
104
|
+
orionis/luminate/facades/app.py,sha256=20ai-4ggQSBLNz2zpaESKsJ7NhnTQ-XvnRoT_WGNcxk,1486
|
101
105
|
orionis/luminate/facades/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
102
|
-
orionis/luminate/facades/config/config_facade.py,sha256=
|
106
|
+
orionis/luminate/facades/config/config_facade.py,sha256=xpyVdH_-CeOvtMuf-Pjl9SFZWOflXzx9lyDy_fYOmxU,1353
|
103
107
|
orionis/luminate/facades/environment/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
104
|
-
orionis/luminate/facades/environment/environment_facade.py,sha256=
|
108
|
+
orionis/luminate/facades/environment/environment_facade.py,sha256=URYc1fhE95U6SXTVFqNGS2zAYAylRw8Mqf6cEht9LBg,2825
|
105
109
|
orionis/luminate/facades/files/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
106
|
-
orionis/luminate/facades/files/path_facade.py,sha256=
|
110
|
+
orionis/luminate/facades/files/path_facade.py,sha256=xajnRjA5FZy9wSCs7NhZyWGapFqQ8hak779_-6G_QXk,9091
|
107
111
|
orionis/luminate/facades/log/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
108
|
-
orionis/luminate/facades/log/log_facade.py,sha256=
|
112
|
+
orionis/luminate/facades/log/log_facade.py,sha256=_F5-Vnon6hZKefrTwurvraW8lfoG99VmLql_prMdKm8,2482
|
109
113
|
orionis/luminate/facades/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
110
114
|
orionis/luminate/facades/tests/tests_facade.py,sha256=eH_fyXjzEVw8aqEwxAgSujFUItz2woau6hc2Mf4VlkE,1660
|
111
115
|
orionis/luminate/patterns/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -113,15 +117,20 @@ orionis/luminate/patterns/singleton.py,sha256=b3U0nubKSQWyal5wTXADVPtOztkaTk-M8Z
|
|
113
117
|
orionis/luminate/pipelines/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
114
118
|
orionis/luminate/pipelines/cli_pipeline.py,sha256=xpdwxArZrYqaeo4h375RQwY329V14S8DJC9z1w_Ar1s,4218
|
115
119
|
orionis/luminate/providers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
120
|
+
orionis/luminate/providers/service_provider.py,sha256=Ave9V10KPVCI6bt3HwJ51322P-_RnQuHXkC-ltlAOOA,1537
|
116
121
|
orionis/luminate/providers/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
117
|
-
orionis/luminate/providers/config/config_service_provider.py,sha256=
|
122
|
+
orionis/luminate/providers/config/config_service_provider.py,sha256=MDUdswBE3llDyTkpWnBnLACXs5lgEBHyVHENnwBtobE,660
|
123
|
+
orionis/luminate/providers/environment/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
124
|
+
orionis/luminate/providers/environment/environment_provider.py,sha256=k5Cgk59UNKliFN1zS7ghUyva03jg00QhJxWYhg-6JUQ,679
|
118
125
|
orionis/luminate/providers/log/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
119
|
-
orionis/luminate/providers/log/log_service_provider.py,sha256=
|
126
|
+
orionis/luminate/providers/log/log_service_provider.py,sha256=tcWDEI-fubi1mWSS-IKiRReuc0pRMHpxvbvuDgs2Uy0,654
|
120
127
|
orionis/luminate/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
121
128
|
orionis/luminate/services/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
122
129
|
orionis/luminate/services/config/config_service.py,sha256=TZa3WZtDKEW6p0bMktzMXn85cOQy-q21myiYu3rZA34,2147
|
130
|
+
orionis/luminate/services/environment/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
131
|
+
orionis/luminate/services/environment/environment_service.py,sha256=IgrfzLELNhnEuz9rn2lYBvv3JQrgiNCGLA34pQ__nxY,4136
|
123
132
|
orionis/luminate/services/files/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
124
|
-
orionis/luminate/services/files/
|
133
|
+
orionis/luminate/services/files/path_resolver_service.py,sha256=E-G_E2H5QAZyxeMssARp7l1OBSxQurxkUPoKdSOCKEE,2041
|
125
134
|
orionis/luminate/services/log/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
126
135
|
orionis/luminate/services/log/log_service.py,sha256=aiENimOQHqaEAsBJz2_698bt1IeJjddHnledLKfg25o,5262
|
127
136
|
orionis/luminate/support/dot_dict.py,sha256=FVHfBuAGTTVMjNG01Fix645fRNKKUMmNx61pYkxPL5c,1253
|
@@ -144,9 +153,9 @@ tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
144
153
|
tests/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
145
154
|
tests/tools/class_example.py,sha256=dIPD997Y15n6WmKhWoOFSwEldRm9MdOHTZZ49eF1p3c,1056
|
146
155
|
tests/tools/test_reflection.py,sha256=bhLQ7VGVod4B8sv-rW9AjnOumvaBVsoxieA3sdoM2yM,5244
|
147
|
-
orionis-0.
|
148
|
-
orionis-0.
|
149
|
-
orionis-0.
|
150
|
-
orionis-0.
|
151
|
-
orionis-0.
|
152
|
-
orionis-0.
|
156
|
+
orionis-0.70.0.dist-info/LICENCE,sha256=-_4cF2EBKuYVS_SQpy1uapq0oJPUU1vl_RUWSy2jJTo,1111
|
157
|
+
orionis-0.70.0.dist-info/METADATA,sha256=YvDFh8uQw1pFuqduGSMEkhUCX1lh2mfDboTFjZ--KbU,2978
|
158
|
+
orionis-0.70.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
159
|
+
orionis-0.70.0.dist-info/entry_points.txt,sha256=eef1_CVewfokKjrGBynXa06KabSJYo7LlDKKIKvs1cM,53
|
160
|
+
orionis-0.70.0.dist-info/top_level.txt,sha256=2bdoHgyGZhOtLAXS6Om8OCTmL24dUMC_L1quMe_ETbk,14
|
161
|
+
orionis-0.70.0.dist-info/RECORD,,
|
@@ -1,91 +0,0 @@
|
|
1
|
-
import os
|
2
|
-
import threading
|
3
|
-
from pathlib import Path
|
4
|
-
from orionis.contracts.services.files.i_path_service import IPathService
|
5
|
-
|
6
|
-
class PathService(IPathService):
|
7
|
-
"""
|
8
|
-
A thread-safe singleton class for resolving and validating absolute paths.
|
9
|
-
|
10
|
-
This class resolves the absolute path for a given relative directory or file path
|
11
|
-
based on the script's execution directory. It ensures that the requested path is valid
|
12
|
-
(either a directory or a file) and provides methods to retrieve the resolved path.
|
13
|
-
|
14
|
-
Attributes
|
15
|
-
----------
|
16
|
-
base_path : Path
|
17
|
-
The base path (current working directory) used for resolving relative paths.
|
18
|
-
route : str
|
19
|
-
The resolved absolute path to the directory or file.
|
20
|
-
"""
|
21
|
-
|
22
|
-
_instance = None
|
23
|
-
_lock = threading.Lock()
|
24
|
-
|
25
|
-
def __new__(cls):
|
26
|
-
"""
|
27
|
-
Override the __new__ method to ensure only one instance of the class is created.
|
28
|
-
|
29
|
-
Returns
|
30
|
-
-------
|
31
|
-
PathService
|
32
|
-
The singleton instance of the PathService class.
|
33
|
-
"""
|
34
|
-
# Use the lock to ensure thread-safe instantiation
|
35
|
-
with cls._lock:
|
36
|
-
if cls._instance is None:
|
37
|
-
cls._instance = super().__new__(cls)
|
38
|
-
cls._instance._initialize()
|
39
|
-
return cls._instance
|
40
|
-
|
41
|
-
def _initialize(self):
|
42
|
-
"""
|
43
|
-
Initializes the instance by setting the base path to the current working directory.
|
44
|
-
"""
|
45
|
-
self.base_path = Path(os.getcwd())
|
46
|
-
|
47
|
-
def resolve(self, route: str) -> str:
|
48
|
-
"""
|
49
|
-
Resolves and returns the absolute path as a string.
|
50
|
-
|
51
|
-
This method combines the base path (current working directory) with the provided
|
52
|
-
relative path, resolves it to an absolute path, and validates that it exists
|
53
|
-
and is either a directory or a file.
|
54
|
-
|
55
|
-
Parameters
|
56
|
-
----------
|
57
|
-
route : str
|
58
|
-
The relative directory or file path to be resolved.
|
59
|
-
|
60
|
-
Returns
|
61
|
-
-------
|
62
|
-
str
|
63
|
-
The absolute path to the directory or file.
|
64
|
-
|
65
|
-
Raises
|
66
|
-
------
|
67
|
-
ValueError
|
68
|
-
If the resolved path does not exist or is neither a directory nor a file.
|
69
|
-
"""
|
70
|
-
# Combine base path with the relative route
|
71
|
-
real_path = (self.base_path / route).resolve()
|
72
|
-
|
73
|
-
# Validate that the path exists and is either a directory or a file
|
74
|
-
if not real_path.exists():
|
75
|
-
raise ValueError(f"The requested path does not exist: {real_path}")
|
76
|
-
if not (real_path.is_dir() or real_path.is_file()):
|
77
|
-
raise ValueError(f"The requested path is neither a directory nor a file: {real_path}")
|
78
|
-
|
79
|
-
self.route = str(real_path)
|
80
|
-
return self.route
|
81
|
-
|
82
|
-
def __str__(self) -> str:
|
83
|
-
"""
|
84
|
-
Returns the resolved absolute path as a string (dunder method).
|
85
|
-
|
86
|
-
Returns
|
87
|
-
-------
|
88
|
-
str
|
89
|
-
The absolute path to the directory or file.
|
90
|
-
"""
|
91
|
-
return self.route
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|