orionis 0.151.0__py3-none-any.whl → 0.153.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/framework.py +1 -1
- orionis/luminate/application.py +159 -309
- orionis/luminate/container/__init__.py +0 -0
- orionis/luminate/container/container.py +2 -22
- orionis/luminate/container/container_integrity.py +2 -2
- orionis/luminate/container/resolve.py +74 -0
- orionis/luminate/contracts/application.py +41 -0
- orionis/luminate/contracts/foundation/providers/service_providers_bootstrapper.py +4 -3
- orionis/luminate/facades/environment/environment_facade.py +0 -24
- orionis/luminate/foundation/exceptions/exception_providers.py +54 -0
- orionis/luminate/foundation/providers/service_providers_bootstrapper.py +52 -44
- orionis/luminate/providers/commands/reactor_commands_service_provider.py +3 -3
- orionis/luminate/providers/commands/scheduler_provider.py +1 -10
- orionis/luminate/providers/config/config_service_provider.py +1 -10
- orionis/luminate/providers/environment/environment__service_provider.py +2 -4
- orionis/luminate/providers/files/paths_provider.py +2 -4
- orionis/luminate/providers/log/log_service_provider.py +2 -2
- orionis/luminate/providers/service_provider.py +1 -4
- orionis/luminate/services/commands/reactor_commands_service.py +5 -14
- orionis/luminate/services/config/config_service.py +3 -3
- orionis/luminate/services/environment/environment_service.py +24 -0
- {orionis-0.151.0.dist-info → orionis-0.153.0.dist-info}/METADATA +1 -1
- {orionis-0.151.0.dist-info → orionis-0.153.0.dist-info}/RECORD +28 -24
- /orionis/luminate/contracts/foundation/{i_bootstraper.py → bootstraper.py} +0 -0
- {orionis-0.151.0.dist-info → orionis-0.153.0.dist-info}/LICENCE +0 -0
- {orionis-0.151.0.dist-info → orionis-0.153.0.dist-info}/WHEEL +0 -0
- {orionis-0.151.0.dist-info → orionis-0.153.0.dist-info}/entry_points.txt +0 -0
- {orionis-0.151.0.dist-info → orionis-0.153.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,74 @@
|
|
1
|
+
import asyncio
|
2
|
+
from typing import Any, Callable
|
3
|
+
from orionis.luminate.container.container import Container
|
4
|
+
from orionis.luminate.container.exception import OrionisContainerValueError
|
5
|
+
|
6
|
+
class Resolve:
|
7
|
+
"""
|
8
|
+
A class to resolve dependencies from the dependency injection container.
|
9
|
+
|
10
|
+
This class ensures that a given abstract class or alias exists in the container
|
11
|
+
and resolves the associated service when an instance is created.
|
12
|
+
|
13
|
+
Parameters
|
14
|
+
----------
|
15
|
+
abstract_or_alias : Callable[..., Any] or str
|
16
|
+
The abstract class, alias, or callable to resolve from the container.
|
17
|
+
|
18
|
+
Returns
|
19
|
+
-------
|
20
|
+
Any
|
21
|
+
The service associated with the abstract class or alias.
|
22
|
+
|
23
|
+
Raises
|
24
|
+
------
|
25
|
+
OrionisContainerValueError
|
26
|
+
If the abstract class or alias is not found in the container.
|
27
|
+
|
28
|
+
Examples
|
29
|
+
--------
|
30
|
+
>>> container = Container()
|
31
|
+
>>> container.bind("my_service", MyService)
|
32
|
+
>>> container.alias("my_alias", "my_service")
|
33
|
+
>>> service = Resolve("my_alias") # Returns the service associated with "my_alias"
|
34
|
+
>>> service = Resolve(MyService) # Returns the service associated with MyService
|
35
|
+
"""
|
36
|
+
|
37
|
+
def __new__(cls, abstract_or_alias: Callable[..., Any] | str):
|
38
|
+
"""
|
39
|
+
Create an instance of Resolve and return the resolved service.
|
40
|
+
|
41
|
+
Parameters
|
42
|
+
----------
|
43
|
+
abstract_or_alias : Callable[..., Any] or str
|
44
|
+
The abstract class, alias, or callable to resolve from the container.
|
45
|
+
|
46
|
+
Returns
|
47
|
+
-------
|
48
|
+
Any
|
49
|
+
The service associated with the abstract class or alias.
|
50
|
+
|
51
|
+
Raises
|
52
|
+
------
|
53
|
+
OrionisContainerValueError
|
54
|
+
If the abstract class or alias is not found in the container.
|
55
|
+
"""
|
56
|
+
container = Container()
|
57
|
+
|
58
|
+
# Validate that the abstract or alias exists in the container
|
59
|
+
if not container.bound(abstract_or_alias):
|
60
|
+
raise OrionisContainerValueError(
|
61
|
+
f"Service or alias '{abstract_or_alias}' not found in the container."
|
62
|
+
)
|
63
|
+
|
64
|
+
# Resolve and return the service associated with the abstract or alias
|
65
|
+
try:
|
66
|
+
# Try to get the running event loop
|
67
|
+
loop = asyncio.get_running_loop()
|
68
|
+
# If there is a running event loop, resolve the service asynchronously
|
69
|
+
return loop.run_until_complete(container.make(abstract_or_alias))
|
70
|
+
except RuntimeError:
|
71
|
+
# If no event loop is running, create a new one and resolve the service
|
72
|
+
loop = asyncio.new_event_loop()
|
73
|
+
asyncio.set_event_loop(loop)
|
74
|
+
return loop.run_until_complete(container.make(abstract_or_alias))
|
@@ -0,0 +1,41 @@
|
|
1
|
+
from abc import ABC, abstractmethod
|
2
|
+
from typing import List, Type
|
3
|
+
from orionis.luminate.contracts.container.container import IContainer
|
4
|
+
from orionis.luminate.contracts.providers.service_provider import IServiceProvider
|
5
|
+
|
6
|
+
class IApplication(ABC):
|
7
|
+
"""
|
8
|
+
Abstract base class for the Application.
|
9
|
+
"""
|
10
|
+
|
11
|
+
@abstractmethod
|
12
|
+
def withProviders(self, providers: List[Type["IServiceProvider"]]) -> None:
|
13
|
+
"""
|
14
|
+
Sets custom service providers.
|
15
|
+
|
16
|
+
Parameters
|
17
|
+
----------
|
18
|
+
providers : List[Type[ServiceProvider]]
|
19
|
+
List of service providers.
|
20
|
+
"""
|
21
|
+
pass
|
22
|
+
|
23
|
+
@abstractmethod
|
24
|
+
def container(self) -> "IContainer":
|
25
|
+
"""
|
26
|
+
Returns the service container instance.
|
27
|
+
|
28
|
+
Returns
|
29
|
+
-------
|
30
|
+
IContainer
|
31
|
+
The service container.
|
32
|
+
"""
|
33
|
+
pass
|
34
|
+
|
35
|
+
@abstractmethod
|
36
|
+
def create(self) -> None:
|
37
|
+
"""
|
38
|
+
Initializes and boots the application, including loading commands
|
39
|
+
and service providers.
|
40
|
+
"""
|
41
|
+
pass
|
@@ -1,4 +1,5 @@
|
|
1
1
|
from abc import ABC, abstractmethod
|
2
|
+
from typing import List, Type
|
2
3
|
from orionis.luminate.providers.service_provider import ServiceProvider
|
3
4
|
|
4
5
|
class IServiceProvidersBootstrapper(ABC):
|
@@ -19,7 +20,7 @@ class IServiceProvidersBootstrapper(ABC):
|
|
19
20
|
pass
|
20
21
|
|
21
22
|
@abstractmethod
|
22
|
-
def _register(self, concrete: ServiceProvider) -> None:
|
23
|
+
def _register(self, concrete: Type[ServiceProvider]) -> None:
|
23
24
|
"""
|
24
25
|
Validates and registers a service provider class.
|
25
26
|
|
@@ -35,7 +36,7 @@ class IServiceProvidersBootstrapper(ABC):
|
|
35
36
|
pass
|
36
37
|
|
37
38
|
@abstractmethod
|
38
|
-
def getBeforeServiceProviders(self) ->
|
39
|
+
def getBeforeServiceProviders(self) -> List[Type[ServiceProvider]]:
|
39
40
|
"""
|
40
41
|
Retrieve the registered service providers.
|
41
42
|
|
@@ -47,7 +48,7 @@ class IServiceProvidersBootstrapper(ABC):
|
|
47
48
|
pass
|
48
49
|
|
49
50
|
@abstractmethod
|
50
|
-
def getAfterServiceProviders(self) ->
|
51
|
+
def getAfterServiceProviders(self) -> List[Type[ServiceProvider]]:
|
51
52
|
"""
|
52
53
|
Retrieve the registered service providers.
|
53
54
|
|
@@ -2,30 +2,6 @@ from orionis.luminate.contracts.facades.environment.environment_facade import IE
|
|
2
2
|
from orionis.luminate.facades.app_facade import app
|
3
3
|
from orionis.luminate.services.environment.environment_service import EnvironmentService
|
4
4
|
|
5
|
-
def env(key: str, default=None) -> str:
|
6
|
-
"""
|
7
|
-
Retrieves the value of an environment variable.
|
8
|
-
|
9
|
-
This function provides a convenient way to access environment variables
|
10
|
-
stored in the application context. If the variable does not exist, it
|
11
|
-
returns the specified default value.
|
12
|
-
|
13
|
-
Parameters
|
14
|
-
----------
|
15
|
-
key : str
|
16
|
-
The name of the environment variable to retrieve.
|
17
|
-
default : Any, optional
|
18
|
-
The default value to return if the environment variable does not exist.
|
19
|
-
Defaults to None.
|
20
|
-
|
21
|
-
Returns
|
22
|
-
-------
|
23
|
-
str
|
24
|
-
The value of the environment variable, or the default value if the variable
|
25
|
-
does not exist.
|
26
|
-
"""
|
27
|
-
return Env.get(key, default)
|
28
|
-
|
29
5
|
class Env(IEnv):
|
30
6
|
|
31
7
|
@staticmethod
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class ProvidersException(Exception):
|
2
|
+
"""
|
3
|
+
Exception related to the providers module.
|
4
|
+
|
5
|
+
Parameters
|
6
|
+
----------
|
7
|
+
message : str
|
8
|
+
The error message describing the issue.
|
9
|
+
|
10
|
+
Attributes
|
11
|
+
----------
|
12
|
+
message : str
|
13
|
+
The stored error message.
|
14
|
+
|
15
|
+
Methods
|
16
|
+
-------
|
17
|
+
__str__()
|
18
|
+
Returns a user-friendly string representation of the exception.
|
19
|
+
__repr__()
|
20
|
+
Returns a detailed representation for debugging purposes.
|
21
|
+
"""
|
22
|
+
|
23
|
+
def __init__(self, message: str):
|
24
|
+
"""
|
25
|
+
Initialize the exception with a message.
|
26
|
+
|
27
|
+
Parameters
|
28
|
+
----------
|
29
|
+
message : str
|
30
|
+
The error message describing the issue.
|
31
|
+
"""
|
32
|
+
super().__init__(f"[ProvidersException]: {message}")
|
33
|
+
|
34
|
+
def __str__(self) -> str:
|
35
|
+
"""
|
36
|
+
Returns a user-friendly string representation.
|
37
|
+
|
38
|
+
Returns
|
39
|
+
-------
|
40
|
+
str
|
41
|
+
A formatted error message.
|
42
|
+
"""
|
43
|
+
return self.args[0]
|
44
|
+
|
45
|
+
def __repr__(self) -> str:
|
46
|
+
"""
|
47
|
+
Returns a detailed representation for debugging.
|
48
|
+
|
49
|
+
Returns
|
50
|
+
-------
|
51
|
+
str
|
52
|
+
A detailed string representation including the exception name.
|
53
|
+
"""
|
54
|
+
return f"{self.__class__.__name__}({self.args[0]!r})"
|
@@ -1,17 +1,28 @@
|
|
1
1
|
import importlib
|
2
2
|
import inspect
|
3
3
|
import pathlib
|
4
|
+
from typing import List, Type
|
4
5
|
from orionis.luminate.contracts.foundation.providers.service_providers_bootstrapper import IServiceProvidersBootstrapper
|
5
|
-
from orionis.luminate.container.container import Container
|
6
6
|
from orionis.luminate.foundation.exceptions.exception_bootstrapper import BootstrapRuntimeError
|
7
7
|
from orionis.luminate.providers.service_provider import ServiceProvider
|
8
8
|
|
9
9
|
class ServiceProvidersBootstrapper(IServiceProvidersBootstrapper):
|
10
|
+
"""
|
11
|
+
Bootstrapper for loading and managing service providers.
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
This class is responsible for scanning directories, loading service provider classes,
|
14
|
+
and registering them in the container.
|
15
|
+
"""
|
16
|
+
|
17
|
+
def __init__(self, custom_providers: List[Type[ServiceProvider]] = None) -> None:
|
18
|
+
"""
|
19
|
+
Initializes the ServiceProvidersBootstrapper.
|
20
|
+
|
21
|
+
Args:
|
22
|
+
providers (List[Type[ServiceProvider]]): A list of service provider classes to register manually.
|
23
|
+
"""
|
24
|
+
self._service_providers: List[Type[ServiceProvider]] = []
|
25
|
+
self._custom_providers = custom_providers or []
|
15
26
|
self._autoload()
|
16
27
|
|
17
28
|
def _autoload(self) -> None:
|
@@ -21,26 +32,27 @@ class ServiceProvidersBootstrapper(IServiceProvidersBootstrapper):
|
|
21
32
|
This method searches for Python files in the specified directories, imports them,
|
22
33
|
and registers any class that inherits from `ServiceProvider`.
|
23
34
|
|
24
|
-
Raises
|
25
|
-
|
26
|
-
BootstrapRuntimeError
|
27
|
-
If there is an error loading a module.
|
35
|
+
Raises:
|
36
|
+
BootstrapRuntimeError: If there is an error loading a module.
|
28
37
|
"""
|
29
|
-
|
38
|
+
# Base path for the project
|
30
39
|
base_path = pathlib.Path.cwd()
|
31
40
|
|
32
|
-
|
41
|
+
# Directories to scan for provider classes (Core Providers)
|
42
|
+
provider_dirs = [
|
33
43
|
pathlib.Path(__file__).resolve().parent.parent.parent / "providers"
|
34
44
|
]
|
35
45
|
|
36
|
-
for
|
37
|
-
|
46
|
+
# Scan directories for provider classes
|
47
|
+
for provider_dir in provider_dirs:
|
48
|
+
if not provider_dir.is_dir():
|
38
49
|
continue
|
39
50
|
|
40
|
-
for file_path in
|
51
|
+
for file_path in provider_dir.rglob("*.py"):
|
41
52
|
if file_path.name == "__init__.py":
|
42
53
|
continue
|
43
54
|
|
55
|
+
# Convert file path to module path
|
44
56
|
module_path = ".".join(file_path.relative_to(base_path).with_suffix("").parts)
|
45
57
|
|
46
58
|
# Remove 'site-packages.' prefix if present
|
@@ -48,51 +60,47 @@ class ServiceProvidersBootstrapper(IServiceProvidersBootstrapper):
|
|
48
60
|
module_path = module_path.split('site-packages.')[1]
|
49
61
|
|
50
62
|
try:
|
63
|
+
# Import the module
|
51
64
|
module = importlib.import_module(module_path.strip())
|
52
65
|
|
53
|
-
# Find and register
|
54
|
-
for
|
66
|
+
# Find and register provider classes
|
67
|
+
for _, concrete in inspect.getmembers(module, inspect.isclass):
|
55
68
|
if issubclass(concrete, ServiceProvider) and concrete is not ServiceProvider:
|
56
69
|
self._register(concrete)
|
57
70
|
except Exception as e:
|
58
|
-
raise BootstrapRuntimeError(f"Error loading {module_path}") from e
|
71
|
+
raise BootstrapRuntimeError(f"Error loading module {module_path}: {str(e)}") from e
|
72
|
+
|
73
|
+
# Register manually provided service providers
|
74
|
+
try:
|
75
|
+
for concrete in self._custom_providers:
|
76
|
+
if issubclass(concrete, ServiceProvider) and concrete is not ServiceProvider:
|
77
|
+
self._register(concrete)
|
78
|
+
except Exception as e:
|
79
|
+
raise BootstrapRuntimeError(f"Error loading provider classes: {str(e)}") from e
|
59
80
|
|
60
|
-
def _register(self, concrete: ServiceProvider) -> None:
|
81
|
+
def _register(self, concrete: Type[ServiceProvider]) -> None:
|
61
82
|
"""
|
62
83
|
Validates and registers a service provider class.
|
63
84
|
|
64
85
|
This method ensures that the provided class is valid (inherits from `ServiceProvider`,
|
65
|
-
has a `register` and `boot` method) and registers it in the
|
66
|
-
`_service_providers` dictionary.
|
86
|
+
has a `register` and `boot` method) and registers it in the appropriate list.
|
67
87
|
|
68
|
-
|
69
|
-
|
70
|
-
concrete : ServiceProvider
|
71
|
-
The service provider class to register
|
72
|
-
"""
|
73
|
-
if concrete.beferoBootstrapping:
|
74
|
-
self._before_providers.append(concrete)
|
75
|
-
else:
|
76
|
-
self._after_providers.append(concrete)
|
88
|
+
Args:
|
89
|
+
concrete (Type[ServiceProvider]): The service provider class to register.
|
77
90
|
|
78
|
-
|
91
|
+
Raises:
|
92
|
+
BootstrapRuntimeError: If the provider class is invalid.
|
79
93
|
"""
|
80
|
-
|
94
|
+
if not hasattr(concrete, "register") or not callable(concrete.register):
|
95
|
+
raise BootstrapRuntimeError(f"Service provider {concrete.__name__} must implement a 'register' method.")
|
81
96
|
|
82
|
-
|
83
|
-
-------
|
84
|
-
list
|
85
|
-
A list of registered service providers
|
86
|
-
"""
|
87
|
-
return self._before_providers
|
97
|
+
self._service_providers.append(concrete)
|
88
98
|
|
89
|
-
def
|
99
|
+
def get(self) -> List[Type[ServiceProvider]]:
|
90
100
|
"""
|
91
|
-
Retrieve the registered service providers.
|
101
|
+
Retrieve the registered service providers that should run before bootstrapping.
|
92
102
|
|
93
|
-
Returns
|
94
|
-
|
95
|
-
list
|
96
|
-
A list of registered service providers
|
103
|
+
Returns:
|
104
|
+
List[Type[ServiceProvider]]: A list of service providers to run before bootstrapping.
|
97
105
|
"""
|
98
|
-
return self.
|
106
|
+
return self._service_providers
|
@@ -8,13 +8,13 @@ class ReactorCommandsServiceProvider(ServiceProvider):
|
|
8
8
|
"""
|
9
9
|
Registers services or bindings into the given container.
|
10
10
|
"""
|
11
|
-
self.
|
11
|
+
self.app.singleton(IReactorCommandsService, ReactorCommandsService)
|
12
12
|
|
13
|
-
def boot(self
|
13
|
+
def boot(self) -> None:
|
14
14
|
"""
|
15
15
|
Boot the service provider.
|
16
16
|
|
17
17
|
This method is intended to be overridden by subclasses to perform
|
18
18
|
any necessary bootstrapping or initialization tasks.
|
19
19
|
"""
|
20
|
-
self.app.make(
|
20
|
+
self.app.make(IReactorCommandsService)
|
@@ -8,13 +8,4 @@ class ScheduleServiceProvider(ServiceProvider):
|
|
8
8
|
"""
|
9
9
|
Registers services or bindings into the given container.
|
10
10
|
"""
|
11
|
-
self.
|
12
|
-
|
13
|
-
def boot(self,) -> None:
|
14
|
-
"""
|
15
|
-
Boot the service provider.
|
16
|
-
|
17
|
-
This method is intended to be overridden by subclasses to perform
|
18
|
-
any necessary bootstrapping or initialization tasks.
|
19
|
-
"""
|
20
|
-
self.app.make(self._container_id)
|
11
|
+
self.app.scoped(IScheduleService, ScheduleService)
|
@@ -8,13 +8,4 @@ class ConfigServiceProvider(ServiceProvider):
|
|
8
8
|
"""
|
9
9
|
Registers services or bindings into the given container.
|
10
10
|
"""
|
11
|
-
self.
|
12
|
-
|
13
|
-
def boot(self,) -> None:
|
14
|
-
"""
|
15
|
-
Boot the service provider.
|
16
|
-
|
17
|
-
This method is intended to be overridden by subclasses to perform
|
18
|
-
any necessary bootstrapping or initialization tasks.
|
19
|
-
"""
|
20
|
-
self.app.make(self._container_id)
|
11
|
+
self.app.scoped(IConfigService, ConfigService)
|
@@ -5,13 +5,11 @@ from orionis.luminate.services.files.path_resolver_service import PathResolverSe
|
|
5
5
|
|
6
6
|
class EnvironmentServiceProvider(ServiceProvider):
|
7
7
|
|
8
|
-
beferoBootstrapping = True
|
9
|
-
|
10
8
|
def register(self) -> None:
|
11
9
|
"""
|
12
10
|
Registers services or bindings into the given container.
|
13
11
|
"""
|
14
|
-
self.
|
12
|
+
self.app.singleton(IEnvironmentService, EnvironmentService)
|
15
13
|
|
16
14
|
def boot(self) -> None:
|
17
15
|
"""
|
@@ -20,4 +18,4 @@ class EnvironmentServiceProvider(ServiceProvider):
|
|
20
18
|
This method is intended to be overridden by subclasses to perform
|
21
19
|
any necessary bootstrapping or initialization tasks.
|
22
20
|
"""
|
23
|
-
self.app.make(
|
21
|
+
self.app.make(IEnvironmentService)
|
@@ -4,13 +4,11 @@ from orionis.luminate.services.files.path_resolver_service import PathResolverSe
|
|
4
4
|
|
5
5
|
class PathResolverProvider(ServiceProvider):
|
6
6
|
|
7
|
-
beferoBootstrapping = True
|
8
|
-
|
9
7
|
def register(self) -> None:
|
10
8
|
"""
|
11
9
|
Registers services or bindings into the given container.
|
12
10
|
"""
|
13
|
-
self.
|
11
|
+
self.app.singleton(IPathResolverService, PathResolverService)
|
14
12
|
|
15
13
|
def boot(self) -> None:
|
16
14
|
"""
|
@@ -19,4 +17,4 @@ class PathResolverProvider(ServiceProvider):
|
|
19
17
|
This method is intended to be overridden by subclasses to perform
|
20
18
|
any necessary bootstrapping or initialization tasks.
|
21
19
|
"""
|
22
|
-
self.app.make(
|
20
|
+
self.app.make(IPathResolverService)
|
@@ -8,7 +8,7 @@ class LogServiceProvider(ServiceProvider):
|
|
8
8
|
"""
|
9
9
|
Registers services or bindings into the given container.
|
10
10
|
"""
|
11
|
-
self.
|
11
|
+
self.app.singleton(ILogguerService, LogguerService)
|
12
12
|
|
13
13
|
def boot(self) -> None:
|
14
14
|
"""
|
@@ -17,4 +17,4 @@ class LogServiceProvider(ServiceProvider):
|
|
17
17
|
This method is intended to be overridden by subclasses to perform
|
18
18
|
any necessary bootstrapping or initialization tasks.
|
19
19
|
"""
|
20
|
-
self.app.make(
|
20
|
+
self.app.make(ILogguerService)
|
@@ -11,9 +11,6 @@ class ServiceProvider(IServiceProvider):
|
|
11
11
|
The container instance to be used by the service provider.
|
12
12
|
"""
|
13
13
|
|
14
|
-
# Indicates whether the service provider is a bootstrapper.
|
15
|
-
beferoBootstrapping = False
|
16
|
-
|
17
14
|
def __init__(self, app : Container) -> None:
|
18
15
|
"""
|
19
16
|
Initialize the service provider with the given container.
|
@@ -51,4 +48,4 @@ class ServiceProvider(IServiceProvider):
|
|
51
48
|
container : Container
|
52
49
|
The container instance where services will be booted.
|
53
50
|
"""
|
54
|
-
|
51
|
+
pass
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import time
|
2
2
|
from typing import Any, Dict, Optional
|
3
|
-
from orionis.luminate.
|
3
|
+
from orionis.luminate.container.resolve import Resolve
|
4
4
|
from orionis.luminate.console.base.command import BaseCommand
|
5
5
|
from orionis.luminate.console.command_filter import CommandFilter
|
6
6
|
from orionis.luminate.console.exceptions.cli_exception import CLIOrionisException
|
@@ -20,29 +20,20 @@ class ReactorCommandsService:
|
|
20
20
|
- Managing execution timing and error handling.
|
21
21
|
"""
|
22
22
|
|
23
|
-
def __init__(
|
24
|
-
self,
|
25
|
-
commands_bootstrapper: CommandsBootstrapper,
|
26
|
-
command_filter: CommandFilter,
|
27
|
-
log: Log,
|
28
|
-
executor: Executor,
|
29
|
-
console: Console,
|
30
|
-
):
|
23
|
+
def __init__(self, command_filter: CommandFilter, log: Log, executor: Executor, console: Console, app = Resolve('__orionis__')) -> None:
|
31
24
|
"""
|
32
25
|
Initializes the ReactorCommandsService instance.
|
33
26
|
|
34
27
|
Assigns provided services to internal attributes for later use in command
|
35
28
|
execution, filtering, and logging.
|
36
29
|
"""
|
37
|
-
self.
|
30
|
+
self.commands = app._commands if hasattr(app, '_commands') else {}
|
38
31
|
self.command_filter = command_filter
|
39
32
|
self.log = log
|
40
33
|
self.console_executor = executor
|
41
34
|
self.console_output = console
|
42
35
|
|
43
|
-
def _parse_arguments(
|
44
|
-
self, arguments, vars: Optional[Dict[str, Any]] = None, *args, **kwargs
|
45
|
-
):
|
36
|
+
def _parse_arguments(self, arguments, vars: Optional[Dict[str, Any]] = None, *args, **kwargs):
|
46
37
|
"""
|
47
38
|
Parses command-line arguments using the Orionis argument parser.
|
48
39
|
|
@@ -118,7 +109,7 @@ class ReactorCommandsService:
|
|
118
109
|
self.console_executor.running(program=signature)
|
119
110
|
|
120
111
|
# Retrieve command from bootstrapper
|
121
|
-
command = self.
|
112
|
+
command = self.commands.get(signature)
|
122
113
|
|
123
114
|
# Parse command arguments dynamically based on execution context
|
124
115
|
args_dict = self._parse_arguments(command.get('arguments', []), vars, *args, **kwargs)
|
@@ -1,17 +1,17 @@
|
|
1
1
|
import copy
|
2
2
|
from typing import Any, Optional
|
3
|
-
from orionis.luminate.
|
3
|
+
from orionis.luminate.container.resolve import Resolve
|
4
4
|
|
5
5
|
class ConfigService:
|
6
6
|
|
7
|
-
def __init__(self,
|
7
|
+
def __init__(self, app = Resolve('__orionis__')) -> None:
|
8
8
|
"""
|
9
9
|
Initializes the ConfigService with the provided configuration.
|
10
10
|
|
11
11
|
Args:
|
12
12
|
config (dict): A dictionary containing configuration settings.
|
13
13
|
"""
|
14
|
-
real_config : dict =
|
14
|
+
real_config : dict = app._config if hasattr(app, '_config') else {}
|
15
15
|
self._config = copy.deepcopy(real_config)
|
16
16
|
|
17
17
|
def set(self, key: str, value: Any) -> None:
|
@@ -4,6 +4,30 @@ from pathlib import Path
|
|
4
4
|
from typing import Any
|
5
5
|
from dotenv import set_key, unset_key, dotenv_values
|
6
6
|
|
7
|
+
def env(key: str, default=None) -> Any:
|
8
|
+
"""
|
9
|
+
Retrieves the value of an environment variable.
|
10
|
+
|
11
|
+
This function provides a convenient way to access environment variables
|
12
|
+
stored in the application context. If the variable does not exist, it
|
13
|
+
returns the specified default value.
|
14
|
+
|
15
|
+
Parameters
|
16
|
+
----------
|
17
|
+
key : str
|
18
|
+
The name of the environment variable to retrieve.
|
19
|
+
default : Any, optional
|
20
|
+
The default value to return if the environment variable does not exist.
|
21
|
+
Defaults to None.
|
22
|
+
|
23
|
+
Returns
|
24
|
+
-------
|
25
|
+
Any
|
26
|
+
The value of the environment variable, or the default value if the variable
|
27
|
+
does not exist.
|
28
|
+
"""
|
29
|
+
return EnvironmentService().get(key, default)
|
30
|
+
|
7
31
|
class EnvironmentService:
|
8
32
|
|
9
33
|
def __init__(self, path: str = None):
|