orionis 0.427.0__py3-none-any.whl → 0.429.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.
Files changed (34) hide show
  1. orionis/{_console → console}/commands/version.py +2 -2
  2. orionis/console/contracts/kernel.py +15 -0
  3. orionis/console/exceptions/__init__.py +11 -0
  4. orionis/console/kelnel.py +25 -0
  5. orionis/foundation/application.py +4 -2
  6. orionis/metadata/framework.py +1 -1
  7. orionis/test/kernel.py +63 -48
  8. {orionis-0.427.0.dist-info → orionis-0.429.0.dist-info}/METADATA +1 -1
  9. {orionis-0.427.0.dist-info → orionis-0.429.0.dist-info}/RECORD +17 -31
  10. orionis/_console/__init__.py +0 -0
  11. orionis/_console/base/__init__.py +0 -0
  12. orionis/_console/base/command.py +0 -436
  13. orionis/_console/command_filter.py +0 -36
  14. orionis/_console/commands/__init__.py +0 -0
  15. orionis/_console/commands/cache_clear.py +0 -76
  16. orionis/_console/commands/help.py +0 -70
  17. orionis/_console/commands/schedule_work.py +0 -55
  18. orionis/_console/dumper/__init__.py +0 -0
  19. orionis/_console/dumper/dump_die.py +0 -418
  20. orionis/_console/exceptions/__init__.py +0 -0
  21. orionis/_console/kernel.py +0 -31
  22. orionis/_console/output/__init__.py +0 -0
  23. orionis/_console/output/console.py +0 -587
  24. orionis/_console/output/executor.py +0 -90
  25. orionis/_console/output/progress_bar.py +0 -100
  26. orionis/_console/parser.py +0 -159
  27. /orionis/{_console → console}/exceptions/cli_exception.py +0 -0
  28. /orionis/{_console/exceptions/cli-orionis-value-error.py → console/exceptions/cli_orionis_value_error.py} +0 -0
  29. /orionis/{_console → console}/exceptions/cli_runtime_error.py +0 -0
  30. /orionis/{_console → console}/exceptions/cli_schedule_exception.py +0 -0
  31. {orionis-0.427.0.dist-info → orionis-0.429.0.dist-info}/WHEEL +0 -0
  32. {orionis-0.427.0.dist-info → orionis-0.429.0.dist-info}/licenses/LICENCE +0 -0
  33. {orionis-0.427.0.dist-info → orionis-0.429.0.dist-info}/top_level.txt +0 -0
  34. {orionis-0.427.0.dist-info → orionis-0.429.0.dist-info}/zip-safe +0 -0
