orionis 0.418.0__py3-none-any.whl → 0.420.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- orionis/metadata/framework.py +1 -1
- {orionis-0.418.0.dist-info → orionis-0.420.0.dist-info}/METADATA +1 -1
- {orionis-0.418.0.dist-info → orionis-0.420.0.dist-info}/RECORD +58 -133
- {orionis-0.418.0.dist-info → orionis-0.420.0.dist-info}/top_level.txt +0 -1
- tests/foundation/config/app/test_foundation_config_app.py +262 -0
- {foundation → tests/foundation}/config/cache/test_foundation_config_cache_file.py +8 -8
- {foundation → tests/foundation}/config/cache/test_foundation_config_cache_stores.py +11 -3
- {foundation → tests/foundation}/config/database/test_foundation_config_database_pgsql.py +5 -5
- {foundation → tests/foundation}/config/queue/test_foundation_config_queue.py +0 -20
- {foundation → tests/foundation}/config/queue/test_foundation_config_queue_brokers.py +0 -13
- tests/foundation/config/root/test_foundation_config_root_paths.py +116 -0
- tests/foundation/config/startup/test_foundation_config_startup.py +199 -0
- foundation/config/app/test_foundation_config_app.py +0 -150
- foundation/config/root/test_foundation_config_root_paths.py +0 -201
- foundation/config/startup/test_foundation_config_startup.py +0 -205
- foundation/exceptions/__init__.py +0 -0
- foundation/exceptions/test_foundation_config_exceptions.py +0 -117
- orionis/_contracts/__init__.py +0 -0
- orionis/_contracts/application.py +0 -41
- orionis/_contracts/config/__init__.py +0 -0
- orionis/_contracts/config/config.py +0 -27
- orionis/_contracts/console/__init__.py +0 -0
- orionis/_contracts/console/base/__init__.py +0 -0
- orionis/_contracts/console/base/command.py +0 -437
- orionis/_contracts/console/command_filter.py +0 -32
- orionis/_contracts/console/kernel.py +0 -32
- orionis/_contracts/console/output/__init__.py +0 -0
- orionis/_contracts/console/output/console.py +0 -421
- orionis/_contracts/console/output/executor.py +0 -51
- orionis/_contracts/console/parser.py +0 -75
- orionis/_contracts/console/task_manager.py +0 -37
- orionis/_contracts/facades/__init__.py +0 -0
- orionis/_contracts/facades/commands/__init__.py +0 -0
- orionis/_contracts/facades/commands/commands_facade.py +0 -40
- orionis/_contracts/facades/commands/scheduler_facade.py +0 -28
- orionis/_contracts/facades/config/__init__.py +0 -0
- orionis/_contracts/facades/config/config_facade.py +0 -37
- orionis/_contracts/facades/environment/__init__.py +0 -0
- orionis/_contracts/facades/environment/environment_facade.py +0 -74
- orionis/_contracts/facades/facade.py +0 -38
- orionis/_contracts/facades/files/__init__.py +0 -0
- orionis/_contracts/facades/files/path_facade.py +0 -148
- orionis/_contracts/facades/log/__init__.py +0 -0
- orionis/_contracts/facades/log/log_facade.py +0 -83
- orionis/_contracts/facades/tests/__init__.py +0 -0
- orionis/_contracts/facades/tests/tests_facade.py +0 -30
- orionis/_contracts/foundation/__init__.py +0 -0
- orionis/_contracts/foundation/bootstraper.py +0 -41
- orionis/_contracts/foundation/config/__init__.py +0 -0
- orionis/_contracts/foundation/config/config_bootstrapper.py +0 -140
- orionis/_contracts/foundation/console/__init__.py +0 -0
- orionis/_contracts/foundation/console/command_bootstrapper.py +0 -81
- orionis/_contracts/foundation/environment/__init__.py +0 -0
- orionis/_contracts/foundation/environment/environment_bootstrapper.py +0 -33
- orionis/_contracts/foundation/providers/__init__.py +0 -0
- orionis/_contracts/foundation/providers/service_providers_bootstrapper.py +0 -47
- orionis/_contracts/providers/__init__.py +0 -0
- orionis/_contracts/providers/service_provider.py +0 -14
- orionis/_contracts/services/__init__.py +0 -0
- orionis/_contracts/services/commands/__init__.py +0 -0
- orionis/_contracts/services/commands/reactor_commands_service.py +0 -23
- orionis/_contracts/services/commands/schedule_service.py +0 -317
- orionis/_contracts/services/config/__init__.py +0 -0
- orionis/_contracts/services/config/config_service.py +0 -37
- orionis/_contracts/services/environment/__init__.py +0 -0
- orionis/_contracts/services/environment/environment_service.py +0 -74
- orionis/_contracts/services/files/__init__.py +0 -0
- orionis/_contracts/services/files/path_resolver_service.py +0 -29
- orionis/_contracts/services/log/__init__.py +0 -0
- orionis/_contracts/services/log/log_service.py +0 -89
- orionis/_contracts/support/exception_parse.py +0 -26
- orionis/_contracts/support/reflection.py +0 -352
- orionis/_foundation/__init__.py +0 -0
- orionis/_foundation/console/__init__.py +0 -0
- orionis/_foundation/console/command_bootstrapper.py +0 -175
- orionis/_foundation/environment/__init__.py +0 -0
- orionis/_foundation/environment/environment_bootstrapper.py +0 -76
- orionis/_foundation/exceptions/__init__.py +0 -0
- orionis/_foundation/exceptions/exception_bootstrapper.py +0 -54
- orionis/_foundation/exceptions/exception_providers.py +0 -54
- orionis/_foundation/foundation/config/__init__.py +0 -0
- orionis/_foundation/foundation/config/config_bootstrapper.py +0 -209
- orionis/_foundation/providers/__init__.py +0 -0
- orionis/_foundation/providers/service_providers_bootstrapper.py +0 -107
- orionis/_services/__init__.py +0 -0
- orionis/_services/commands/__init__.py +0 -0
- orionis/_services/commands/reactor_commands_service.py +0 -148
- orionis/_services/commands/scheduler_service.py +0 -611
- orionis/_services/config/__init__.py +0 -0
- orionis/_services/config/config_service.py +0 -72
- {orionis-0.418.0.dist-info → orionis-0.420.0.dist-info}/WHEEL +0 -0
- {orionis-0.418.0.dist-info → orionis-0.420.0.dist-info}/licenses/LICENCE +0 -0
- {orionis-0.418.0.dist-info → orionis-0.420.0.dist-info}/zip-safe +0 -0
- {foundation → tests/foundation}/__init__.py +0 -0
- {foundation → tests/foundation}/config/__init__.py +0 -0
- {foundation → tests/foundation}/config/app/__init__.py +0 -0
- {foundation → tests/foundation}/config/auth/__init__.py +0 -0
- {foundation → tests/foundation}/config/auth/test_foundation_config_auth.py +0 -0
- {foundation → tests/foundation}/config/cache/__init__.py +0 -0
- {foundation → tests/foundation}/config/cache/test_foundation_config_cache.py +0 -0
- {foundation → tests/foundation}/config/cors/__init__.py +0 -0
- {foundation → tests/foundation}/config/cors/test_foundation_config_cors.py +0 -0
- {foundation → tests/foundation}/config/database/__init__.py +0 -0
- {foundation → tests/foundation}/config/database/test_foundation_config_database.py +0 -0
- {foundation → tests/foundation}/config/database/test_foundation_config_database_connections.py +0 -0
- {foundation → tests/foundation}/config/database/test_foundation_config_database_mysql.py +0 -0
- {foundation → tests/foundation}/config/database/test_foundation_config_database_oracle.py +0 -0
- {foundation → tests/foundation}/config/database/test_foundation_config_database_sqlite.py +0 -0
- {foundation → tests/foundation}/config/filesystems/__init__.py +0 -0
- {foundation → tests/foundation}/config/filesystems/test_foundation_config_filesystems.py +0 -0
- {foundation → tests/foundation}/config/filesystems/test_foundation_config_filesystems_aws.py +0 -0
- {foundation → tests/foundation}/config/filesystems/test_foundation_config_filesystems_disks.py +0 -0
- {foundation → tests/foundation}/config/filesystems/test_foundation_config_filesystems_local.py +0 -0
- {foundation → tests/foundation}/config/filesystems/test_foundation_config_filesystems_public.py +0 -0
- {foundation → tests/foundation}/config/logging/__init__.py +0 -0
- {foundation → tests/foundation}/config/logging/test_foundation_config_logging.py +0 -0
- {foundation → tests/foundation}/config/logging/test_foundation_config_logging_channels.py +0 -0
- {foundation → tests/foundation}/config/logging/test_foundation_config_logging_chunked.py +0 -0
- {foundation → tests/foundation}/config/logging/test_foundation_config_logging_daily.py +0 -0
- {foundation → tests/foundation}/config/logging/test_foundation_config_logging_hourly.py +0 -0
- {foundation → tests/foundation}/config/logging/test_foundation_config_logging_monthly.py +0 -0
- {foundation → tests/foundation}/config/logging/test_foundation_config_logging_stack.py +0 -0
- {foundation → tests/foundation}/config/logging/test_foundation_config_logging_weekly.py +0 -0
- {foundation → tests/foundation}/config/mail/__init__.py +0 -0
- {foundation → tests/foundation}/config/mail/test_foundation_config_mail.py +0 -0
- {foundation → tests/foundation}/config/mail/test_foundation_config_mail_file.py +0 -0
- {foundation → tests/foundation}/config/mail/test_foundation_config_mail_mailers.py +0 -0
- {foundation → tests/foundation}/config/mail/test_foundation_config_mail_smtp.py +0 -0
- {foundation → tests/foundation}/config/queue/__init__.py +0 -0
- {foundation → tests/foundation}/config/queue/test_foundation_config_queue_database.py +0 -0
- {foundation → tests/foundation}/config/root/__init__.py +0 -0
- {foundation → tests/foundation}/config/session/__init__.py +0 -0
- {foundation → tests/foundation}/config/session/test_foundation_config_session.py +0 -0
- {foundation → tests/foundation}/config/startup/__init__.py +0 -0
- {foundation → tests/foundation}/config/testing/__init__.py +0 -0
- {foundation → tests/foundation}/config/testing/test_foundation_config_testing.py +0 -0
|
@@ -1,352 +0,0 @@
|
|
|
1
|
-
from abc import ABC, abstractmethod
|
|
2
|
-
from typing import Any, List, Optional
|
|
3
|
-
|
|
4
|
-
class IReflection(ABC):
|
|
5
|
-
|
|
6
|
-
@abstractmethod
|
|
7
|
-
def safeImport(self):
|
|
8
|
-
"""
|
|
9
|
-
Safely imports the specified module and assigns the class object if a classname is provided.
|
|
10
|
-
|
|
11
|
-
This method raises a ValueError if the module cannot be imported or if the class does not exist
|
|
12
|
-
within the module.
|
|
13
|
-
|
|
14
|
-
Raises
|
|
15
|
-
------
|
|
16
|
-
ValueError
|
|
17
|
-
If the module cannot be imported or the class does not exist in the module.
|
|
18
|
-
"""
|
|
19
|
-
pass
|
|
20
|
-
|
|
21
|
-
@abstractmethod
|
|
22
|
-
def getFile(self) -> str:
|
|
23
|
-
"""
|
|
24
|
-
Retrieves the file path where the class is defined.
|
|
25
|
-
|
|
26
|
-
Returns
|
|
27
|
-
-------
|
|
28
|
-
str
|
|
29
|
-
The file path if the class is found, otherwise raises an error.
|
|
30
|
-
|
|
31
|
-
Raises
|
|
32
|
-
------
|
|
33
|
-
ValueError
|
|
34
|
-
If the class has not been loaded yet.
|
|
35
|
-
"""
|
|
36
|
-
pass
|
|
37
|
-
|
|
38
|
-
@abstractmethod
|
|
39
|
-
def hasClass(self) -> bool:
|
|
40
|
-
"""
|
|
41
|
-
Checks whether the class object is available.
|
|
42
|
-
|
|
43
|
-
Returns
|
|
44
|
-
-------
|
|
45
|
-
bool
|
|
46
|
-
True if the class is loaded, False otherwise.
|
|
47
|
-
"""
|
|
48
|
-
pass
|
|
49
|
-
|
|
50
|
-
@abstractmethod
|
|
51
|
-
def hasMethod(self, method_name: str) -> bool:
|
|
52
|
-
"""
|
|
53
|
-
Checks whether the specified method exists in the class.
|
|
54
|
-
|
|
55
|
-
Parameters
|
|
56
|
-
----------
|
|
57
|
-
method_name : str
|
|
58
|
-
The name of the method to check.
|
|
59
|
-
|
|
60
|
-
Returns
|
|
61
|
-
-------
|
|
62
|
-
bool
|
|
63
|
-
True if the method exists, False otherwise.
|
|
64
|
-
"""
|
|
65
|
-
pass
|
|
66
|
-
|
|
67
|
-
@abstractmethod
|
|
68
|
-
def hasProperty(self, prop: str) -> bool:
|
|
69
|
-
"""
|
|
70
|
-
Checks whether the specified property exists in the class.
|
|
71
|
-
|
|
72
|
-
Parameters
|
|
73
|
-
----------
|
|
74
|
-
prop : str
|
|
75
|
-
The name of the property to check.
|
|
76
|
-
|
|
77
|
-
Returns
|
|
78
|
-
-------
|
|
79
|
-
bool
|
|
80
|
-
True if the property exists, False otherwise.
|
|
81
|
-
"""
|
|
82
|
-
pass
|
|
83
|
-
|
|
84
|
-
@abstractmethod
|
|
85
|
-
def hasConstant(self, constant: str) -> bool:
|
|
86
|
-
"""
|
|
87
|
-
Checks whether the specified constant exists in the class.
|
|
88
|
-
|
|
89
|
-
Parameters
|
|
90
|
-
----------
|
|
91
|
-
constant : str
|
|
92
|
-
The name of the constant to check.
|
|
93
|
-
|
|
94
|
-
Returns
|
|
95
|
-
-------
|
|
96
|
-
bool
|
|
97
|
-
True if the constant exists, False otherwise.
|
|
98
|
-
"""
|
|
99
|
-
pass
|
|
100
|
-
|
|
101
|
-
@abstractmethod
|
|
102
|
-
def getAttributes(self) -> List[str]:
|
|
103
|
-
"""
|
|
104
|
-
Retrieves a list of all attributes (including methods and properties) of the class.
|
|
105
|
-
|
|
106
|
-
Returns
|
|
107
|
-
-------
|
|
108
|
-
list
|
|
109
|
-
A list of attribute names in the class.
|
|
110
|
-
"""
|
|
111
|
-
pass
|
|
112
|
-
|
|
113
|
-
@abstractmethod
|
|
114
|
-
def getConstructor(self):
|
|
115
|
-
"""
|
|
116
|
-
Retrieves the constructor (__init__) of the class.
|
|
117
|
-
|
|
118
|
-
Returns
|
|
119
|
-
-------
|
|
120
|
-
function or None
|
|
121
|
-
The constructor method if available, otherwise None.
|
|
122
|
-
"""
|
|
123
|
-
pass
|
|
124
|
-
|
|
125
|
-
@abstractmethod
|
|
126
|
-
def getDocComment(self) -> Optional[str]:
|
|
127
|
-
"""
|
|
128
|
-
Retrieves the docstring of the class.
|
|
129
|
-
|
|
130
|
-
Returns
|
|
131
|
-
-------
|
|
132
|
-
str or None
|
|
133
|
-
The docstring of the class if available, otherwise None.
|
|
134
|
-
"""
|
|
135
|
-
pass
|
|
136
|
-
|
|
137
|
-
@abstractmethod
|
|
138
|
-
def getFileName(self, remove_extension: bool = False) -> str:
|
|
139
|
-
"""
|
|
140
|
-
Retrieves the file name where the class is defined, the same as `get_file()`.
|
|
141
|
-
|
|
142
|
-
Parameters
|
|
143
|
-
----------
|
|
144
|
-
remove_extension : bool, optional
|
|
145
|
-
If True, the file extension will be removed from the filename. Default is False.
|
|
146
|
-
|
|
147
|
-
Returns
|
|
148
|
-
-------
|
|
149
|
-
str
|
|
150
|
-
The file name of the class definition.
|
|
151
|
-
"""
|
|
152
|
-
pass
|
|
153
|
-
|
|
154
|
-
@abstractmethod
|
|
155
|
-
def getMethod(self, method_name: str):
|
|
156
|
-
"""
|
|
157
|
-
Retrieves the specified method from the class.
|
|
158
|
-
|
|
159
|
-
Parameters
|
|
160
|
-
----------
|
|
161
|
-
method_name : str
|
|
162
|
-
The name of the method to retrieve.
|
|
163
|
-
|
|
164
|
-
Returns
|
|
165
|
-
-------
|
|
166
|
-
function or None
|
|
167
|
-
The method if it exists, otherwise None.
|
|
168
|
-
"""
|
|
169
|
-
pass
|
|
170
|
-
|
|
171
|
-
@abstractmethod
|
|
172
|
-
def getMethods(self) -> List[str]:
|
|
173
|
-
"""
|
|
174
|
-
Retrieves a list of all methods in the class.
|
|
175
|
-
|
|
176
|
-
Returns
|
|
177
|
-
-------
|
|
178
|
-
list
|
|
179
|
-
A list of method names in the class.
|
|
180
|
-
"""
|
|
181
|
-
pass
|
|
182
|
-
|
|
183
|
-
@abstractmethod
|
|
184
|
-
def getName(self) -> str:
|
|
185
|
-
"""
|
|
186
|
-
Retrieves the name of the class.
|
|
187
|
-
|
|
188
|
-
Returns
|
|
189
|
-
-------
|
|
190
|
-
str or None
|
|
191
|
-
The name of the class if available, otherwise None.
|
|
192
|
-
"""
|
|
193
|
-
pass
|
|
194
|
-
|
|
195
|
-
@abstractmethod
|
|
196
|
-
def getParentClass(self) -> Optional[tuple]:
|
|
197
|
-
"""
|
|
198
|
-
Retrieves the parent classes (base classes) of the class.
|
|
199
|
-
|
|
200
|
-
Returns
|
|
201
|
-
-------
|
|
202
|
-
tuple or None
|
|
203
|
-
A tuple of base classes if available, otherwise None.
|
|
204
|
-
"""
|
|
205
|
-
pass
|
|
206
|
-
|
|
207
|
-
@abstractmethod
|
|
208
|
-
def getProperties(self) -> List[str]:
|
|
209
|
-
"""
|
|
210
|
-
Retrieves a list of all properties of the class.
|
|
211
|
-
|
|
212
|
-
Returns
|
|
213
|
-
-------
|
|
214
|
-
list
|
|
215
|
-
A list of property names in the class.
|
|
216
|
-
"""
|
|
217
|
-
pass
|
|
218
|
-
|
|
219
|
-
@abstractmethod
|
|
220
|
-
def getProperty(self, prop: str):
|
|
221
|
-
"""
|
|
222
|
-
Retrieves the specified property from the class.
|
|
223
|
-
|
|
224
|
-
Parameters
|
|
225
|
-
----------
|
|
226
|
-
prop : str
|
|
227
|
-
The name of the property to retrieve.
|
|
228
|
-
|
|
229
|
-
Returns
|
|
230
|
-
-------
|
|
231
|
-
property or None
|
|
232
|
-
The property if it exists, otherwise None.
|
|
233
|
-
"""
|
|
234
|
-
pass
|
|
235
|
-
|
|
236
|
-
@abstractmethod
|
|
237
|
-
def isAbstract(self) -> bool:
|
|
238
|
-
"""
|
|
239
|
-
Checks whether the class is abstract.
|
|
240
|
-
|
|
241
|
-
Returns
|
|
242
|
-
-------
|
|
243
|
-
bool
|
|
244
|
-
True if the class is abstract, False otherwise.
|
|
245
|
-
"""
|
|
246
|
-
pass
|
|
247
|
-
|
|
248
|
-
@abstractmethod
|
|
249
|
-
def isEnum(self) -> bool:
|
|
250
|
-
"""
|
|
251
|
-
Checks whether the class is an enumeration.
|
|
252
|
-
|
|
253
|
-
Returns
|
|
254
|
-
-------
|
|
255
|
-
bool
|
|
256
|
-
True if the class is a subclass of Enum, False otherwise.
|
|
257
|
-
"""
|
|
258
|
-
pass
|
|
259
|
-
|
|
260
|
-
@abstractmethod
|
|
261
|
-
def isSubclassOf(self, parent: type) -> bool:
|
|
262
|
-
"""
|
|
263
|
-
Checks whether the class is a subclass of the specified parent class.
|
|
264
|
-
|
|
265
|
-
Parameters
|
|
266
|
-
----------
|
|
267
|
-
parent : type
|
|
268
|
-
The parent class to check against.
|
|
269
|
-
|
|
270
|
-
Returns
|
|
271
|
-
-------
|
|
272
|
-
bool
|
|
273
|
-
True if the class is a subclass of the parent, False otherwise.
|
|
274
|
-
"""
|
|
275
|
-
pass
|
|
276
|
-
|
|
277
|
-
@abstractmethod
|
|
278
|
-
def isInstanceOf(self, instance: Any) -> bool:
|
|
279
|
-
"""
|
|
280
|
-
Checks whether the class is an instance of the specified class.
|
|
281
|
-
|
|
282
|
-
Parameters
|
|
283
|
-
----------
|
|
284
|
-
parent : type
|
|
285
|
-
The class to check against.
|
|
286
|
-
|
|
287
|
-
Returns
|
|
288
|
-
-------
|
|
289
|
-
bool
|
|
290
|
-
True if the class is a subclass of the parent, False otherwise.
|
|
291
|
-
"""
|
|
292
|
-
pass
|
|
293
|
-
|
|
294
|
-
@abstractmethod
|
|
295
|
-
def isIterable(self) -> bool:
|
|
296
|
-
"""
|
|
297
|
-
Checks whether the class is iterable.
|
|
298
|
-
|
|
299
|
-
Returns
|
|
300
|
-
-------
|
|
301
|
-
bool
|
|
302
|
-
True if the class is iterable, False otherwise.
|
|
303
|
-
"""
|
|
304
|
-
pass
|
|
305
|
-
|
|
306
|
-
@abstractmethod
|
|
307
|
-
def isInstantiable(self) -> bool:
|
|
308
|
-
"""
|
|
309
|
-
Checks whether the class can be instantiated.
|
|
310
|
-
|
|
311
|
-
Returns
|
|
312
|
-
-------
|
|
313
|
-
bool
|
|
314
|
-
True if the class is callable and not abstract, False otherwise.
|
|
315
|
-
"""
|
|
316
|
-
pass
|
|
317
|
-
|
|
318
|
-
@abstractmethod
|
|
319
|
-
def newInstance(self, *args, **kwargs):
|
|
320
|
-
"""
|
|
321
|
-
Creates a new instance of the class if it is instantiable.
|
|
322
|
-
|
|
323
|
-
Parameters
|
|
324
|
-
----------
|
|
325
|
-
args : tuple
|
|
326
|
-
Arguments to pass to the class constructor.
|
|
327
|
-
kwargs : dict
|
|
328
|
-
Keyword arguments to pass to the class constructor.
|
|
329
|
-
|
|
330
|
-
Returns
|
|
331
|
-
-------
|
|
332
|
-
object
|
|
333
|
-
A new instance of the class.
|
|
334
|
-
|
|
335
|
-
Raises
|
|
336
|
-
------
|
|
337
|
-
TypeError
|
|
338
|
-
If the class is not instantiable.
|
|
339
|
-
"""
|
|
340
|
-
pass
|
|
341
|
-
|
|
342
|
-
@abstractmethod
|
|
343
|
-
def __str__(self) -> str:
|
|
344
|
-
"""
|
|
345
|
-
Returns a string representation of the Reflection instance.
|
|
346
|
-
|
|
347
|
-
Returns
|
|
348
|
-
-------
|
|
349
|
-
str
|
|
350
|
-
A string describing the class and module.
|
|
351
|
-
"""
|
|
352
|
-
pass
|
orionis/_foundation/__init__.py
DELETED
|
File without changes
|
|
File without changes
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import pathlib
|
|
2
|
-
import importlib
|
|
3
|
-
import inspect
|
|
4
|
-
from typing import Any, Callable, Dict, List
|
|
5
|
-
from orionis._contracts.foundation.console.command_bootstrapper import ICommandsBootstrapper
|
|
6
|
-
from orionis._foundation.exceptions.exception_bootstrapper import BootstrapRuntimeError
|
|
7
|
-
from orionis._console.base.command import BaseCommand
|
|
8
|
-
|
|
9
|
-
class CommandsBootstrapper(ICommandsBootstrapper):
|
|
10
|
-
"""
|
|
11
|
-
A class responsible for loading and registering console commands dynamically.
|
|
12
|
-
|
|
13
|
-
This class scans specified directories for Python files, imports them, and registers
|
|
14
|
-
command classes that inherit from `BaseCommand`. It ensures that commands are loaded
|
|
15
|
-
only once and provides methods to access and manage them.
|
|
16
|
-
|
|
17
|
-
Attributes
|
|
18
|
-
----------
|
|
19
|
-
_commands : Dict[str, Dict[str, Any]]
|
|
20
|
-
A dictionary to store registered commands, where the key is the command signature
|
|
21
|
-
and the value is a dictionary containing the command class, arguments, description,
|
|
22
|
-
and signature.
|
|
23
|
-
|
|
24
|
-
Methods
|
|
25
|
-
-------
|
|
26
|
-
__init__()
|
|
27
|
-
Initializes the `CommandsBootstrapper` and triggers the autoload process.
|
|
28
|
-
_autoload()
|
|
29
|
-
Scans the command directories and loads command classes.
|
|
30
|
-
_register(concrete: Callable[..., Any])
|
|
31
|
-
Validates and registers a command class.
|
|
32
|
-
"""
|
|
33
|
-
|
|
34
|
-
def __init__(self) -> None:
|
|
35
|
-
"""
|
|
36
|
-
Initializes the `CommandsBootstrapper` and triggers the autoload process.
|
|
37
|
-
|
|
38
|
-
The `_commands` dictionary is initialized to store command data, and the
|
|
39
|
-
`_autoload` method is called to load commands from the specified directories.
|
|
40
|
-
"""
|
|
41
|
-
self._commands: Dict[str, Dict[str, Any]] = {}
|
|
42
|
-
self._autoload()
|
|
43
|
-
|
|
44
|
-
def _autoload(self) -> None:
|
|
45
|
-
"""
|
|
46
|
-
Scans the command directories and loads command classes.
|
|
47
|
-
|
|
48
|
-
This method searches for Python files in the specified directories, imports them,
|
|
49
|
-
and registers any class that inherits from `BaseCommand`.
|
|
50
|
-
|
|
51
|
-
Raises
|
|
52
|
-
------
|
|
53
|
-
BootstrapRuntimeError
|
|
54
|
-
If there is an error loading a module.
|
|
55
|
-
"""
|
|
56
|
-
base_path = pathlib.Path.cwd()
|
|
57
|
-
|
|
58
|
-
# Define the directories to scan for commands
|
|
59
|
-
command_dirs = [
|
|
60
|
-
base_path / "app" / "console" / "commands", # Developer-defined commands
|
|
61
|
-
pathlib.Path(__file__).resolve().parent.parent.parent / "console" / "commands" # Core commands
|
|
62
|
-
]
|
|
63
|
-
|
|
64
|
-
for cmd_dir in command_dirs:
|
|
65
|
-
if not cmd_dir.is_dir():
|
|
66
|
-
continue
|
|
67
|
-
|
|
68
|
-
for file_path in cmd_dir.rglob("*.py"):
|
|
69
|
-
if file_path.name == "__init__.py":
|
|
70
|
-
continue
|
|
71
|
-
|
|
72
|
-
module_path = ".".join(file_path.relative_to(base_path).with_suffix("").parts)
|
|
73
|
-
|
|
74
|
-
# Remove 'site-packages.' prefix if present
|
|
75
|
-
if 'site-packages.' in module_path:
|
|
76
|
-
module_path = module_path.split('site-packages.')[1]
|
|
77
|
-
|
|
78
|
-
try:
|
|
79
|
-
module = importlib.import_module(module_path.strip())
|
|
80
|
-
|
|
81
|
-
# Find and register command classes
|
|
82
|
-
for name, concrete in inspect.getmembers(module, inspect.isclass):
|
|
83
|
-
if issubclass(concrete, BaseCommand) and concrete is not BaseCommand:
|
|
84
|
-
self._register(concrete)
|
|
85
|
-
except Exception as e:
|
|
86
|
-
raise BootstrapRuntimeError(f"Error loading {module_path}") from e
|
|
87
|
-
|
|
88
|
-
def _register(self, concrete: Callable[..., Any]) -> None:
|
|
89
|
-
"""
|
|
90
|
-
Validates and registers a command class.
|
|
91
|
-
|
|
92
|
-
This method ensures that the provided class is valid (inherits from `BaseCommand`,
|
|
93
|
-
has a `signature`, `description`, and `handle` method) and registers it in the
|
|
94
|
-
`_commands` dictionary.
|
|
95
|
-
|
|
96
|
-
Parameters
|
|
97
|
-
----------
|
|
98
|
-
concrete : Callable[..., Any]
|
|
99
|
-
The command class to register.
|
|
100
|
-
|
|
101
|
-
Raises
|
|
102
|
-
------
|
|
103
|
-
TypeError
|
|
104
|
-
If the input is not a class or does not inherit from `BaseCommand`.
|
|
105
|
-
ValueError
|
|
106
|
-
If the class does not have required attributes or methods.
|
|
107
|
-
"""
|
|
108
|
-
if not isinstance(concrete, type):
|
|
109
|
-
raise TypeError(f"Expected a class, but got {type(concrete).__name__}.")
|
|
110
|
-
|
|
111
|
-
# Validate 'signature' attribute
|
|
112
|
-
if not hasattr(concrete, 'signature') or not isinstance(concrete.signature, str):
|
|
113
|
-
raise ValueError(f"Class {concrete.__name__} must have a 'signature' attribute as a string.")
|
|
114
|
-
|
|
115
|
-
signature = concrete.signature.strip()
|
|
116
|
-
|
|
117
|
-
# Validate signature format
|
|
118
|
-
if not signature or ' ' in signature or not all(c.isalnum() or c == ":" for c in signature):
|
|
119
|
-
raise ValueError(f"Invalid signature format: '{signature}'. Only letters, numbers, and ':' are allowed, with no spaces.")
|
|
120
|
-
|
|
121
|
-
# Validate 'description' attribute
|
|
122
|
-
if not hasattr(concrete, 'description') or not isinstance(concrete.description, str):
|
|
123
|
-
raise ValueError(f"Class {concrete.__name__} must have a 'description' attribute as a string.")
|
|
124
|
-
|
|
125
|
-
description = concrete.description.strip()
|
|
126
|
-
|
|
127
|
-
# Validate 'handle' method
|
|
128
|
-
if not hasattr(concrete, 'handle') or not callable(getattr(concrete, 'handle')):
|
|
129
|
-
raise ValueError(f"Class {concrete.__name__} must implement a 'handle' method.")
|
|
130
|
-
|
|
131
|
-
# Validate 'arguments' method (optional)
|
|
132
|
-
arguments: List[Any] = []
|
|
133
|
-
if hasattr(concrete, 'arguments') and callable(getattr(concrete, 'arguments')):
|
|
134
|
-
arguments = concrete().arguments()
|
|
135
|
-
|
|
136
|
-
# Validate inheritance from 'BaseCommand'
|
|
137
|
-
if not issubclass(concrete, BaseCommand):
|
|
138
|
-
raise TypeError(f"Class {concrete.__name__} must inherit from 'BaseCommand'.")
|
|
139
|
-
|
|
140
|
-
# Ensure the command signature is unique
|
|
141
|
-
if signature in self._commands:
|
|
142
|
-
raise ValueError(f"Command '{signature}' is already registered. Please ensure signatures are unique.")
|
|
143
|
-
|
|
144
|
-
# Register the command
|
|
145
|
-
self._commands[signature] = {
|
|
146
|
-
'concrete': concrete,
|
|
147
|
-
'arguments': arguments,
|
|
148
|
-
'description': description,
|
|
149
|
-
'signature': signature
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
def get(self, signature: str = None) -> Dict[str, Any]:
|
|
153
|
-
"""
|
|
154
|
-
Retrieves a registered command by its signature.
|
|
155
|
-
|
|
156
|
-
Parameters
|
|
157
|
-
----------
|
|
158
|
-
signature : str
|
|
159
|
-
The command signature to retrieve.
|
|
160
|
-
|
|
161
|
-
Returns
|
|
162
|
-
-------
|
|
163
|
-
Dict[str, Any]
|
|
164
|
-
A dictionary containing the command class, arguments, description, and signature.
|
|
165
|
-
|
|
166
|
-
Raises
|
|
167
|
-
------
|
|
168
|
-
KeyError
|
|
169
|
-
If the command signature is not found.
|
|
170
|
-
"""
|
|
171
|
-
if signature is None:
|
|
172
|
-
return self._commands
|
|
173
|
-
if signature not in self._commands:
|
|
174
|
-
raise KeyError(f"Command '{signature}' not found.")
|
|
175
|
-
return self._commands[signature]
|
|
File without changes
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
from typing import Dict
|
|
2
|
-
from orionis._contracts.foundation.environment.environment_bootstrapper import IEnvironmentBootstrapper
|
|
3
|
-
# from orionis.support.environment.env import Env
|
|
4
|
-
# from orionis.services.environment.environment_service import EnvironmentService
|
|
5
|
-
|
|
6
|
-
class EnvironmentBootstrapper(IEnvironmentBootstrapper):
|
|
7
|
-
"""
|
|
8
|
-
A class responsible for loading and managing environment variables from a `.env` file.
|
|
9
|
-
|
|
10
|
-
This class implements the `IEnvironment` interface and provides functionality to
|
|
11
|
-
automatically load environment variables from a `.env` file located in the current
|
|
12
|
-
working directory. If the file does not exist, it creates it.
|
|
13
|
-
|
|
14
|
-
Attributes
|
|
15
|
-
----------
|
|
16
|
-
_environment_vars : Dict[str, str]
|
|
17
|
-
A dictionary to store the loaded environment variables.
|
|
18
|
-
path : Path
|
|
19
|
-
The path to the `.env` file.
|
|
20
|
-
|
|
21
|
-
Methods
|
|
22
|
-
-------
|
|
23
|
-
__init__()
|
|
24
|
-
Initializes the `EnvironmentBootstrapper` and triggers the autoload process.
|
|
25
|
-
_autoload()
|
|
26
|
-
Loads environment variables from the `.env` file or creates the file if it does not exist.
|
|
27
|
-
"""
|
|
28
|
-
|
|
29
|
-
def __init__(self) -> None:
|
|
30
|
-
"""
|
|
31
|
-
Initializes the `EnvironmentBootstrapper` and triggers the autoload process.
|
|
32
|
-
|
|
33
|
-
The `_environment_vars` dictionary is initialized to store environment variables,
|
|
34
|
-
and the `_autoload` method is called to load variables from the `.env` file.
|
|
35
|
-
"""
|
|
36
|
-
self._environment_vars: Dict[str, str] = {}
|
|
37
|
-
self._autoload()
|
|
38
|
-
|
|
39
|
-
def _autoload(self) -> None:
|
|
40
|
-
"""
|
|
41
|
-
Loads environment variables from the `.env` file or creates the file if it does not exist.
|
|
42
|
-
|
|
43
|
-
This method checks if the `.env` file exists in the current working directory.
|
|
44
|
-
If the file does not exist, it creates an empty `.env` file. If the file exists,
|
|
45
|
-
it loads the environment variables into the `_environment_vars` dictionary.
|
|
46
|
-
"""
|
|
47
|
-
environment_service =Env() # type: ignore
|
|
48
|
-
self._environment_vars = environment_service.all()
|
|
49
|
-
|
|
50
|
-
def get(self, key: str = None) -> str:
|
|
51
|
-
"""
|
|
52
|
-
Retrieves the value of an environment variable by its key.
|
|
53
|
-
|
|
54
|
-
Parameters
|
|
55
|
-
----------
|
|
56
|
-
key : str
|
|
57
|
-
The key of the environment variable to retrieve.
|
|
58
|
-
|
|
59
|
-
Returns
|
|
60
|
-
-------
|
|
61
|
-
str
|
|
62
|
-
The value of the environment variable.
|
|
63
|
-
|
|
64
|
-
Raises
|
|
65
|
-
------
|
|
66
|
-
KeyError
|
|
67
|
-
If the environment variable does not exist.
|
|
68
|
-
"""
|
|
69
|
-
|
|
70
|
-
if not key:
|
|
71
|
-
return self._environment_vars
|
|
72
|
-
|
|
73
|
-
if key not in self._environment_vars:
|
|
74
|
-
raise KeyError(f"Environment variable {key} not found")
|
|
75
|
-
|
|
76
|
-
return self._environment_vars[key]
|
|
File without changes
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
class BootstrapRuntimeError(RuntimeError):
|
|
2
|
-
"""
|
|
3
|
-
Exception raised for errors related to dumping Orionis data.
|
|
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"[BootstrapRuntimeError]: {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})"
|