orionis 0.44.0__py3-none-any.whl → 0.47.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- orionis/cli_manager.py +16 -30
- orionis/contracts/bootstrap/i_command_bootstrapper.py +59 -0
- orionis/contracts/bootstrap/i_config_bootstrapper.py +112 -0
- orionis/contracts/bootstrap/i_environment_bootstrapper.py +33 -0
- orionis/{luminate/contracts/console/base/base_command_interface.py → contracts/console/base/i_command.py} +0 -1
- orionis/contracts/facades/config/i_config_facade.py +37 -0
- orionis/contracts/facades/environment/i_environment_facade.py +40 -0
- orionis/{luminate/contracts/facades/paths_interface.py → contracts/facades/files/i_path_facade.py} +27 -20
- orionis/contracts/facades/log/i_log_facade.py +83 -0
- orionis/{luminate/contracts/facades/tests_interface.py → contracts/facades/tests/i_tests_facade.py} +3 -6
- orionis/{luminate/contracts/console/scripts/management_interface.py → contracts/installer/i_installer_manager.py} +19 -16
- orionis/contracts/installer/i_installer_output.py +101 -0
- orionis/contracts/installer/i_installer_setup.py +59 -0
- orionis/contracts/providers/i_service_provider.py +27 -0
- orionis/contracts/services/config/i_config_service.py +37 -0
- orionis/contracts/services/files/i_path_service.py +31 -0
- orionis/contracts/services/log/i_log_service.py +89 -0
- orionis/{luminate/facades/environment.py → contracts/support/i_environment.py} +25 -32
- orionis/{luminate/contracts/tools/exception_to_dict_interface.py → contracts/support/i_exception_to_dict.py} +0 -9
- orionis/{luminate/contracts/tools/reflection_interface.py → contracts/support/i_reflection.py} +17 -8
- orionis/{luminate/contracts/tools/std_interface.py → contracts/support/i_std.py} +3 -16
- orionis/framework.py +1 -1
- orionis/{luminate/console/scripts/management.py → installer/installer_manager.py} +22 -16
- orionis/{luminate/installer/output.py → installer/installer_output.py} +16 -10
- orionis/{luminate/installer/setup.py → installer/installer_setup.py} +13 -25
- orionis/luminate/app.py +15 -11
- orionis/luminate/bootstrap/command_bootstrapper.py +150 -0
- orionis/luminate/bootstrap/config_bootstrapper.py +168 -0
- orionis/luminate/bootstrap/environment_bootstrapper.py +67 -0
- orionis/luminate/config/helpers.py +20 -0
- orionis/luminate/console/base/command.py +1 -3
- orionis/luminate/console/command_filter.py +2 -2
- orionis/luminate/console/commands/cache_clear.py +17 -5
- orionis/luminate/console/commands/help.py +19 -13
- orionis/luminate/console/commands/schedule_work.py +6 -3
- orionis/luminate/console/commands/tests.py +1 -6
- orionis/luminate/console/commands/version.py +0 -5
- orionis/luminate/console/exceptions/cli_exception.py +1 -4
- orionis/luminate/console/kernel.py +2 -2
- orionis/luminate/console/output/console.py +2 -2
- orionis/luminate/console/output/executor.py +1 -1
- orionis/luminate/console/output/progress_bar.py +1 -1
- orionis/luminate/console/parser.py +2 -2
- orionis/luminate/console/runner.py +127 -126
- orionis/luminate/console/tasks/scheduler.py +8 -7
- orionis/luminate/container/container.py +1 -1
- orionis/luminate/container/types.py +38 -12
- orionis/luminate/facades/config/config_facade.py +43 -0
- orionis/luminate/facades/environment/environment_facade.py +68 -0
- orionis/luminate/facades/{paths.py → files/path_facade.py} +50 -6
- orionis/luminate/facades/log/__init__.py +0 -0
- orionis/luminate/facades/log/log_facade.py +95 -0
- orionis/luminate/facades/tests/__init__.py +0 -0
- orionis/luminate/facades/{tests.py → tests/tests_facade.py} +1 -1
- orionis/luminate/patterns/__init__.py +0 -0
- orionis/luminate/pipelines/cli_pipeline.py +122 -116
- orionis/luminate/providers/__init__.py +0 -0
- orionis/luminate/providers/config/__init__.py +0 -0
- orionis/luminate/providers/config/config_service_provider.py +26 -0
- orionis/luminate/providers/files/__init__.py +0 -0
- orionis/luminate/providers/files/path_service_provider.py +26 -0
- orionis/luminate/providers/log/__init__.py +0 -0
- orionis/luminate/providers/log/log_service_provider.py +26 -0
- orionis/luminate/services/__init__.py +0 -0
- orionis/luminate/services/config/__init__.py +0 -0
- orionis/luminate/services/config/config_service.py +72 -0
- orionis/luminate/services/files/__init__.py +0 -0
- orionis/luminate/services/files/path_service.py +71 -0
- orionis/luminate/services/log/__init__.py +0 -0
- orionis/luminate/services/log/log_service.py +159 -0
- orionis/luminate/{config → support}/environment.py +21 -32
- orionis/luminate/{tools → support}/exception_to_dict.py +1 -1
- orionis/luminate/{tools → support}/reflection.py +1 -1
- orionis/luminate/{tools → support}/std.py +1 -1
- orionis/luminate/test/unit_test.py +1 -2
- {orionis-0.44.0.dist-info → orionis-0.47.0.dist-info}/METADATA +1 -1
- orionis-0.47.0.dist-info/RECORD +157 -0
- tests/tools/test_reflection.py +1 -1
- orionis/luminate/bootstrap/commands/bootstrapper.py +0 -101
- orionis/luminate/bootstrap/commands/register.py +0 -92
- orionis/luminate/bootstrap/config/bootstrapper.py +0 -79
- orionis/luminate/bootstrap/config/parser.py +0 -53
- orionis/luminate/bootstrap/config/register.py +0 -76
- orionis/luminate/cache/app/config.py +0 -91
- orionis/luminate/cache/console/commands.py +0 -97
- orionis/luminate/console/cache.py +0 -87
- orionis/luminate/console/command.py +0 -40
- orionis/luminate/contracts/bootstrap/commands/bootstrapper_interface.py +0 -44
- orionis/luminate/contracts/bootstrap/commands/register_interface.py +0 -33
- orionis/luminate/contracts/bootstrap/config/bootstrapper_interface.py +0 -40
- orionis/luminate/contracts/bootstrap/config/parser_interface.py +0 -46
- orionis/luminate/contracts/bootstrap/config/register_interface.py +0 -47
- orionis/luminate/contracts/cache/app/config_interface.py +0 -76
- orionis/luminate/contracts/cache/console/commands_interface.py +0 -78
- orionis/luminate/contracts/config/environment_interface.py +0 -64
- orionis/luminate/contracts/console/command_interface.py +0 -36
- orionis/luminate/contracts/console/runner_interface.py +0 -50
- orionis/luminate/contracts/facades/env_interface.py +0 -64
- orionis/luminate/contracts/facades/log_interface.py +0 -48
- orionis/luminate/contracts/files/paths_interface.py +0 -29
- orionis/luminate/contracts/installer/output_interface.py +0 -125
- orionis/luminate/contracts/installer/setup_interface.py +0 -29
- orionis/luminate/contracts/installer/upgrade_interface.py +0 -24
- orionis/luminate/contracts/log/logger_interface.py +0 -33
- orionis/luminate/contracts/pipelines/cli_pipeline_interface.py +0 -84
- orionis/luminate/contracts/publisher/pypi_publisher_interface.py +0 -36
- orionis/luminate/contracts/test/unit_test_interface.py +0 -51
- orionis/luminate/facades/config.py +0 -10
- orionis/luminate/facades/log.py +0 -56
- orionis/luminate/files/paths.py +0 -56
- orionis/luminate/installer/upgrade.py +0 -42
- orionis/luminate/log/logger.py +0 -116
- orionis/luminate/publisher/pypi.py +0 -215
- orionis-0.44.0.dist-info/RECORD +0 -156
- /orionis/{luminate/bootstrap/config → contracts}/__init__.py +0 -0
- /orionis/{luminate/cache → contracts/config}/__init__.py +0 -0
- /orionis/{luminate/contracts/config/config_interface.py → contracts/config/i_config.py} +0 -0
- /orionis/{luminate/cache/app → contracts/console}/__init__.py +0 -0
- /orionis/{luminate/cache/console → contracts/console/base}/__init__.py +0 -0
- /orionis/{luminate/contracts/console/command_filter_interface.py → contracts/console/i_command_filter.py} +0 -0
- /orionis/{luminate/contracts/console/kernel_interface.py → contracts/console/i_kernel.py} +0 -0
- /orionis/{luminate/contracts/console/parser_interface.py → contracts/console/i_parser.py} +0 -0
- /orionis/{luminate/contracts/console/task_manager_interface.py → contracts/console/i_task_manager.py} +0 -0
- /orionis/{luminate/config/dataclass → contracts/console/output}/__init__.py +0 -0
- /orionis/{luminate/contracts/console/output/console_interface.py → contracts/console/output/i_console.py} +0 -0
- /orionis/{luminate/contracts/console/output/executor_interface.py → contracts/console/output/i_executor.py} +0 -0
- /orionis/{luminate/contracts/console/output/progress_bar_interface.py → contracts/console/output/i_progress_bar.py} +0 -0
- /orionis/{luminate/console/scripts → contracts/console/tasks}/__init__.py +0 -0
- /orionis/{luminate/contracts/console/tasks/schedule_interface.py → contracts/console/tasks/i_schedule.py} +0 -0
- /orionis/{luminate/contracts/container/container_interface.py → contracts/container/i_container.py} +0 -0
- /orionis/{luminate/contracts/container/types_interface.py → contracts/container/i_types.py} +0 -0
- /orionis/{luminate/contracts → contracts/facades}/__init__.py +0 -0
- /orionis/{luminate/contracts/cache → contracts/facades/config}/__init__.py +0 -0
- /orionis/{luminate/contracts/config → contracts/facades/environment}/__init__.py +0 -0
- /orionis/{luminate/contracts/console → contracts/facades/files}/__init__.py +0 -0
- /orionis/{luminate/contracts/facades → contracts/facades/log}/__init__.py +0 -0
- /orionis/{luminate/contracts/files → contracts/facades/tests}/__init__.py +0 -0
- /orionis/{luminate/contracts → contracts}/installer/__init__.py +0 -0
- /orionis/{luminate/contracts/log → contracts/providers}/__init__.py +0 -0
- /orionis/{luminate/contracts/publisher → contracts/services}/__init__.py +0 -0
- /orionis/{luminate/contracts/test → contracts/services/config}/__init__.py +0 -0
- /orionis/{luminate/contracts/tools → contracts/services/files}/__init__.py +0 -0
- /orionis/{luminate/files → contracts/services/log}/__init__.py +0 -0
- /orionis/{luminate/installer → installer}/__init__.py +0 -0
- /orionis/luminate/bootstrap/{cli_exception.py → exception_bootstrapper.py} +0 -0
- /orionis/luminate/config/{dataclass/app.py → app.py} +0 -0
- /orionis/luminate/config/{dataclass/auth.py → auth.py} +0 -0
- /orionis/luminate/config/{dataclass/cache.py → cache.py} +0 -0
- /orionis/luminate/config/{dataclass/cors.py → cors.py} +0 -0
- /orionis/luminate/config/{dataclass/database.py → database.py} +0 -0
- /orionis/luminate/config/{dataclass/filesystems.py → filesystems.py} +0 -0
- /orionis/luminate/config/{dataclass/logging.py → logging.py} +0 -0
- /orionis/luminate/config/{dataclass/mail.py → mail.py} +0 -0
- /orionis/luminate/config/{dataclass/queue.py → queue.py} +0 -0
- /orionis/luminate/config/{dataclass/session.py → session.py} +0 -0
- /orionis/luminate/{log → facades/config}/__init__.py +0 -0
- /orionis/luminate/{publisher → facades/environment}/__init__.py +0 -0
- /orionis/luminate/{tools → facades/files}/__init__.py +0 -0
- /orionis/luminate/{tools → support}/dot_dict.py +0 -0
- /orionis/{luminate/installer → static/ascii}/icon.ascii +0 -0
- /orionis/{luminate/installer → static/ascii}/info.ascii +0 -0
- /orionis/{luminate/static → static}/bg/galaxy.jpg +0 -0
- /orionis/{luminate/static → static}/favicon/OrionisFrameworkFavicon.png +0 -0
- /orionis/{luminate/static → static}/logos/OrionisFramework.jpg +0 -0
- /orionis/{luminate/static → static}/logos/OrionisFramework.png +0 -0
- /orionis/{luminate/static → static}/logos/OrionisFramework.psd +0 -0
- /orionis/{luminate/static → static}/logos/OrionisFramework2.png +0 -0
- /orionis/{luminate/static → static}/logos/OrionisFramework3.png +0 -0
- {orionis-0.44.0.dist-info → orionis-0.47.0.dist-info}/LICENCE +0 -0
- {orionis-0.44.0.dist-info → orionis-0.47.0.dist-info}/WHEEL +0 -0
- {orionis-0.44.0.dist-info → orionis-0.47.0.dist-info}/entry_points.txt +0 -0
- {orionis-0.44.0.dist-info → orionis-0.47.0.dist-info}/top_level.txt +0 -0
@@ -1,101 +0,0 @@
|
|
1
|
-
import pathlib
|
2
|
-
import importlib
|
3
|
-
import inspect
|
4
|
-
from orionis.luminate.bootstrap.cli_exception import BootstrapRuntimeError
|
5
|
-
from orionis.luminate.bootstrap.commands.register import Register
|
6
|
-
from orionis.luminate.console.base.command import BaseCommand
|
7
|
-
from orionis.luminate.contracts.bootstrap.commands.bootstrapper_interface import IBootstrapper
|
8
|
-
|
9
|
-
class Bootstrapper(IBootstrapper):
|
10
|
-
"""
|
11
|
-
Manages the automatic loading and registration of command classes
|
12
|
-
from Python files located in predefined directories.
|
13
|
-
|
14
|
-
The `Bootstrapper` class scans specific directories for Python files, dynamically
|
15
|
-
imports them, and registers classes that inherit from `BaseCommand`.
|
16
|
-
|
17
|
-
Attributes
|
18
|
-
----------
|
19
|
-
register : Register
|
20
|
-
An instance of the `Register` class used to register command classes.
|
21
|
-
|
22
|
-
Methods
|
23
|
-
-------
|
24
|
-
__init__(register: Register) -> None
|
25
|
-
Initializes the `Bootstrapper` with a `Register` instance and triggers autoloading.
|
26
|
-
_autoload() -> None
|
27
|
-
Scans predefined directories for Python files, dynamically imports modules,
|
28
|
-
and registers classes that extend `BaseCommand`.
|
29
|
-
"""
|
30
|
-
|
31
|
-
def __init__(self, register: Register) -> None:
|
32
|
-
"""
|
33
|
-
Initializes the `Bootstrapper` with a `Register` instance and triggers autoloading.
|
34
|
-
|
35
|
-
Parameters
|
36
|
-
----------
|
37
|
-
register : Register
|
38
|
-
An instance of the `Register` class used to register command classes.
|
39
|
-
"""
|
40
|
-
self.register = register
|
41
|
-
self._autoload()
|
42
|
-
|
43
|
-
def _autoload(self) -> None:
|
44
|
-
"""
|
45
|
-
Autoloads command modules from specified directories and registers command classes.
|
46
|
-
|
47
|
-
This method searches for Python files in the predefined command directories,
|
48
|
-
dynamically imports the modules, and registers classes that inherit from `BaseCommand`.
|
49
|
-
|
50
|
-
The command directories searched are:
|
51
|
-
- `app/console/commands` relative to the current working directory.
|
52
|
-
- `console/commands` relative to the parent directory of the current file.
|
53
|
-
|
54
|
-
It skips `__init__.py` files and ignores directories that do not exist.
|
55
|
-
|
56
|
-
Raises
|
57
|
-
------
|
58
|
-
BootstrapRuntimeError
|
59
|
-
If an error occurs while loading a module.
|
60
|
-
"""
|
61
|
-
|
62
|
-
# Define the base project path
|
63
|
-
base_path = pathlib.Path.cwd()
|
64
|
-
|
65
|
-
# Define the command directories to search
|
66
|
-
command_dirs = [
|
67
|
-
base_path / "app" / "console" / "commands",
|
68
|
-
pathlib.Path(__file__).resolve().parent.parent.parent / "console" / "commands"
|
69
|
-
]
|
70
|
-
|
71
|
-
# Iterate over each command directory
|
72
|
-
for cmd_dir in command_dirs:
|
73
|
-
|
74
|
-
# Skip if the directory does not exist
|
75
|
-
if not cmd_dir.is_dir():
|
76
|
-
continue
|
77
|
-
|
78
|
-
# Iterate over Python files in the directory (recursive search)
|
79
|
-
for file_path in cmd_dir.rglob("*.py"):
|
80
|
-
|
81
|
-
# Skip `__init__.py` files
|
82
|
-
if file_path.name == "__init__.py":
|
83
|
-
continue
|
84
|
-
|
85
|
-
# Convert file path to a Python module import path
|
86
|
-
module_path = ".".join(file_path.relative_to(base_path).with_suffix("").parts)
|
87
|
-
if 'site-packages.' in module_path:
|
88
|
-
module_path = module_path.split('site-packages.')[1]
|
89
|
-
|
90
|
-
try:
|
91
|
-
# Dynamically import the module
|
92
|
-
module = importlib.import_module(module_path.strip())
|
93
|
-
|
94
|
-
# Find classes that inherit from `BaseCommand`
|
95
|
-
for name, obj in inspect.getmembers(module, inspect.isclass):
|
96
|
-
if issubclass(obj, BaseCommand) and obj is not BaseCommand:
|
97
|
-
# Register the class
|
98
|
-
self.register.command(obj)
|
99
|
-
|
100
|
-
except Exception as e:
|
101
|
-
raise BootstrapRuntimeError(f"Error loading {module_path}") from e
|
@@ -1,92 +0,0 @@
|
|
1
|
-
from typing import Any, Callable
|
2
|
-
from orionis.luminate.console.base.command import BaseCommand
|
3
|
-
from orionis.luminate.cache.console.commands import CacheCommands
|
4
|
-
from orionis.luminate.contracts.bootstrap.commands.register_interface import IRegister
|
5
|
-
|
6
|
-
class Register(IRegister):
|
7
|
-
"""
|
8
|
-
A class to register and manage command classes.
|
9
|
-
|
10
|
-
Attributes
|
11
|
-
----------
|
12
|
-
commands : dict
|
13
|
-
A dictionary storing registered command classes.
|
14
|
-
"""
|
15
|
-
|
16
|
-
def __init__(self, cache : CacheCommands):
|
17
|
-
"""
|
18
|
-
Initializes the Register instance and prepares the cache commands system.
|
19
|
-
"""
|
20
|
-
self.cache_commands = cache
|
21
|
-
|
22
|
-
def command(self, command_class: Callable[..., Any]) -> None:
|
23
|
-
"""
|
24
|
-
Registers a command class after validating its structure.
|
25
|
-
|
26
|
-
Parameters
|
27
|
-
----------
|
28
|
-
command_class : type
|
29
|
-
The command class to register. It must:
|
30
|
-
- Have a 'signature' attribute (str, containing only letters, numbers, and ':', with no spaces).
|
31
|
-
- Have a 'description' attribute (str).
|
32
|
-
- Implement a 'handle' method.
|
33
|
-
- Inherit from 'BaseCommand'.
|
34
|
-
|
35
|
-
Returns
|
36
|
-
-------
|
37
|
-
type
|
38
|
-
The registered command class.
|
39
|
-
|
40
|
-
Raises
|
41
|
-
------
|
42
|
-
ValueError
|
43
|
-
If 'signature' is missing, invalid, contains spaces, or is not a string.
|
44
|
-
If 'description' is missing or not a string.
|
45
|
-
If 'handle' method is missing.
|
46
|
-
TypeError
|
47
|
-
If the class does not inherit from 'BaseCommand'.
|
48
|
-
"""
|
49
|
-
|
50
|
-
# Ensure 'command_class' is actually a class
|
51
|
-
if not isinstance(command_class, type):
|
52
|
-
raise TypeError(f"Expected a class, but got {type(command_class).__name__}.")
|
53
|
-
|
54
|
-
# Validate 'signature' attribute
|
55
|
-
if not hasattr(command_class, 'signature') or not isinstance(command_class.signature, str):
|
56
|
-
raise ValueError(f"Class {command_class.__name__} must have a 'signature' attribute as a string.")
|
57
|
-
|
58
|
-
# Sanitaze signature
|
59
|
-
signature = command_class.signature.strip()
|
60
|
-
|
61
|
-
# Ensure signature contains only letters, numbers, and ':', with no spaces
|
62
|
-
if not signature or ' ' in signature or not all(c.isalnum() or c == ":" for c in signature):
|
63
|
-
raise ValueError(f"Invalid signature format: '{signature}'. Only letters, numbers, and ':' are allowed, with no spaces.")
|
64
|
-
|
65
|
-
# Validate 'description' attribute
|
66
|
-
if not hasattr(command_class, 'description') or not isinstance(command_class.description, str):
|
67
|
-
raise ValueError(f"Class {command_class.__name__} must have a 'description' attribute as a string.")
|
68
|
-
|
69
|
-
# Sanitaze signature
|
70
|
-
description = command_class.description.strip()
|
71
|
-
|
72
|
-
# Validate 'handle' method
|
73
|
-
if not hasattr(command_class, 'handle') or not callable(getattr(command_class, 'handle')):
|
74
|
-
raise ValueError(f"Class {command_class.__name__} must implement a 'handle' method.")
|
75
|
-
|
76
|
-
# Validate 'arguments' method
|
77
|
-
if hasattr(command_class, 'arguments') and callable(getattr(command_class, 'arguments')):
|
78
|
-
arguments = command_class().arguments()
|
79
|
-
else:
|
80
|
-
arguments = []
|
81
|
-
|
82
|
-
# Validate inheritance from 'BaseCommand'
|
83
|
-
if not issubclass(command_class, BaseCommand):
|
84
|
-
raise TypeError(f"Class {command_class.__name__} must inherit from 'BaseCommand'.")
|
85
|
-
|
86
|
-
# Register the command
|
87
|
-
self.cache_commands.register(
|
88
|
-
concrete=command_class,
|
89
|
-
arguments=arguments,
|
90
|
-
description=description,
|
91
|
-
signature=signature
|
92
|
-
)
|
@@ -1,79 +0,0 @@
|
|
1
|
-
import importlib
|
2
|
-
import pathlib
|
3
|
-
from orionis.luminate.bootstrap.cli_exception import BootstrapRuntimeError
|
4
|
-
from orionis.luminate.bootstrap.config.register import Register
|
5
|
-
from orionis.luminate.contracts.bootstrap.config.bootstrapper_interface import IBootstrapper
|
6
|
-
|
7
|
-
class Bootstrapper(IBootstrapper):
|
8
|
-
"""
|
9
|
-
Manages the automatic loading and registration of configuration classes
|
10
|
-
from Python files located in a specified directory.
|
11
|
-
|
12
|
-
The `Bootstrapper` class scans directories for Python files and dynamically
|
13
|
-
imports them to find configuration classes. Once found, the classes are
|
14
|
-
registered using the provided `Register` instance.
|
15
|
-
|
16
|
-
Attributes
|
17
|
-
----------
|
18
|
-
register : Register
|
19
|
-
An instance of the `Register` class used to register configuration classes.
|
20
|
-
|
21
|
-
Methods
|
22
|
-
-------
|
23
|
-
__init__(register: Register) -> None
|
24
|
-
Initializes the `Bootstrapper` with a `Register` instance.
|
25
|
-
|
26
|
-
_autoload(directory: str) -> None
|
27
|
-
Scans a directory for Python files, imports them, finds configuration classes,
|
28
|
-
and registers them using the `Register` instance.
|
29
|
-
"""
|
30
|
-
|
31
|
-
def __init__(self, register: Register) -> None:
|
32
|
-
"""
|
33
|
-
Initializes the `Bootstrapper` with a `Register` instance.
|
34
|
-
|
35
|
-
Parameters
|
36
|
-
----------
|
37
|
-
register : Register
|
38
|
-
An instance of the `Register` class used to register configuration classes.
|
39
|
-
"""
|
40
|
-
self.register = register
|
41
|
-
self._autoload()
|
42
|
-
|
43
|
-
def _autoload(self, directory: str = 'config') -> None:
|
44
|
-
"""
|
45
|
-
Automatically registers configuration classes found in a given directory.
|
46
|
-
|
47
|
-
This method walks through the specified directory, imports all Python files,
|
48
|
-
and scans for class definitions. If a class is found, it is registered using
|
49
|
-
the `Register` instance. Only classes defined in Python files (excluding
|
50
|
-
`__init__.py`) are considered.
|
51
|
-
|
52
|
-
Parameters
|
53
|
-
----------
|
54
|
-
directory : str
|
55
|
-
The directory to scan for Python configuration files.
|
56
|
-
|
57
|
-
Raises
|
58
|
-
------
|
59
|
-
FileNotFoundError
|
60
|
-
If the provided directory does not exist.
|
61
|
-
"""
|
62
|
-
base_path = pathlib.Path(directory).resolve()
|
63
|
-
|
64
|
-
if not base_path.exists():
|
65
|
-
raise FileNotFoundError(f"Directory {directory} does not exist.")
|
66
|
-
|
67
|
-
for file_path in base_path.rglob("*.py"):
|
68
|
-
if file_path.name == "__init__.py":
|
69
|
-
continue
|
70
|
-
|
71
|
-
module_path = ".".join(file_path.relative_to(base_path).with_suffix("").parts)
|
72
|
-
|
73
|
-
try:
|
74
|
-
module = importlib.import_module(f"{directory}.{module_path}")
|
75
|
-
if hasattr(module, "Config"):
|
76
|
-
self.register.config(getattr(module, "Config"))
|
77
|
-
except Exception as e:
|
78
|
-
raise BootstrapRuntimeError(f"Error loading module {module_path}") from e
|
79
|
-
|
@@ -1,53 +0,0 @@
|
|
1
|
-
from typing import Any
|
2
|
-
from dataclasses import asdict
|
3
|
-
from orionis.luminate.contracts.bootstrap.config.parser_interface import IParser
|
4
|
-
|
5
|
-
class Parser(IParser):
|
6
|
-
"""
|
7
|
-
A class responsible for parsing configuration objects into dictionaries.
|
8
|
-
|
9
|
-
This class implements the `IParser` interface and provides a method
|
10
|
-
to convert configuration instances into a dictionary format.
|
11
|
-
|
12
|
-
Methods
|
13
|
-
-------
|
14
|
-
toDict(instance: Any) -> dict
|
15
|
-
Converts the `config` attribute of an instance into a dictionary.
|
16
|
-
"""
|
17
|
-
|
18
|
-
@staticmethod
|
19
|
-
def toDict(instance: Any) -> dict:
|
20
|
-
"""
|
21
|
-
Converts the `config` attribute of a given instance into a dictionary.
|
22
|
-
|
23
|
-
This method uses `asdict()` to transform a dataclass-based configuration
|
24
|
-
into a dictionary, ensuring that all attributes are properly serialized.
|
25
|
-
|
26
|
-
Parameters
|
27
|
-
----------
|
28
|
-
instance : Any
|
29
|
-
The object containing a `config` attribute to be converted.
|
30
|
-
|
31
|
-
Returns
|
32
|
-
-------
|
33
|
-
dict
|
34
|
-
A dictionary representation of the `config` attribute.
|
35
|
-
|
36
|
-
Raises
|
37
|
-
------
|
38
|
-
AttributeError
|
39
|
-
If the provided instance does not have a `config` attribute.
|
40
|
-
TypeError
|
41
|
-
If the `config` attribute cannot be converted to a dictionary.
|
42
|
-
"""
|
43
|
-
try:
|
44
|
-
# Check if instance is a dictionary
|
45
|
-
if isinstance(instance.config, dict):
|
46
|
-
return instance
|
47
|
-
# Check if instance is a dataclass
|
48
|
-
elif hasattr(instance.config, '__dataclass_fields__'):
|
49
|
-
return asdict(instance.config)
|
50
|
-
except AttributeError as e:
|
51
|
-
raise AttributeError("The provided instance does not have a 'config' attribute.") from e
|
52
|
-
except TypeError as e:
|
53
|
-
raise TypeError(f"Error: The 'config' attribute could not be converted to a dictionary. {str(e)}")
|
@@ -1,76 +0,0 @@
|
|
1
|
-
from orionis.luminate.bootstrap.config.parser import Parser
|
2
|
-
from orionis.luminate.cache.app.config import CacheConfig
|
3
|
-
from orionis.luminate.contracts.bootstrap.config.register_interface import IRegister
|
4
|
-
from orionis.luminate.contracts.config.config_interface import IConfig
|
5
|
-
from orionis.luminate.tools.reflection import Reflection
|
6
|
-
|
7
|
-
class Register(IRegister):
|
8
|
-
"""
|
9
|
-
Handles the registration of configuration classes within the application.
|
10
|
-
|
11
|
-
This class ensures that only valid configuration classes are registered
|
12
|
-
while enforcing structure and type safety.
|
13
|
-
|
14
|
-
Methods
|
15
|
-
-------
|
16
|
-
config(config_class: type) -> type
|
17
|
-
Registers a configuration class and ensures it meets the necessary criteria.
|
18
|
-
"""
|
19
|
-
|
20
|
-
def __init__(self, cache : CacheConfig) -> None:
|
21
|
-
"""
|
22
|
-
Initializes the Register instance with a cache configuration.
|
23
|
-
|
24
|
-
Parameters
|
25
|
-
----------
|
26
|
-
container : Container
|
27
|
-
The container instance to be used for configuration registration.
|
28
|
-
"""
|
29
|
-
self.cache = cache
|
30
|
-
|
31
|
-
def config(self, config_class: type) -> None:
|
32
|
-
"""
|
33
|
-
Registers a configuration class and ensures it meets the required structure.
|
34
|
-
|
35
|
-
This method performs multiple validation steps, including checking if the input
|
36
|
-
is a class, verifying the existence of a `config` attribute, and confirming
|
37
|
-
inheritance from `IConfig`.
|
38
|
-
|
39
|
-
Parameters
|
40
|
-
----------
|
41
|
-
config_class : type
|
42
|
-
The class to be registered as a configuration.
|
43
|
-
|
44
|
-
Returns
|
45
|
-
-------
|
46
|
-
type
|
47
|
-
The same class passed as an argument, if registration is successful.
|
48
|
-
|
49
|
-
Raises
|
50
|
-
------
|
51
|
-
TypeError
|
52
|
-
If `config_class` is not a class or does not inherit from `IConfig`.
|
53
|
-
ValueError
|
54
|
-
If `config_class` does not have a `config` attribute or is already registered.
|
55
|
-
"""
|
56
|
-
|
57
|
-
# Validate input type
|
58
|
-
if not isinstance(config_class, type):
|
59
|
-
raise TypeError(f"Expected a class, but got {type(config_class).__name__}.")
|
60
|
-
|
61
|
-
# Validate config attribute
|
62
|
-
if not hasattr(config_class, 'config'):
|
63
|
-
raise ValueError(f"Class {config_class.__name__} must have a 'config' attribute.")
|
64
|
-
|
65
|
-
# Extract module name
|
66
|
-
section = Reflection(config_class).getFileName(remove_extension=True)
|
67
|
-
|
68
|
-
# Validate inheritance
|
69
|
-
if not issubclass(config_class, IConfig):
|
70
|
-
raise TypeError(f"Class {config_class.__name__} must inherit from 'IConfig'.")
|
71
|
-
|
72
|
-
# Register configuration
|
73
|
-
self.cache.register(
|
74
|
-
section=section,
|
75
|
-
data=Parser.toDict(config_class)
|
76
|
-
)
|
@@ -1,91 +0,0 @@
|
|
1
|
-
from typing import Dict, Any
|
2
|
-
from orionis.luminate.contracts.cache.app.config_interface import ICacheConfig
|
3
|
-
|
4
|
-
class CacheConfig(ICacheConfig):
|
5
|
-
"""
|
6
|
-
CacheConfig is a class that manages the registration, unregistration, and retrieval of configuration sections.
|
7
|
-
|
8
|
-
Methods
|
9
|
-
-------
|
10
|
-
__init__()
|
11
|
-
Initializes a new instance of the class with an empty configuration dictionary.
|
12
|
-
register(section: str, data: Dict[str, Any])
|
13
|
-
Registers a configuration section with its associated data.
|
14
|
-
unregister(section: str)
|
15
|
-
Unregisters a previously registered configuration section.
|
16
|
-
get(section: str)
|
17
|
-
Retrieves the configuration data for a specific section.
|
18
|
-
"""
|
19
|
-
|
20
|
-
def __init__(self) -> None:
|
21
|
-
"""
|
22
|
-
Initializes a new instance of the class with an empty configuration dictionary.
|
23
|
-
|
24
|
-
Attributes:
|
25
|
-
config (dict): A dictionary to store configuration settings.
|
26
|
-
"""
|
27
|
-
self.config = {}
|
28
|
-
|
29
|
-
def register(self, section: str, data: Dict[str, Any]) -> None:
|
30
|
-
"""
|
31
|
-
Registers a configuration section.
|
32
|
-
|
33
|
-
Parameters
|
34
|
-
----------
|
35
|
-
section : str
|
36
|
-
The name of the configuration section to register.
|
37
|
-
data : dict
|
38
|
-
The configuration data associated with the section.
|
39
|
-
|
40
|
-
Raises
|
41
|
-
------
|
42
|
-
ValueError
|
43
|
-
If the section is already registered.
|
44
|
-
"""
|
45
|
-
if section in self.config:
|
46
|
-
raise ValueError(f"Configuration section '{section}' is already registered.")
|
47
|
-
|
48
|
-
self.config[section] = data
|
49
|
-
|
50
|
-
def unregister(self, section: str) -> None:
|
51
|
-
"""
|
52
|
-
Unregisters a previously registered configuration section.
|
53
|
-
|
54
|
-
Parameters
|
55
|
-
----------
|
56
|
-
section : str
|
57
|
-
The name of the configuration section to remove.
|
58
|
-
|
59
|
-
Raises
|
60
|
-
------
|
61
|
-
KeyError
|
62
|
-
If the section is not found in the registered configurations.
|
63
|
-
"""
|
64
|
-
if section not in self.config:
|
65
|
-
raise KeyError(f"Configuration section '{section}' is not registered.")
|
66
|
-
|
67
|
-
del self.config[section]
|
68
|
-
|
69
|
-
def get(self, section: str) -> Dict[str, Any]:
|
70
|
-
"""
|
71
|
-
Retrieves the configuration for a specific section.
|
72
|
-
|
73
|
-
Parameters
|
74
|
-
----------
|
75
|
-
section : str
|
76
|
-
The name of the configuration section to retrieve.
|
77
|
-
|
78
|
-
Returns
|
79
|
-
-------
|
80
|
-
dict
|
81
|
-
The configuration data for the specified section.
|
82
|
-
|
83
|
-
Raises
|
84
|
-
------
|
85
|
-
KeyError
|
86
|
-
If the requested section is not found.
|
87
|
-
"""
|
88
|
-
if section not in self.config:
|
89
|
-
raise KeyError(f"Configuration section '{section}' is not registered.")
|
90
|
-
|
91
|
-
return self.config[section]
|
@@ -1,97 +0,0 @@
|
|
1
|
-
from typing import Any, Callable
|
2
|
-
from orionis.luminate.contracts.cache.console.commands_interface import ICacheCommands
|
3
|
-
|
4
|
-
class CacheCommands(ICacheCommands):
|
5
|
-
"""
|
6
|
-
CacheCommands is a class that manages the registration, unregistration, and retrieval of command instances.
|
7
|
-
|
8
|
-
Methods
|
9
|
-
-------
|
10
|
-
__init__()
|
11
|
-
Initializes the command cache with an empty dictionary.
|
12
|
-
register(signature: str, description: str, arguments: list, concrete: Callable[..., Any])
|
13
|
-
Register a new command with its signature, description, and class instance.
|
14
|
-
unregister(signature: str)
|
15
|
-
Unregister an existing command by its signature.
|
16
|
-
get(signature: str)
|
17
|
-
Retrieve the information of a registered command by its signature.
|
18
|
-
"""
|
19
|
-
|
20
|
-
def __init__(self):
|
21
|
-
|
22
|
-
"""
|
23
|
-
Initializes the command cache.
|
24
|
-
|
25
|
-
This constructor sets up an empty dictionary to store commands.
|
26
|
-
"""
|
27
|
-
self.commands = {}
|
28
|
-
|
29
|
-
def register(self, signature: str, description: str, arguments: list, concrete: Callable[..., Any]):
|
30
|
-
"""
|
31
|
-
Register a new command with its signature, description, and class instance.
|
32
|
-
|
33
|
-
Parameters
|
34
|
-
----------
|
35
|
-
signature : str
|
36
|
-
The unique identifier (signature) for the command.
|
37
|
-
description : str
|
38
|
-
A brief description of what the command does.
|
39
|
-
concrete : class
|
40
|
-
The class or callable instance that defines the command behavior.
|
41
|
-
|
42
|
-
Raises
|
43
|
-
------
|
44
|
-
ValueError
|
45
|
-
If a command with the given signature already exists.
|
46
|
-
"""
|
47
|
-
if signature in self.commands:
|
48
|
-
raise ValueError(f"Command '{signature}' is already registered. Please ensure signatures are unique.")
|
49
|
-
|
50
|
-
self.commands[signature] = {
|
51
|
-
'concrete':concrete,
|
52
|
-
'arguments':arguments,
|
53
|
-
'description':description,
|
54
|
-
'signature':signature
|
55
|
-
}
|
56
|
-
|
57
|
-
def unregister(self, signature: str):
|
58
|
-
"""
|
59
|
-
Unregister an existing command by its signature.
|
60
|
-
|
61
|
-
Parameters
|
62
|
-
----------
|
63
|
-
signature : str
|
64
|
-
The unique identifier (signature) for the command to unregister.
|
65
|
-
|
66
|
-
Raises
|
67
|
-
------
|
68
|
-
KeyError
|
69
|
-
If the command with the given signature does not exist.
|
70
|
-
"""
|
71
|
-
if signature not in self.commands:
|
72
|
-
raise KeyError(f"Command '{signature}' not found.")
|
73
|
-
del self.commands[signature]
|
74
|
-
|
75
|
-
def get(self, signature: str):
|
76
|
-
"""
|
77
|
-
Retrieve the information of a registered command by its signature.
|
78
|
-
|
79
|
-
Parameters
|
80
|
-
----------
|
81
|
-
signature : str
|
82
|
-
The unique identifier (signature) for the command.
|
83
|
-
|
84
|
-
Returns
|
85
|
-
-------
|
86
|
-
dict
|
87
|
-
A dictionary containing the class, signature, and description of the command.
|
88
|
-
|
89
|
-
Raises
|
90
|
-
------
|
91
|
-
KeyError
|
92
|
-
If the command with the given signature does not exist.
|
93
|
-
"""
|
94
|
-
command = self.commands.get(signature)
|
95
|
-
if not command:
|
96
|
-
raise KeyError(f"Command with signature '{signature}' not found.")
|
97
|
-
return command
|
@@ -1,87 +0,0 @@
|
|
1
|
-
import os
|
2
|
-
from orionis.luminate.tools.reflection import Reflection
|
3
|
-
|
4
|
-
class CLICache:
|
5
|
-
"""
|
6
|
-
Class responsible for managing the loading and execution of commands within the framework.
|
7
|
-
|
8
|
-
This class ensures that commands are loaded only once and are accessible for execution.
|
9
|
-
|
10
|
-
Attributes
|
11
|
-
----------
|
12
|
-
paths : list
|
13
|
-
List of directories where commands are located.
|
14
|
-
|
15
|
-
Methods
|
16
|
-
-------
|
17
|
-
__init__ :
|
18
|
-
Initializes the CLICache instance, loading commands if not already initialized.
|
19
|
-
_load_commands :
|
20
|
-
Loads command modules from predefined directories and imports them dynamically.
|
21
|
-
"""
|
22
|
-
|
23
|
-
|
24
|
-
def __init__(self) -> None:
|
25
|
-
"""
|
26
|
-
Initializes the CLICache instance by loading commands if not already initialized.
|
27
|
-
|
28
|
-
This method will load command modules only once, ensuring that the commands are available for execution
|
29
|
-
across the application. It should not be called directly multiple times.
|
30
|
-
|
31
|
-
Attributes
|
32
|
-
----------
|
33
|
-
paths : list
|
34
|
-
List of directories containing command files to be loaded.
|
35
|
-
"""
|
36
|
-
self.paths = []
|
37
|
-
self._load_commands()
|
38
|
-
|
39
|
-
def _load_commands(self):
|
40
|
-
"""
|
41
|
-
Dynamically loads command modules from predefined directories.
|
42
|
-
|
43
|
-
This method traverses the specified directories, locates Python files, and imports them as modules.
|
44
|
-
It ensures that only the main directories are iterated over, avoiding subdirectories.
|
45
|
-
|
46
|
-
Directories searched:
|
47
|
-
---------------------
|
48
|
-
- app/console/commands (relative to the base path)
|
49
|
-
- Current directory of the module (this file's directory)
|
50
|
-
"""
|
51
|
-
paths = []
|
52
|
-
|
53
|
-
# Define the base path of the application
|
54
|
-
base_path = os.getcwd()
|
55
|
-
|
56
|
-
# Define command directories to be searched
|
57
|
-
command_dirs = [
|
58
|
-
os.path.join(base_path, 'app', 'console', 'commands'),
|
59
|
-
os.path.join(os.path.dirname(__file__), 'commands')
|
60
|
-
]
|
61
|
-
|
62
|
-
# Add valid directories to paths list
|
63
|
-
for command_dir in command_dirs:
|
64
|
-
if os.path.isdir(command_dir):
|
65
|
-
paths.append(command_dir)
|
66
|
-
|
67
|
-
# Iterate over each valid directory
|
68
|
-
for path in paths:
|
69
|
-
for current_directory, _, files in os.walk(path):
|
70
|
-
# Ensure to only iterate through the top-level directories
|
71
|
-
if current_directory == path:
|
72
|
-
pre_module = current_directory.replace(base_path, '').replace(os.sep, '.').lstrip('.')
|
73
|
-
for file in files:
|
74
|
-
if file.endswith('.py'):
|
75
|
-
|
76
|
-
# Remove the '.py' extension
|
77
|
-
module_name = file[:-3]
|
78
|
-
|
79
|
-
# Construct the full module path
|
80
|
-
module_path = f"{pre_module}.{module_name}"
|
81
|
-
|
82
|
-
# Remove the 'site-packages' prefix from the module path
|
83
|
-
if 'site-packages.' in module_path:
|
84
|
-
module_path = module_path.split('site-packages.')[1]
|
85
|
-
|
86
|
-
# Use Reflection to load the module dynamically
|
87
|
-
Reflection(module=module_path)
|