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,418 +0,0 @@
1
- import os
2
- import sys
3
- import inspect
4
- import json
5
- from typing import Any
6
- from datetime import datetime
7
- from dataclasses import is_dataclass
8
- from rich.console import Console
9
- from rich.panel import Panel
10
- from rich.table import Table
11
- from rich.syntax import Syntax
12
- from rich.traceback import install
13
-
14
- class Debug:
15
- """
16
- Debugging utility class for enhanced output and inspection of Python objects.
17
- This class provides methods for dumping and inspecting data in various formats,
18
- including plain text, JSON, and tabular representations. It also supports
19
- rendering nested structures with recursion handling and customizable indentation.
20
- """
21
-
22
- def __init__(self, line:str = None) -> None:
23
- """
24
- Initializes the class instance.
25
-
26
- This constructor sets up the necessary components for the class, including:
27
- - Installing required dependencies or configurations.
28
- - Initializing a console for output handling.
29
- - Setting the default indentation size for formatting.
30
- - Creating a set to guard against recursion during operations.
31
- """
32
- install()
33
- self.console = Console()
34
- self.indent_size = 4
35
- self._recursion_guard = set()
36
- self.line_tcbk = line
37
-
38
- def dd(self, *args: Any) -> None:
39
- """
40
- Dumps the provided arguments to the output and exits the program.
41
-
42
- Args:
43
- *args (Any): Variable length argument list to be processed and output.
44
-
45
- Returns:
46
- None
47
- """
48
- self.__processOutput(*args, exit_after=True)
49
-
50
- def dump(self, *args: Any) -> None:
51
- """
52
- Dumps the provided arguments for debugging or logging purposes.
53
-
54
- Args:
55
- *args (Any): Variable length argument list to be processed and output.
56
-
57
- Returns:
58
- None
59
- """
60
- self.__processOutput(*args, exit_after=False)
61
-
62
- def __processOutput(self, *args: Any, exit_after: bool) -> None:
63
- """
64
- Processes the output based on the provided arguments and determines the appropriate
65
- format for displaying the data (tabular, JSON, or raw dump). Handles exceptions
66
- during processing and optionally exits the program.
67
-
68
- Args:
69
- *args (Any): Variable-length arguments representing the data to be processed.
70
- exit_after (bool): If True, the program will exit after processing the output.
71
-
72
- Raises:
73
- Exception: Catches and logs any exception that occurs during processing. If
74
- `exit_after` is True, the program will terminate with an exit code of 1.
75
- """
76
- try:
77
- if not args:
78
- raise ValueError("No arguments were provided, or the arguments are null or invalid")
79
- elif len(args) == 1:
80
- arg = args[0]
81
- if self.__isJsonSerializable(arg) and self.__isTabular(arg) and isinstance(arg, (list)):
82
- self.__printTable(arg)
83
- elif self.__isJsonSerializable(arg):
84
- self.__printJson(arg)
85
- else:
86
- self.__printDump(args)
87
- else:
88
- self.__printDump(args)
89
- except Exception as e:
90
- self.__printStandardPanel(
91
- f"[bold red]An error occurred while processing the debug output: {str(e)}[/]",
92
- border_style="red",
93
- )
94
- finally:
95
- if exit_after:
96
- os._exit(1)
97
-
98
- def __printDump(self, args: tuple) -> None:
99
- """
100
- Prints a formatted dump of the provided arguments to the console and optionally exits the program.
101
- Args:
102
- args (tuple): A tuple containing the objects to be dumped and displayed.
103
- Returns:
104
- None
105
- """
106
- content = []
107
- for arg in args:
108
- self._recursion_guard.clear()
109
- content.append(self.__render(arg))
110
-
111
- self.__printStandardPanel(
112
- Syntax(
113
- "\n".join(content),
114
- "python",
115
- line_numbers=False,
116
- background_color="default",
117
- word_wrap=True
118
- ),
119
- border_style="cyan bold",
120
- )
121
-
122
- def __printJson(self, data: Any) -> None:
123
- """
124
- Prints a JSON representation of the given data to the console using a styled panel.
125
- Args:
126
- data (Any): The data to be serialized and displayed as JSON.
127
- Raises:
128
- TypeError: If the data cannot be serialized to JSON, falls back to a generic dump method.
129
- Notes:
130
- - Uses the `rich` library to format and display the JSON output with syntax highlighting.
131
- - Retrieves and displays the caller's line information for context.
132
- - Handles non-serializable objects using a custom JSON serializer.
133
- """
134
- try:
135
- if not isinstance(data, (dict, list)):
136
- raise TypeError("Data must be a dictionary or a list for JSON serialization.")
137
-
138
- json_str = json.dumps(data, ensure_ascii=False, indent=2, default=self.__jsonSerializer)
139
- self.__printStandardPanel(
140
- Syntax(
141
- json_str,
142
- "json",
143
- line_numbers=True,
144
- background_color="default",
145
- word_wrap=True
146
- ),
147
- border_style="green",
148
- )
149
- except TypeError as e:
150
- self.__printDump((data,))
151
-
152
- def __printTable(self, data: Any) -> None:
153
- """
154
- Prints a formatted table representation of the given data using the `rich` library.
155
- Args:
156
- data (Any): The data to be displayed in the table. It can be a list, dictionary,
157
- or an object with attributes.
158
- Behavior:
159
- - If `data` is a list:
160
- - If the list is empty, prints a message indicating an empty list.
161
- - If the list contains dictionaries, uses the dictionary keys as column headers.
162
- - If the list contains objects with attributes, uses the attribute names as column headers.
163
- - Otherwise, displays the index and value of each item in the list.
164
- - If `data` is a dictionary:
165
- - Displays the keys and values as two columns.
166
- - If an exception occurs during processing, calls `__printDump` to handle the error.
167
- Note:
168
- This method relies on the `rich.Table` class for rendering the table and assumes
169
- the presence of a `console` object for output and a `__printStandardPanel` method
170
- for displaying the table with a border.
171
- """
172
- try:
173
- table = Table(
174
- show_header=True,
175
- header_style="bold white on blue",
176
- min_width=(self.console.width // 4) * 3
177
- )
178
-
179
- if isinstance(data, list):
180
- if not data:
181
- self.console.print("[yellow]Empty list[/]")
182
- return
183
-
184
- first = data[0]
185
- if isinstance(first, dict):
186
- columns = list(first.keys())
187
- elif hasattr(first, '__dict__'):
188
- columns = list(vars(first).keys())
189
- else:
190
- columns = ["Index", "Value"]
191
-
192
- for col in columns:
193
- table.add_column(str(col))
194
-
195
- for i, item in enumerate(data):
196
- if isinstance(item, dict):
197
- table.add_row(*[str(item.get(col, '')) for col in columns])
198
- elif hasattr(item, '__dict__'):
199
- item_dict = vars(item)
200
- table.add_row(*[str(item_dict.get(col, '')) for col in columns])
201
- else:
202
- table.add_row(str(i), str(item))
203
-
204
- elif isinstance(data, dict):
205
- table.add_column("Key", style="magenta")
206
- table.add_column("Value")
207
-
208
- for k, v in data.items():
209
- table.add_row(str(k), str(v))
210
-
211
- self.__printStandardPanel(
212
- table,
213
- border_style="blue",
214
- )
215
- except Exception as e:
216
- self.__printDump((data,))
217
-
218
- def __printStandardPanel(self, renderable, border_style: str, padding=(0, 1)) -> None:
219
- """
220
- Renders a standard panel with the given content and styling options.
221
- Args:
222
- renderable: The content to be displayed inside the panel. This can be any renderable object.
223
- border_style (str): The style of the border for the panel.
224
- padding (tuple, optional): A tuple specifying the padding inside the panel as (vertical, horizontal). Defaults to (0, 0).
225
- expand (bool, optional): Whether the panel should expand to fill available space. Defaults to False.
226
- Returns:
227
- None
228
- """
229
- if self.line_tcbk is None:
230
- frame = inspect.currentframe()
231
- caller_frame = frame.f_back.f_back.f_back.f_back if frame else None
232
- line_info = f"[blue underline]{self.__getLineInfo(caller_frame) if caller_frame else 'Unknown location'}[/]"
233
- else:
234
- line_info = f"[blue underline]{self.line_tcbk}[/]"
235
-
236
- subtitle = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
237
-
238
- self.console.print()
239
- self.console.print(Panel(
240
- renderable,
241
- title=f"Debugger - {line_info}",
242
- title_align='left',
243
- subtitle=subtitle,
244
- subtitle_align='right',
245
- border_style=border_style,
246
- highlight=True,
247
- padding=padding,
248
- width=(self.console.width // 4) * 3,
249
- ))
250
- self.console.print()
251
-
252
- def __isTabular(self, data: Any) -> bool:
253
- """
254
- Determines if the given data is in a tabular format.
255
-
256
- A data structure is considered tabular if it is a list or a dictionary.
257
- For lists, it further checks if the first element is either a dictionary
258
- or an object with attributes (i.e., has a `__dict__` attribute).
259
-
260
- Args:
261
- data (Any): The data to be checked.
262
-
263
- Returns:
264
- bool: True if the data is tabular, False otherwise.
265
- """
266
-
267
- if isinstance(data, list):
268
- if all(isinstance(item, dict) for item in data):
269
- keys = set(data[0].keys())
270
- return all(set(item.keys()) == keys for item in data)
271
- if len(data) > 0 and hasattr(data[0], '__dict__'):
272
- return True
273
- elif isinstance(data, dict):
274
- return True
275
- return False
276
-
277
- def __isJsonSerializable(self, data: Any) -> bool:
278
- """
279
- Determines if the given data is JSON serializable.
280
-
281
- This method attempts to serialize the provided data into a JSON string
282
- using a custom serializer. If the serialization succeeds, the data is
283
- considered JSON serializable. Otherwise, it is not.
284
-
285
- Args:
286
- data (Any): The data to check for JSON serializability.
287
-
288
- Returns:
289
- bool: True if the data is JSON serializable, False otherwise.
290
- """
291
- try:
292
- json.dumps(data, default=self.__jsonSerializer)
293
- return True
294
- except (TypeError, OverflowError):
295
- return False
296
-
297
- def __render(self, value: Any, indent: int = 0, key: Any = None, depth: int = 0) -> str:
298
- """
299
- Recursively renders a string representation of a given value with customizable indentation,
300
- handling various data types, recursion, and depth limits.
301
- Args:
302
- value (Any): The value to render. Can be of any type, including dict, list, tuple, set,
303
- dataclass, or objects with a `__dict__` attribute.
304
- indent (int, optional): The current indentation level. Defaults to 0.
305
- key (Any, optional): The key or index associated with the value, if applicable. Defaults to None.
306
- depth (int, optional): The current recursion depth. Defaults to 0.
307
- Returns:
308
- str: A string representation of the value, formatted with indentation and type information.
309
- Notes:
310
- - Limits recursion depth to 10 to prevent infinite loops.
311
- - Detects and handles recursive references to avoid infinite recursion.
312
- - Supports rendering of common Python data structures, dataclasses, and objects with attributes.
313
- - Formats datetime objects and callable objects with additional details.
314
- """
315
-
316
- if depth > 10:
317
- return "... (max depth)"
318
-
319
- obj_id = id(value)
320
- if obj_id in self._recursion_guard:
321
- return "... (recursive)"
322
- self._recursion_guard.add(obj_id)
323
-
324
- space = ' ' * indent
325
- prefix = f"{space}"
326
-
327
- if key is not None:
328
- prefix += f"{self.__formatKey(key)} => "
329
-
330
- if value is None:
331
- result = f"{prefix}None"
332
- elif isinstance(value, dict):
333
- result = f"{prefix}dict({len(value)})"
334
- for k, v in value.items():
335
- result += "\n" + self.__render(v, indent + self.indent_size, k, depth + 1)
336
- elif isinstance(value, (list, tuple, set)):
337
- type_name = type(value).__name__
338
- result = f"{prefix}{type_name}({len(value)})"
339
- for i, item in enumerate(value):
340
- result += "\n" + self.__render(
341
- item,
342
- indent + self.indent_size,
343
- i if isinstance(value, (list, tuple)) else None,
344
- depth + 1
345
- )
346
- elif is_dataclass(value):
347
- result = f"{prefix}{value.__class__.__name__}"
348
- for k, v in vars(value).items():
349
- result += "\n" + self.__render(v, indent + self.indent_size, k, depth + 1)
350
- elif hasattr(value, "__dict__"):
351
- result = f"{prefix}{value.__class__.__name__}"
352
- for k, v in vars(value).items():
353
- result += "\n" + self.__render(v, indent + self.indent_size, k, depth + 1)
354
- elif isinstance(value, datetime):
355
- result = f"{prefix}datetime({value.isoformat()})"
356
- elif callable(value):
357
- result = f"{prefix}callable({value.__name__ if hasattr(value, '__name__') else repr(value)})"
358
- else:
359
- result = f"{prefix}{type(value).__name__}({repr(value)})"
360
-
361
- self._recursion_guard.discard(obj_id)
362
- return result
363
-
364
- @staticmethod
365
- def __jsonSerializer(obj):
366
- """
367
- Serialize an object into a JSON-compatible format.
368
- Args:
369
- obj: The object to serialize. Supported types include:
370
- - datetime: Converted to ISO 8601 string format.
371
- - Objects with a `__dict__` attribute: Converted to a dictionary of their attributes.
372
- - set or tuple: Converted to a list.
373
- Returns:
374
- A JSON-serializable representation of the input object.
375
- Raises:
376
- TypeError: If the object type is not supported for JSON serialization.
377
- """
378
- if isinstance(obj, datetime):
379
- return obj.isoformat()
380
- elif hasattr(obj, '__dict__'):
381
- return vars(obj)
382
- elif isinstance(obj, (set, tuple)):
383
- return list(obj)
384
- raise TypeError(f"Object of type {obj.__class__.__name__} is not JSON serializable")
385
-
386
- @staticmethod
387
- def __formatKey(key: Any) -> str:
388
- """
389
- Formats a given key into a string representation.
390
-
391
- Args:
392
- key (Any): The key to be formatted. It can be of any type.
393
-
394
- Returns:
395
- str: A string representation of the key. If the key is a string, it is
396
- enclosed in double quotes. Otherwise, the string representation of the
397
- key is returned as-is.
398
- """
399
- if isinstance(key, str):
400
- return f'"{key}"'
401
- return str(key)
402
-
403
- @staticmethod
404
- def __getLineInfo(frame: inspect.FrameInfo) -> str:
405
- """
406
- Extracts and formats line information from a given frame.
407
-
408
- Args:
409
- frame (inspect.FrameInfo): The frame object containing code context.
410
-
411
- Returns:
412
- str: A string in the format "filename:line_no", where `filename` is the
413
- name of the file (excluding the path) and `line_no` is the line number
414
- in the file where the frame is located.
415
- """
416
- filename = frame.f_code.co_filename.split('/')[-1]
417
- line_no = frame.f_lineno
418
- return f"{filename}:{line_no}"
File without changes
@@ -1,31 +0,0 @@
1
- from typing import Any
2
- from orionis._contracts.console.kernel import ICLIKernel
3
-
4
- class CLIKernel(ICLIKernel):
5
- """
6
- CLIKernel acts as a bridge between the CLI entry point and the command runner.
7
-
8
- This class provides a static method to handle command execution via `CLIRunner`.
9
-
10
- Methods
11
- -------
12
- handle(*args: tuple[Any, ...]) -> Any
13
- Processes CLI arguments and delegates execution to `CLIRunner`.
14
- """
15
-
16
- @staticmethod
17
- def handle(*args: tuple[Any, ...]) -> Any:
18
- """
19
- Handles CLI command execution by forwarding arguments to `CLIRunner`.
20
-
21
- Parameters
22
- ----------
23
- *args : tuple[Any, ...]
24
- A tuple containing CLI arguments passed from the command line.
25
-
26
- Returns
27
- -------
28
- Any
29
- The result of the executed command.
30
- """
31
- pass
File without changes