@@ -1,587 +0,0 @@
1
- import datetime
2
- import getpass
3
- import os
4
- import sys
5
- from orionis.console.output.enums.styles import ANSIColors
6
- from orionis._contracts.console.output.console import IConsole
7
- from orionis.support.formatter.serializer import Parser
8
-
9
- class Console(IConsole):
10
- """
11
- Utility class for printing formatted messages to the console with ANSI colors.
12
-
13
- Provides methods to print success, info, warning, and error messages with
14
- optional timestamps, as well as general text formatting methods.
15
- """
16
-
17
- @staticmethod
18
- def _get_timestamp() -> str:
19
- """
20
- Returns the current date and time formatted in a muted color.
21
-
22
- Returns
23
- -------
24
- str
25
- The formatted timestamp with muted color.
26
- """
27
- return f"{ANSIColors.TEXT_MUTED.value}{datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}{ANSIColors.DEFAULT.value}"
28
-
29
- @staticmethod
30
- def _print_with_background(label: str, bg_color: ANSIColors, message: str, timestamp: bool):
31
- """
32
- Prints a formatted message with a background color.
33
-
34
- Parameters
35
- ----------
36
- label : str
37
- The label to display (e.g., 'SUCCESS', 'INFO').
38
- bg_color : ANSIColors
39
- The background color to use.
40
- message : str
41
- The message to print.
42
- timestamp : bool
43
- Whether to include a timestamp.
44
- """
45
- str_time = Console._get_timestamp() if timestamp else ''
46
- print(f"{bg_color.value}{ANSIColors.TEXT_WHITE.value} {label} {ANSIColors.DEFAULT.value} {str_time} {message}{ANSIColors.DEFAULT.value}")
47
-
48
- @staticmethod
49
- def _print_colored(message: str, text_color: ANSIColors):
50
- """
51
- Prints a message with a specified text color.
52
-
53
- Parameters
54
- ----------
55
- message : str
56
- The message to print.
57
- text_color : ANSIColors
58
- The text color to use.
59
- """
60
- print(f"{text_color.value}{message}{ANSIColors.DEFAULT.value}")
61
-
62
- @staticmethod
63
- def success(message: str, timestamp: bool = True):
64
- """
65
- Prints a success message with a green background.
66
-
67
- Parameters
68
- ----------
69
- message : str, optional
70
- The success message to print.
71
- timestamp : bool, optional
72
- Whether to include a timestamp (default is True).
73
- """
74
- Console._print_with_background("SUCCESS", ANSIColors.BG_SUCCESS, message, timestamp)
75
-
76
- @staticmethod
77
- def textSuccess(message: str):
78
- """
79
- Prints a success message in green.
80
-
81
- Parameters
82
- ----------
83
- message : str
84
- The success message to print.
85
- """
86
- Console._print_colored(message, ANSIColors.TEXT_SUCCESS)
87
-
88
- @staticmethod
89
- def textSuccessBold(message: str):
90
- """
91
- Prints a bold success message in green.
92
-
93
- Parameters
94
- ----------
95
- message : str
96
- The success message to print.
97
- """
98
- Console._print_colored(message, ANSIColors.TEXT_BOLD_SUCCESS)
99
-
100
- @staticmethod
101
- def info(message: str, timestamp: bool = True):
102
- """
103
- Prints an informational message with a blue background.
104
-
105
- Parameters
106
- ----------
107
- message : str
108
- The informational message to print.
109
- timestamp : bool, optional
110
- Whether to include a timestamp (default is True).
111
- """
112
- Console._print_with_background("INFO", ANSIColors.BG_INFO, message, timestamp)
113
-
114
- @staticmethod
115
- def textInfo(message: str):
116
- """
117
- Prints an informational message in blue.
118
-
119
- Parameters
120
- ----------
121
- message : str
122
- The informational message to print.
123
- """
124
- Console._print_colored(message, ANSIColors.TEXT_INFO)
125
-
126
- @staticmethod
127
- def textInfoBold(message: str):
128
- """
129
- Prints a bold informational message in blue.
130
-
131
- Parameters
132
- ----------
133
- message : str
134
- The informational message to print.
135
- """
136
- Console._print_colored(message, ANSIColors.TEXT_BOLD_INFO)
137
-
138
- @staticmethod
139
- def warning(message: str, timestamp: bool = True):
140
- """
141
- Prints a warning message with a yellow background.
142
-
143
- Parameters
144
- ----------
145
- message : str
146
- The warning message to print.
147
- timestamp : bool, optional
148
- Whether to include a timestamp (default is True).
149
- """
150
- Console._print_with_background("WARNING", ANSIColors.BG_WARNING, message, timestamp)
151
-
152
- @staticmethod
153
- def textWarning(message: str):
154
- """
155
- Prints a warning message in yellow.
156
-
157
- Parameters
158
- ----------
159
- message : str
160
- The warning message to print.
161
- """
162
- Console._print_colored(message, ANSIColors.TEXT_WARNING)
163
-
164
- @staticmethod
165
- def textWarningBold(message: str):
166
- """
167
- Prints a bold warning message in yellow.
168
-
169
- Parameters
170
- ----------
171
- message : str
172
- The warning message to print.
173
- """
174
- Console._print_colored(message, ANSIColors.TEXT_BOLD_WARNING)
175
-
176
- @staticmethod
177
- def fail(message: str, timestamp: bool = True):
178
- """
179
- Prints a failure message with a red background.
180
-
181
- Parameters
182
- ----------
183
- message : str
184
- The failure message to print.
185
- timestamp : bool, optional
186
- Whether to include a timestamp (default is True).
187
- """
188
- Console._print_with_background("FAIL", ANSIColors.BG_FAIL, message, timestamp)
189
-
190
- @staticmethod
191
- def error(message: str, timestamp: bool = True):
192
- """
193
- Prints an error message with a red background.
194
-
195
- Parameters
196
- ----------
197
- message : str
198
- The error message to print.
199
- timestamp : bool, optional
200
- Whether to include a timestamp (default is True).
201
- """
202
- Console._print_with_background("ERROR", ANSIColors.BG_ERROR, message, timestamp)
203
-
204
- @staticmethod
205
- def textError(message: str):
206
- """
207
- Prints an error message in red.
208
-
209
- Parameters
210
- ----------
211
- message : str
212
- The error message to print.
213
- """
214
- Console._print_colored(message, ANSIColors.TEXT_ERROR)
215
-
216
- @staticmethod
217
- def textErrorBold(message: str):
218
- """
219
- Prints a bold error message in red.
220
-
221
- Parameters
222
- ----------
223
- message : str
224
- The error message to print.
225
- """
226
- Console._print_colored(message, ANSIColors.TEXT_BOLD_ERROR)
227
-
228
- @staticmethod
229
- def textMuted(message: str):
230
- """
231
- Prints a muted (gray) message.
232
-
233
- Parameters
234
- ----------
235
- message : str
236
- The message to print.
237
- """
238
- Console._print_colored(message, ANSIColors.TEXT_MUTED)
239
-
240
- @staticmethod
241
- def textMutedBold(message: str):
242
- """
243
- Prints a bold muted (gray) message.
244
-
245
- Parameters
246
- ----------
247
- message : str
248
- The message to print.
249
- """
250
- Console._print_colored(message, ANSIColors.TEXT_BOLD_MUTED)
251
-
252
- @staticmethod
253
- def textUnderline(message: str):
254
- """
255
- Prints an underlined message.
256
-
257
- Parameters
258
- ----------
259
- message : str, optional
260
- The message to print.
261
- """
262
- print(f"{ANSIColors.TEXT_STYLE_UNDERLINE.value}{message}{ANSIColors.DEFAULT.value}")
263
-
264
- @staticmethod
265
- def clear():
266
- """
267
- Clears the console screen.
268
- """
269
- os.system('cls' if os.name == 'nt' else 'clear')
270
-
271
- @staticmethod
272
- def clearLine():
273
- """
274
- Clears the current line in the console.
275
- """
276
- sys.stdout.write("\r \r")
277
- sys.stdout.flush()
278
-
279
- @staticmethod
280
- def line():
281
- """
282
- Prints a horizontal line in the console.
283
- """
284
- print("\n", end="")
285
-
286
- @staticmethod
287
- def newLine(count: int = 1):
288
- """
289
- Prints multiple new lines.
290
-
291
- Parameters
292
- ----------
293
- count : int, optional
294
- The number of new lines to print (default is 1).
295
-
296
- Raises
297
- ------
298
- ValueError
299
- If count is less than or equal to 0.
300
- """
301
- if count <= 0:
302
- raise ValueError(f"Unsupported Value '{count}'")
303
- print("\n" * count, end="")
304
-
305
- @staticmethod
306
- def write(message: str):
307
- """
308
- Prints a message without moving to the next line.
309
-
310
- Parameters
311
- ----------
312
- message : str
313
- The message to print.
314
- """
315
- sys.stdout.write(f"{message}")
316
- sys.stdout.flush()
317
-
318
- @staticmethod
319
- def writeLine(message: str):
320
- """
321
- Prints a message and moves to the next line.
322
-
323
- Parameters
324
- ----------
325
- message : str, optional
326
- The message to print.
327
- """
328
- print(f"{message}")
329
-
330
- @staticmethod
331
- def ask(question: str) -> str:
332
- """
333
- Prompts the user for input with a message and returns the user's response.
334
-
335
- Parameters
336
- ----------
337
- question : str
338
- The question to ask the user.
339
-
340
- Returns
341
- -------
342
- str
343
- The user's input, as a string.
344
- """
345
- return input(f"{ANSIColors.TEXT_INFO.value}{str(question).strip()}{ANSIColors.DEFAULT.value} ")
346
-
347
- @staticmethod
348
- def confirm(question: str, default: bool = False) -> bool:
349
- """
350
- Asks a confirmation question and returns True or False based on the user's response.
351
-
352
- Parameters
353
- ----------
354
- question : str
355
- The confirmation question to ask.
356
- default : bool, optional
357
- The default response if the user presses Enter without typing a response.
358
- Default is False, which corresponds to a 'No' response.
359
-
360
- Returns
361
- -------
362
- bool
363
- The user's response, which will be True if 'Y' is entered,
364
- or False if 'N' is entered or the default is used.
365
- """
366
- response = input(f"{ANSIColors.TEXT_INFO.value}{str(question).strip()} (Y/n): {ANSIColors.DEFAULT.value} ").upper()
367
- return default if not response else str(response).upper in ["Y", "YES"]
368
-
369
- @staticmethod
370
- def secret(question: str) -> str:
371
- """
372
- Prompts the user for hidden input, typically used for password input.
373
-
374
- Parameters
375
- ----------
376
- question : str
377
- The prompt to ask the user.
378
-
379
- Returns
380
- -------
381
- str
382
- The user's hidden input, returned as a string.
383
- """
384
- return getpass.getpass(f"{ANSIColors.TEXT_INFO.value}{str(question).strip()}{ANSIColors.DEFAULT.value} ")
385
-
386
- @staticmethod
387
- def table(headers: list, rows: list):
388
- """
389
- Prints a table in the console with the given headers and rows, with bold headers.
390
-
391
- Parameters
392
- ----------
393
- headers : list of str
394
- The column headers for the table.
395
- rows : list of list of str
396
- The rows of the table, where each row is a list of strings representing the columns.
397
-
398
- Raises
399
- ------
400
- ValueError
401
- If headers or rows are empty.
402
-
403
- Notes
404
- -----
405
- The table adjusts column widths dynamically, includes bold headers, and uses box-drawing characters for formatting.
406
- """
407
- if not headers:
408
- raise ValueError("Headers cannot be empty.")
409
- if not rows:
410
- raise ValueError("Rows cannot be empty.")
411
-
412
- # Determine the maximum width of each column
413
- col_widths = [max(len(str(item)) for item in col) for col in zip(headers, *rows)]
414
-
415
- # Define border characters
416
- top_border = "┌" + "┬".join("─" * (col_width + 2) for col_width in col_widths) + "┐"
417
- separator = "├" + "┼".join("─" * (col_width + 2) for col_width in col_widths) + "┤"
418
- bottom_border = "└" + "┴".join("─" * (col_width + 2) for col_width in col_widths) + "┘"
419
-
420
- # Format the header row with bold text
421
- header_row = "│ " + " │ ".join(f"{ANSIColors.TEXT_BOLD.value}{header:<{col_width}}{ANSIColors.TEXT_RESET.value}" for header, col_width in zip(headers, col_widths)) + " │"
422
-
423
- # Print the table
424
- print(top_border)
425
- print(header_row)
426
- print(separator)
427
-
428
- for row in rows:
429
- row_text = "│ " + " │ ".join(f"{str(item):<{col_width}}" for item, col_width in zip(row, col_widths)) + " │"
430
- print(row_text)
431
-
432
- print(bottom_border)
433
-
434
- @staticmethod
435
- def anticipate(question: str, options: list, default=None):
436
- """
437
- Provides autocomplete suggestions based on user input.
438
-
439
- Parameters
440
- ----------
441
- question : str
442
- The prompt for the user.
443
- options : list of str
444
- The list of possible options for autocomplete.
445
- default : str, optional
446
- The default value if no matching option is found. Defaults to None.
447
-
448
- Returns
449
- -------
450
- str
451
- The chosen option or the default value.
452
-
453
- Notes
454
- -----
455
- This method allows the user to input a string, and then attempts to provide
456
- an autocomplete suggestion by matching the beginning of the input with the
457
- available options. If no match is found, the method returns the default value
458
- or the user input if no default is provided.
459
- """
460
- # Prompt the user for input
461
- input_value = input(f"{ANSIColors.TEXT_INFO.value}{str(question).strip()}{ANSIColors.DEFAULT.value} ")
462
-
463
- # Find the first option that starts with the input value, or use the default value
464
- return next((option for option in options if option.startswith(input_value)), default or input_value)
465
-
466
- @staticmethod
467
- def choice(question: str, choices: list, default_index: int = 0) -> str:
468
- """
469
- Allows the user to select an option from a list.
470
-
471
- Parameters
472
- ----------
473
- question : str
474
- The prompt for the user.
475
- choices : list of str
476
- The list of available choices.
477
- default_index : int, optional
478
- The index of the default choice (zero-based). Defaults to 0.
479
-
480
- Returns
481
- -------
482
- str
483
- The selected choice.
484
-
485
- Raises
486
- ------
487
- ValueError
488
- If `default_index` is out of the range of choices.
489
-
490
- Notes
491
- -----
492
- The user is presented with a numbered list of choices and prompted to select
493
- one by entering the corresponding number. If an invalid input is provided,
494
- the user will be repeatedly prompted until a valid choice is made.
495
- """
496
- if not choices:
497
- raise ValueError("The choices list cannot be empty.")
498
-
499
- if not (0 <= default_index < len(choices)):
500
- raise ValueError(f"Invalid default_index {default_index}. Must be between 0 and {len(choices) - 1}.")
501
-
502
- # Display the question and the choices
503
- print(f"{ANSIColors.TEXT_INFO.value}{question.strip()} (default: {choices[default_index]}):{ANSIColors.DEFAULT.value}")
504
-
505
- for idx, choice in enumerate(choices, 1):
506
- print(f"{ANSIColors.TEXT_MUTED.value}{idx}: {choice}{ANSIColors.DEFAULT.value}")
507
-
508
- # Prompt the user for input
509
- answer = input("Answer: ").strip()
510
-
511
- # If the user provides no input, select the default choice
512
- if not answer:
513
- return choices[default_index]
514
-
515
- # Validate input: ensure it's a number within range
516
- while not answer.isdigit() or not (1 <= int(answer) <= len(choices)):
517
- answer = input("Please select a valid number: ").strip()
518
-
519
- return choices[int(answer) - 1]
520
-
521
- @staticmethod
522
- def exception(e) -> None:
523
- """
524
- Prints an exception message with detailed information.
525
-
526
- Parameters
527
- ----------
528
- exception : Exception
529
- The exception to print.
530
-
531
- Notes
532
- -----
533
- This method prints the exception type, message, and a detailed stack trace.
534
- """
535
-
536
- errors = Parser.exception(e).toDict()
537
- error_type = str(errors.get("error_type")).split(".")[-1]
538
- error_message = str(errors.get("error_message")).replace(error_type, "").replace("[]", "").strip()
539
- stack_trace = errors.get("stack_trace")
540
-
541
- # Format the output with a more eye-catching appearance
542
- message = f"{ANSIColors.BG_ERROR.value}{ANSIColors.TEXT_WHITE.value}[{error_type}]{ANSIColors.TEXT_RESET.value}: {ANSIColors.TEXT_WARNING.value}{error_message}{ANSIColors.TEXT_RESET.value}"
543
- print("▬" * len(f" [{error_type}] : {error_message}"))
544
- print(message)
545
-
546
- real_count = len(stack_trace)
547
- count_error = real_count
548
- for frame in stack_trace:
549
- filename = frame["filename"]
550
- lineno = frame["lineno"]
551
- name = frame["name"]
552
- line = frame["line"]
553
-
554
- # Print the stack trace with enhanced styling
555
- print(f"{ANSIColors.TEXT_MUTED.value}Trace Call ({count_error}/{real_count}){ANSIColors.TEXT_RESET.value} - {ANSIColors.TEXT_WHITE.value}{filename}:{lineno}{ANSIColors.TEXT_RESET.value}")
556
- print(f" {ANSIColors.DIM.value}{ANSIColors.ITALIC.value}{ANSIColors.TEXT_WARNING.value}{name}{ANSIColors.TEXT_RESET.value} : {ANSIColors.CYAN.value}{line}{ANSIColors.TEXT_RESET.value}")
557
- count_error -= 1
558
-
559
- print("▬" * len(f" [{error_type}] : {error_message}"))
560
-
561
- @staticmethod
562
- def exitSuccess(message: str = None) -> None:
563
- """
564
- Exits the program with a success message.
565
-
566
- Parameters
567
- ----------
568
- message : str, optional
569
- The success message to print before exiting.
570
- """
571
- if message:
572
- Console.success(message)
573
- sys.exit(0)
574
-
575
- @staticmethod
576
- def exitError(message: str = None) -> None:
577
- """
578
- Exits the program with an error message.
579
-
580
- Parameters
581
- ----------
582
- message : str, optional
583
- The error message to print before exiting.
584
- """
585
- if message:
586
- Console.error(message)
587
- sys.exit(1)
@@ -1,90 +0,0 @@
1
- from datetime import datetime
2
- from orionis.console.output.enums.styles import ANSIColors
3
- from orionis._contracts.console.output.executor import IExecutor
4
-
5
- class Executor(IExecutor):
6
- """
7
- A utility class for logging program execution states with ANSI color formatting.
8
-
9
- Methods
10
- -------
11
- running(program: str, time: str = ''):
12
- Logs the execution of a program in a "RUNNING" state.
13
- done(program: str, time: str = ''):
14
- Logs the execution of a program in a "DONE" state.
15
- fail(program: str, time: str = ''):
16
- Logs the execution of a program in a "FAIL" state.
17
- """
18
-
19
- @staticmethod
20
- def _ansi_output(program: str, state: str, state_color: str, time: str = ''):
21
- """
22
- Logs a formatted message with timestamp, program name, and execution state.
23
-
24
- Parameters
25
- ----------
26
- program : str
27
- The name of the program being executed.
28
- state : str
29
- The state of execution (e.g., RUNNING, DONE, FAIL).
30
- state_color : str
31
- The ANSI color code for the state.
32
- time : str, optional
33
- The time duration of execution, default is an empty string, example (30s)
34
- """
35
- width = 60
36
- len_state = len(state)
37
- len_time = len(time)
38
- line = '.' * (width - (len(program) + len_state + len_time))
39
-
40
- timestamp = f"{ANSIColors.TEXT_MUTED.value}{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}{ANSIColors.DEFAULT.value}"
41
- program_formatted = f"{program}"
42
- time_formatted = f"{ANSIColors.TEXT_MUTED.value}{time}{ANSIColors.DEFAULT.value}" if time else ""
43
- state_formatted = f"{state_color}{state}{ANSIColors.DEFAULT.value}"
44
-
45
- start = "\n\r" if state == 'RUNNING' else ''
46
- end = "\n\r" if state != 'RUNNING' else ''
47
-
48
- print(f"{start}{timestamp} | {program_formatted} {line} {time_formatted} {state_formatted}{end}")
49
-
50
- @staticmethod
51
- def running(program: str, time: str = ''):
52
- """
53
- Logs the execution of a program in a "RUNNING" state.
54
-
55
- Parameters
56
- ----------
57
- program : str
58
- The name of the program being executed.
59
- time : str, optional
60
- The time duration of execution, default is an empty string.
61
- """
62
- Executor._ansi_output(program, "RUNNING", ANSIColors.TEXT_BOLD_WARNING.value, time)
63
-
64
- @staticmethod
65
- def done(program: str, time: str = ''):
66
- """
67
- Logs the execution of a program in a "DONE" state.
68
-
69
- Parameters
70
- ----------
71
- program : str
72
- The name of the program being executed.
73
- time : str, optional
74
- The time duration of execution, default is an empty string.
75
- """
76
- Executor._ansi_output(program, "DONE", ANSIColors.TEXT_BOLD_SUCCESS.value, time)
77
-
78
- @staticmethod
79
- def fail(program: str, time: str = ''):
80
- """
81
- Logs the execution of a program in a "FAIL" state.
82
-
83
- Parameters
84
- ----------
85
- program : str
86
- The name of the program being executed.
87
- time : str, optional
88
- The time duration of execution, default is an empty string.
89
- """
90
- Executor._ansi_output(program, "FAIL", ANSIColors.TEXT_BOLD_ERROR.value, time)