janito 3.3.0__py3-none-any.whl → 3.4.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.
- janito/cli/cli_commands/list_plugins.py +48 -52
- janito/cli/core/getters.py +0 -3
- janito/cli/main_cli.py +12 -9
- janito/drivers/openai/driver.py +0 -1
- janito/drivers/zai/driver.py +0 -1
- janito/hello.txt +0 -0
- janito/llm/auth_utils.py +5 -14
- janito/plugins/__init__.py +7 -18
- janito/{plugins_backup_20250825_070018 → plugins}/auto_loader_fixed.py +11 -12
- janito/plugins/base.py +152 -57
- janito/plugins/builtin.py +1 -15
- janito/{plugins_backup_20250825_070018 → plugins}/core_adapter.py +9 -11
- janito/plugins/core_loader.py +34 -58
- janito/{plugin_system_backup_20250825_070018/core_loader.py → plugins/core_loader_fixed.py} +26 -45
- janito/plugins/discovery.py +3 -3
- janito/tools/__init__.py +7 -31
- janito/tools/adapters/__init__.py +1 -6
- janito/tools/adapters/local/__init__.py +70 -7
- janito/{plugins_backup_20250825_070018/tools → tools/adapters/local}/ask_user.py +3 -3
- janito/{plugins_backup_20250825_070018/tools → tools/adapters/local}/create_file.py +4 -4
- janito/{plugins/core/filemanager/tools → tools/adapters/local}/delete_text_in_file.py +0 -1
- janito/{plugins_backup_20250825_070018/tools → tools/adapters/local}/fetch_url.py +3 -3
- janito/{plugins_backup_20250825_070018/tools → tools/adapters/local}/replace_text_in_file.py +4 -4
- janito/{plugins_backup_20250825_070018/tools → tools/adapters/local}/show_image.py +6 -15
- janito/{plugins/core/imagedisplay/tools → tools/adapters/local}/show_image_grid.py +5 -13
- janito/tools/base.py +1 -31
- janito/tools/function_adapter.py +16 -127
- janito/tools/tool_base.py +114 -142
- janito/tools/tools_schema.py +6 -12
- {janito-3.3.0.dist-info → janito-3.4.0.dist-info}/METADATA +2 -1
- janito-3.4.0.dist-info/RECORD +264 -0
- janito/cli/cli_commands/check_tools.py +0 -212
- janito/plugin_system_backup_20250825_070018/__init__.py +0 -10
- janito/plugin_system_backup_20250825_070018/base.py +0 -155
- janito/plugin_system_backup_20250825_070018/core_loader_fixed.py +0 -149
- janito/plugins/__main__.py +0 -85
- janito/plugins/core/__init__.py +0 -7
- janito/plugins/core/codeanalyzer/__init__.py +0 -43
- janito/plugins/core/filemanager/__init__.py +0 -124
- janito/plugins/core/filemanager/tools/copy_file.py +0 -111
- janito/plugins/core/filemanager/tools/create_directory.py +0 -97
- janito/plugins/core/filemanager/tools/create_file.py +0 -111
- janito/plugins/core/filemanager/tools/replace_text_in_file.py +0 -270
- janito/plugins/core/imagedisplay/__init__.py +0 -14
- janito/plugins/core/imagedisplay/plugin.py +0 -51
- janito/plugins/core/imagedisplay/tools/__init__.py +0 -1
- janito/plugins/core/imagedisplay/tools/show_image.py +0 -83
- janito/plugins/core/system/__init__.py +0 -23
- janito/plugins/dev/__init__.py +0 -7
- janito/plugins/dev/pythondev/__init__.py +0 -37
- janito/plugins/dev/visualization/__init__.py +0 -23
- janito/plugins/example_plugin.py +0 -108
- janito/plugins/ui/__init__.py +0 -7
- janito/plugins/ui/userinterface/__init__.py +0 -16
- janito/plugins/ui/userinterface/tools/ask_user.py +0 -110
- janito/plugins/web/__init__.py +0 -7
- janito/plugins/web/webtools/__init__.py +0 -33
- janito/plugins/web/webtools/tools/fetch_url.py +0 -458
- janito/plugins_backup_20250825_070018/__init__.py +0 -36
- janito/plugins_backup_20250825_070018/builtin.py +0 -102
- janito/plugins_backup_20250825_070018/config.py +0 -84
- janito/plugins_backup_20250825_070018/core/__init__.py +0 -7
- janito/plugins_backup_20250825_070018/core/codeanalyzer/__init__.py +0 -43
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/get_file_outline/__init__.py +0 -1
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/get_file_outline/core.py +0 -122
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/get_file_outline/java_outline.py +0 -47
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/get_file_outline/markdown_outline.py +0 -14
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/get_file_outline/python_outline.py +0 -303
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/get_file_outline/search_outline.py +0 -36
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/search_text/__init__.py +0 -1
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/search_text/core.py +0 -205
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/search_text/match_lines.py +0 -67
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/search_text/pattern_utils.py +0 -73
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/search_text/traverse_directory.py +0 -145
- janito/plugins_backup_20250825_070018/core/filemanager/__init__.py +0 -124
- janito/plugins_backup_20250825_070018/core/filemanager/tools/create_file.py +0 -87
- janito/plugins_backup_20250825_070018/core/filemanager/tools/delete_text_in_file.py +0 -135
- janito/plugins_backup_20250825_070018/core/filemanager/tools/find_files.py +0 -143
- janito/plugins_backup_20250825_070018/core/filemanager/tools/move_file.py +0 -131
- janito/plugins_backup_20250825_070018/core/filemanager/tools/read_files.py +0 -58
- janito/plugins_backup_20250825_070018/core/filemanager/tools/remove_directory.py +0 -55
- janito/plugins_backup_20250825_070018/core/filemanager/tools/remove_file.py +0 -58
- janito/plugins_backup_20250825_070018/core/filemanager/tools/replace_text_in_file.py +0 -270
- janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/__init__.py +0 -1
- janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/core.py +0 -114
- janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/css_validator.py +0 -35
- janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/html_validator.py +0 -100
- janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/jinja2_validator.py +0 -50
- janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/js_validator.py +0 -27
- janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/json_validator.py +0 -6
- janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/markdown_validator.py +0 -109
- janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/ps1_validator.py +0 -32
- janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/python_validator.py +0 -5
- janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/xml_validator.py +0 -11
- janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/yaml_validator.py +0 -6
- janito/plugins_backup_20250825_070018/core/filemanager/tools/view_file.py +0 -172
- janito/plugins_backup_20250825_070018/core/imagedisplay/__init__.py +0 -14
- janito/plugins_backup_20250825_070018/core/imagedisplay/plugin.py +0 -51
- janito/plugins_backup_20250825_070018/core/imagedisplay/tools/__init__.py +0 -1
- janito/plugins_backup_20250825_070018/core/imagedisplay/tools/show_image.py +0 -83
- janito/plugins_backup_20250825_070018/core/imagedisplay/tools/show_image_grid.py +0 -84
- janito/plugins_backup_20250825_070018/core/system/__init__.py +0 -23
- janito/plugins_backup_20250825_070018/core/system/tools/run_bash_command.py +0 -183
- janito/plugins_backup_20250825_070018/core/system/tools/run_powershell_command.py +0 -218
- janito/plugins_backup_20250825_070018/dev/__init__.py +0 -7
- janito/plugins_backup_20250825_070018/dev/pythondev/__init__.py +0 -37
- janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_code_run.py +0 -172
- janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_command_run.py +0 -171
- janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_file_run.py +0 -172
- janito/plugins_backup_20250825_070018/dev/visualization/__init__.py +0 -23
- janito/plugins_backup_20250825_070018/dev/visualization/tools/read_chart.py +0 -259
- janito/plugins_backup_20250825_070018/discovery.py +0 -289
- janito/plugins_backup_20250825_070018/example_plugin.py +0 -108
- janito/plugins_backup_20250825_070018/manager.py +0 -243
- janito/plugins_backup_20250825_070018/tools/__init__.py +0 -10
- janito/plugins_backup_20250825_070018/tools/copy_file.py +0 -87
- janito/plugins_backup_20250825_070018/tools/core_tools_plugin.py +0 -88
- janito/plugins_backup_20250825_070018/tools/create_directory.py +0 -70
- janito/plugins_backup_20250825_070018/tools/decorators.py +0 -19
- janito/plugins_backup_20250825_070018/tools/delete_text_in_file.py +0 -135
- janito/plugins_backup_20250825_070018/tools/find_files.py +0 -143
- janito/plugins_backup_20250825_070018/tools/get_file_outline/__init__.py +0 -7
- janito/plugins_backup_20250825_070018/tools/get_file_outline/core.py +0 -122
- janito/plugins_backup_20250825_070018/tools/get_file_outline/java_outline.py +0 -47
- janito/plugins_backup_20250825_070018/tools/get_file_outline/markdown_outline.py +0 -14
- janito/plugins_backup_20250825_070018/tools/get_file_outline/python_outline.py +0 -303
- janito/plugins_backup_20250825_070018/tools/get_file_outline/search_outline.py +0 -36
- janito/plugins_backup_20250825_070018/tools/move_file.py +0 -131
- janito/plugins_backup_20250825_070018/tools/open_html_in_browser.py +0 -51
- janito/plugins_backup_20250825_070018/tools/open_url.py +0 -37
- janito/plugins_backup_20250825_070018/tools/python_code_run.py +0 -172
- janito/plugins_backup_20250825_070018/tools/python_command_run.py +0 -171
- janito/plugins_backup_20250825_070018/tools/python_file_run.py +0 -172
- janito/plugins_backup_20250825_070018/tools/read_chart.py +0 -259
- janito/plugins_backup_20250825_070018/tools/read_files.py +0 -58
- janito/plugins_backup_20250825_070018/tools/remove_directory.py +0 -55
- janito/plugins_backup_20250825_070018/tools/remove_file.py +0 -58
- janito/plugins_backup_20250825_070018/tools/run_bash_command.py +0 -183
- janito/plugins_backup_20250825_070018/tools/run_powershell_command.py +0 -218
- janito/plugins_backup_20250825_070018/tools/search_text/__init__.py +0 -7
- janito/plugins_backup_20250825_070018/tools/search_text/core.py +0 -205
- janito/plugins_backup_20250825_070018/tools/search_text/match_lines.py +0 -67
- janito/plugins_backup_20250825_070018/tools/search_text/pattern_utils.py +0 -73
- janito/plugins_backup_20250825_070018/tools/search_text/traverse_directory.py +0 -145
- janito/plugins_backup_20250825_070018/tools/show_image_grid.py +0 -85
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/__init__.py +0 -7
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/core.py +0 -114
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/css_validator.py +0 -35
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/html_validator.py +0 -100
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/jinja2_validator.py +0 -50
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/js_validator.py +0 -27
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/json_validator.py +0 -6
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/markdown_validator.py +0 -109
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/ps1_validator.py +0 -32
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/python_validator.py +0 -5
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/xml_validator.py +0 -11
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/yaml_validator.py +0 -6
- janito/plugins_backup_20250825_070018/tools/view_file.py +0 -172
- janito/plugins_backup_20250825_070018/ui/__init__.py +0 -7
- janito/plugins_backup_20250825_070018/ui/userinterface/__init__.py +0 -16
- janito/plugins_backup_20250825_070018/ui/userinterface/tools/ask_user.py +0 -110
- janito/plugins_backup_20250825_070018/web/__init__.py +0 -7
- janito/plugins_backup_20250825_070018/web/webtools/__init__.py +0 -33
- janito/plugins_backup_20250825_070018/web/webtools/tools/fetch_url.py +0 -458
- janito/plugins_backup_20250825_070018/web/webtools/tools/open_html_in_browser.py +0 -51
- janito/plugins_backup_20250825_070018/web/webtools/tools/open_url.py +0 -37
- janito/tools/cli_initializer.py +0 -88
- janito/tools/initialize.py +0 -70
- janito-3.3.0.dist-info/RECORD +0 -400
- /janito/{plugins_backup_20250825_070018 → plugins}/auto_loader.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/discovery_core.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager/tools → tools/adapters/local}/copy_file.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager/tools → tools/adapters/local}/create_directory.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/find_files.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/__init__.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/core.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/java_outline.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/markdown_outline.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/python_outline.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/search_outline.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/move_file.py +0 -0
- /janito/{plugins/web/webtools/tools → tools/adapters/local}/open_html_in_browser.py +0 -0
- /janito/{plugins/web/webtools/tools → tools/adapters/local}/open_url.py +0 -0
- /janito/{plugins/dev/pythondev/tools → tools/adapters/local}/python_code_run.py +0 -0
- /janito/{plugins/dev/pythondev/tools → tools/adapters/local}/python_command_run.py +0 -0
- /janito/{plugins/dev/pythondev/tools → tools/adapters/local}/python_file_run.py +0 -0
- /janito/{plugins/dev/visualization/tools → tools/adapters/local}/read_chart.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/read_files.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/remove_directory.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/remove_file.py +0 -0
- /janito/{plugins/core/system/tools → tools/adapters/local}/run_bash_command.py +0 -0
- /janito/{plugins/core/system/tools → tools/adapters/local}/run_powershell_command.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/__init__.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/core.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/match_lines.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/pattern_utils.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/traverse_directory.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/__init__.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/core.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/css_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/html_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/jinja2_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/js_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/json_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/markdown_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/ps1_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/python_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/xml_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/yaml_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/view_file.py +0 -0
- {janito-3.3.0.dist-info → janito-3.4.0.dist-info}/WHEEL +0 -0
- {janito-3.3.0.dist-info → janito-3.4.0.dist-info}/entry_points.txt +0 -0
- {janito-3.3.0.dist-info → janito-3.4.0.dist-info}/licenses/LICENSE +0 -0
- {janito-3.3.0.dist-info → janito-3.4.0.dist-info}/top_level.txt +0 -0
@@ -1,171 +0,0 @@
|
|
1
|
-
import subprocess
|
2
|
-
import os
|
3
|
-
import sys
|
4
|
-
import tempfile
|
5
|
-
import threading
|
6
|
-
from janito.tools.tool_base import ToolBase, ToolPermissions
|
7
|
-
from janito.report_events import ReportAction
|
8
|
-
from janito.tools.adapters.local.adapter import register_local_tool
|
9
|
-
from janito.i18n import tr
|
10
|
-
|
11
|
-
|
12
|
-
@register_local_tool
|
13
|
-
class PythonCommandRunTool(ToolBase):
|
14
|
-
"""
|
15
|
-
Tool to execute Python code using the `python -c` command-line flag.
|
16
|
-
|
17
|
-
Args:
|
18
|
-
code (str): The Python code to execute as a string.
|
19
|
-
timeout (int): Timeout in seconds for the command. Defaults to 60.
|
20
|
-
silent (bool): If True, suppresses progress and status messages. Defaults to False.
|
21
|
-
|
22
|
-
Returns:
|
23
|
-
str: Output and status message, or file paths/line counts if output is large.
|
24
|
-
"""
|
25
|
-
|
26
|
-
permissions = ToolPermissions(execute=True)
|
27
|
-
tool_name = "python_command_run"
|
28
|
-
|
29
|
-
def run(self, code: str, timeout: int = 60, silent: bool = False) -> str:
|
30
|
-
if not code.strip():
|
31
|
-
self.report_warning(tr("ℹ️ Empty code provided."), ReportAction.EXECUTE)
|
32
|
-
return tr("Warning: Empty code provided. Operation skipped.")
|
33
|
-
if not silent:
|
34
|
-
self.report_action(
|
35
|
-
tr("🐍 Running: python -c ...\n{code}\n", code=code),
|
36
|
-
ReportAction.EXECUTE,
|
37
|
-
)
|
38
|
-
self.report_stdout("\n")
|
39
|
-
else:
|
40
|
-
self.report_action(tr("⚡ Executing..."), ReportAction.EXECUTE)
|
41
|
-
try:
|
42
|
-
with (
|
43
|
-
tempfile.NamedTemporaryFile(
|
44
|
-
mode="w+",
|
45
|
-
prefix="python_cmd_stdout_",
|
46
|
-
delete=False,
|
47
|
-
encoding="utf-8",
|
48
|
-
) as stdout_file,
|
49
|
-
tempfile.NamedTemporaryFile(
|
50
|
-
mode="w+",
|
51
|
-
prefix="python_cmd_stderr_",
|
52
|
-
delete=False,
|
53
|
-
encoding="utf-8",
|
54
|
-
) as stderr_file,
|
55
|
-
):
|
56
|
-
process = subprocess.Popen(
|
57
|
-
[sys.executable, "-c", code],
|
58
|
-
stdout=subprocess.PIPE,
|
59
|
-
stderr=subprocess.PIPE,
|
60
|
-
text=True,
|
61
|
-
bufsize=1,
|
62
|
-
universal_newlines=True,
|
63
|
-
encoding="utf-8",
|
64
|
-
env={**os.environ, "PYTHONIOENCODING": "utf-8"},
|
65
|
-
)
|
66
|
-
stdout_lines, stderr_lines = self._stream_process_output(
|
67
|
-
process, stdout_file, stderr_file
|
68
|
-
)
|
69
|
-
return_code = self._wait_for_process(process, timeout)
|
70
|
-
if return_code is None:
|
71
|
-
return tr(
|
72
|
-
"Code timed out after {timeout} seconds.", timeout=timeout
|
73
|
-
)
|
74
|
-
stdout_file.flush()
|
75
|
-
stderr_file.flush()
|
76
|
-
if not silent:
|
77
|
-
self.report_success(
|
78
|
-
tr("✅ Return code {return_code}", return_code=return_code),
|
79
|
-
ReportAction.EXECUTE,
|
80
|
-
)
|
81
|
-
return self._format_result(
|
82
|
-
stdout_file.name, stderr_file.name, return_code
|
83
|
-
)
|
84
|
-
except Exception as e:
|
85
|
-
self.report_error(tr("❌ Error: {error}", error=e), ReportAction.EXECUTE)
|
86
|
-
return tr("Error running code: {error}", error=e)
|
87
|
-
|
88
|
-
def _stream_process_output(self, process, stdout_file, stderr_file):
|
89
|
-
stdout_lines = 0
|
90
|
-
stderr_lines = 0
|
91
|
-
|
92
|
-
def stream_output(stream, file_obj, report_func, count_func):
|
93
|
-
nonlocal stdout_lines, stderr_lines
|
94
|
-
for line in stream:
|
95
|
-
file_obj.write(line)
|
96
|
-
file_obj.flush()
|
97
|
-
from janito.tools.tool_base import ReportAction
|
98
|
-
|
99
|
-
report_func(line.rstrip("\r\n"), ReportAction.EXECUTE)
|
100
|
-
if count_func == "stdout":
|
101
|
-
stdout_lines += 1
|
102
|
-
else:
|
103
|
-
stderr_lines += 1
|
104
|
-
|
105
|
-
stdout_thread = threading.Thread(
|
106
|
-
target=stream_output,
|
107
|
-
args=(process.stdout, stdout_file, self.report_stdout, "stdout"),
|
108
|
-
)
|
109
|
-
stderr_thread = threading.Thread(
|
110
|
-
target=stream_output,
|
111
|
-
args=(process.stderr, stderr_file, self.report_stderr, "stderr"),
|
112
|
-
)
|
113
|
-
stdout_thread.start()
|
114
|
-
stderr_thread.start()
|
115
|
-
stdout_thread.join()
|
116
|
-
stderr_thread.join()
|
117
|
-
return stdout_lines, stderr_lines
|
118
|
-
|
119
|
-
def _wait_for_process(self, process, timeout):
|
120
|
-
try:
|
121
|
-
return process.wait(timeout=timeout)
|
122
|
-
except subprocess.TimeoutExpired:
|
123
|
-
process.kill()
|
124
|
-
self.report_error(
|
125
|
-
tr("❌ Timed out after {timeout} seconds.", timeout=timeout),
|
126
|
-
ReportAction.EXECUTE,
|
127
|
-
)
|
128
|
-
return None
|
129
|
-
|
130
|
-
def _format_result(self, stdout_file_name, stderr_file_name, return_code):
|
131
|
-
with open(stdout_file_name, "r", encoding="utf-8", errors="replace") as out_f:
|
132
|
-
stdout_content = out_f.read()
|
133
|
-
with open(stderr_file_name, "r", encoding="utf-8", errors="replace") as err_f:
|
134
|
-
stderr_content = err_f.read()
|
135
|
-
max_lines = 100
|
136
|
-
stdout_lines = stdout_content.count("\n")
|
137
|
-
stderr_lines = stderr_content.count("\n")
|
138
|
-
|
139
|
-
def head_tail(text, n=10):
|
140
|
-
lines = text.splitlines()
|
141
|
-
if len(lines) <= 2 * n:
|
142
|
-
return "\n".join(lines)
|
143
|
-
return "\n".join(
|
144
|
-
lines[:n]
|
145
|
-
+ ["... ({} lines omitted) ...".format(len(lines) - 2 * n)]
|
146
|
-
+ lines[-n:]
|
147
|
-
)
|
148
|
-
|
149
|
-
if stdout_lines <= max_lines and stderr_lines <= max_lines:
|
150
|
-
result = f"Return code: {return_code}\n--- python_command_run: STDOUT ---\n{stdout_content}"
|
151
|
-
if stderr_content.strip():
|
152
|
-
result += f"\n--- python_command_run: STDERR ---\n{stderr_content}"
|
153
|
-
return result
|
154
|
-
else:
|
155
|
-
result = f"stdout_file: {stdout_file_name} (lines: {stdout_lines})\n"
|
156
|
-
if stderr_lines > 0 and stderr_content.strip():
|
157
|
-
result += f"stderr_file: {stderr_file_name} (lines: {stderr_lines})\n"
|
158
|
-
result += f"returncode: {return_code}\n"
|
159
|
-
result += (
|
160
|
-
"--- python_command_run: STDOUT (head/tail) ---\n"
|
161
|
-
+ head_tail(stdout_content)
|
162
|
-
+ "\n"
|
163
|
-
)
|
164
|
-
if stderr_content.strip():
|
165
|
-
result += (
|
166
|
-
"--- python_command_run: STDERR (head/tail) ---\n"
|
167
|
-
+ head_tail(stderr_content)
|
168
|
-
+ "\n"
|
169
|
-
)
|
170
|
-
result += "Use the view_file tool to inspect the contents of these files when needed."
|
171
|
-
return result
|
@@ -1,172 +0,0 @@
|
|
1
|
-
import subprocess
|
2
|
-
import os
|
3
|
-
import sys
|
4
|
-
import tempfile
|
5
|
-
import threading
|
6
|
-
from janito.tools.tool_base import ToolBase, ToolPermissions
|
7
|
-
from janito.report_events import ReportAction
|
8
|
-
from janito.tools.adapters.local.adapter import register_local_tool
|
9
|
-
from janito.i18n import tr
|
10
|
-
|
11
|
-
|
12
|
-
@register_local_tool
|
13
|
-
class PythonFileRunTool(ToolBase):
|
14
|
-
"""
|
15
|
-
Tool to execute a specified Python script file.
|
16
|
-
|
17
|
-
Args:
|
18
|
-
path (str): Path to the Python script file to execute.
|
19
|
-
timeout (int): Timeout in seconds for the command. Defaults to 60.
|
20
|
-
silent (bool): If True, suppresses progress and status messages. Defaults to False.
|
21
|
-
|
22
|
-
Returns:
|
23
|
-
str: Output and status message, or file paths/line counts if output is large.
|
24
|
-
"""
|
25
|
-
|
26
|
-
permissions = ToolPermissions(execute=True)
|
27
|
-
tool_name = "python_file_run"
|
28
|
-
|
29
|
-
def run(self, path: str, timeout: int = 60, silent: bool = False) -> str:
|
30
|
-
from janito.tools.path_utils import expand_path
|
31
|
-
|
32
|
-
path = expand_path(path)
|
33
|
-
if not silent:
|
34
|
-
self.report_action(
|
35
|
-
tr("🚀 Running: python {path}", path=path),
|
36
|
-
ReportAction.EXECUTE,
|
37
|
-
)
|
38
|
-
self.report_stdout("\n")
|
39
|
-
else:
|
40
|
-
self.report_action(tr("⚡ Executing..."), ReportAction.EXECUTE)
|
41
|
-
try:
|
42
|
-
with (
|
43
|
-
tempfile.NamedTemporaryFile(
|
44
|
-
mode="w+",
|
45
|
-
prefix="python_file_stdout_",
|
46
|
-
delete=False,
|
47
|
-
encoding="utf-8",
|
48
|
-
) as stdout_file,
|
49
|
-
tempfile.NamedTemporaryFile(
|
50
|
-
mode="w+",
|
51
|
-
prefix="python_file_stderr_",
|
52
|
-
delete=False,
|
53
|
-
encoding="utf-8",
|
54
|
-
) as stderr_file,
|
55
|
-
):
|
56
|
-
process = subprocess.Popen(
|
57
|
-
[sys.executable, path],
|
58
|
-
stdout=subprocess.PIPE,
|
59
|
-
stderr=subprocess.PIPE,
|
60
|
-
text=True,
|
61
|
-
bufsize=1,
|
62
|
-
universal_newlines=True,
|
63
|
-
encoding="utf-8",
|
64
|
-
env={**os.environ, "PYTHONIOENCODING": "utf-8"},
|
65
|
-
)
|
66
|
-
stdout_lines, stderr_lines = self._stream_process_output(
|
67
|
-
process, stdout_file, stderr_file
|
68
|
-
)
|
69
|
-
return_code = self._wait_for_process(process, timeout)
|
70
|
-
if return_code is None:
|
71
|
-
return tr(
|
72
|
-
"Code timed out after {timeout} seconds.", timeout=timeout
|
73
|
-
)
|
74
|
-
stdout_file.flush()
|
75
|
-
stderr_file.flush()
|
76
|
-
if not silent:
|
77
|
-
self.report_success(
|
78
|
-
tr("✅ Return code {return_code}", return_code=return_code),
|
79
|
-
ReportAction.EXECUTE,
|
80
|
-
)
|
81
|
-
return self._format_result(
|
82
|
-
stdout_file.name, stderr_file.name, return_code
|
83
|
-
)
|
84
|
-
except Exception as e:
|
85
|
-
self.report_error(tr("❌ Error: {error}", error=e), ReportAction.EXECUTE)
|
86
|
-
return tr("Error running file: {error}", error=e)
|
87
|
-
|
88
|
-
def _stream_process_output(self, process, stdout_file, stderr_file):
|
89
|
-
stdout_lines = 0
|
90
|
-
stderr_lines = 0
|
91
|
-
|
92
|
-
def stream_output(stream, file_obj, report_func, count_func):
|
93
|
-
nonlocal stdout_lines, stderr_lines
|
94
|
-
for line in stream:
|
95
|
-
file_obj.write(line)
|
96
|
-
file_obj.flush()
|
97
|
-
# Always supply a default action for stdout/stderr reporting
|
98
|
-
from janito.report_events import ReportAction
|
99
|
-
|
100
|
-
report_func(line.rstrip("\r\n"), ReportAction.EXECUTE)
|
101
|
-
if count_func == "stdout":
|
102
|
-
stdout_lines += 1
|
103
|
-
else:
|
104
|
-
stderr_lines += 1
|
105
|
-
|
106
|
-
stdout_thread = threading.Thread(
|
107
|
-
target=stream_output,
|
108
|
-
args=(process.stdout, stdout_file, self.report_stdout, "stdout"),
|
109
|
-
)
|
110
|
-
stderr_thread = threading.Thread(
|
111
|
-
target=stream_output,
|
112
|
-
args=(process.stderr, stderr_file, self.report_stderr, "stderr"),
|
113
|
-
)
|
114
|
-
stdout_thread.start()
|
115
|
-
stderr_thread.start()
|
116
|
-
stdout_thread.join()
|
117
|
-
stderr_thread.join()
|
118
|
-
return stdout_lines, stderr_lines
|
119
|
-
|
120
|
-
def _wait_for_process(self, process, timeout):
|
121
|
-
try:
|
122
|
-
return process.wait(timeout=timeout)
|
123
|
-
except subprocess.TimeoutExpired:
|
124
|
-
process.kill()
|
125
|
-
self.report_error(
|
126
|
-
tr("❌ Timed out after {timeout} seconds.", timeout=timeout),
|
127
|
-
ReportAction.EXECUTE,
|
128
|
-
)
|
129
|
-
return None
|
130
|
-
|
131
|
-
def _format_result(self, stdout_file_name, stderr_file_name, return_code):
|
132
|
-
with open(stdout_file_name, "r", encoding="utf-8", errors="replace") as out_f:
|
133
|
-
stdout_content = out_f.read()
|
134
|
-
with open(stderr_file_name, "r", encoding="utf-8", errors="replace") as err_f:
|
135
|
-
stderr_content = err_f.read()
|
136
|
-
max_lines = 100
|
137
|
-
stdout_lines = stdout_content.count("\n")
|
138
|
-
stderr_lines = stderr_content.count("\n")
|
139
|
-
|
140
|
-
def head_tail(text, n=10):
|
141
|
-
lines = text.splitlines()
|
142
|
-
if len(lines) <= 2 * n:
|
143
|
-
return "\n".join(lines)
|
144
|
-
return "\n".join(
|
145
|
-
lines[:n]
|
146
|
-
+ ["... ({} lines omitted) ...".format(len(lines) - 2 * n)]
|
147
|
-
+ lines[-n:]
|
148
|
-
)
|
149
|
-
|
150
|
-
if stdout_lines <= max_lines and stderr_lines <= max_lines:
|
151
|
-
result = f"Return code: {return_code}\n--- python_file_run: STDOUT ---\n{stdout_content}"
|
152
|
-
if stderr_content.strip():
|
153
|
-
result += f"\n--- python_file_run: STDERR ---\n{stderr_content}"
|
154
|
-
return result
|
155
|
-
else:
|
156
|
-
result = f"stdout_file: {stdout_file_name} (lines: {stdout_lines})\n"
|
157
|
-
if stderr_lines > 0 and stderr_content.strip():
|
158
|
-
result += f"stderr_file: {stderr_file_name} (lines: {stderr_lines})\n"
|
159
|
-
result += f"returncode: {return_code}\n"
|
160
|
-
result += (
|
161
|
-
"--- python_file_run: STDOUT (head/tail) ---\n"
|
162
|
-
+ head_tail(stdout_content)
|
163
|
-
+ "\n"
|
164
|
-
)
|
165
|
-
if stderr_content.strip():
|
166
|
-
result += (
|
167
|
-
"--- python_file_run: STDERR (head/tail) ---\n"
|
168
|
-
+ head_tail(stderr_content)
|
169
|
-
+ "\n"
|
170
|
-
)
|
171
|
-
result += "Use the view_file tool to inspect the contents of these files when needed."
|
172
|
-
return result
|
@@ -1,23 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Visualization Plugin
|
3
|
-
|
4
|
-
Data visualization and charting tools.
|
5
|
-
"""
|
6
|
-
|
7
|
-
from typing import Dict, Any
|
8
|
-
|
9
|
-
|
10
|
-
def read_chart(
|
11
|
-
data: Dict[str, Any], title: str = "Chart", width: int = 80, height: int = 20
|
12
|
-
) -> str:
|
13
|
-
"""Display charts in terminal (bar, line, pie, table)"""
|
14
|
-
return f"read_chart(type='{data.get('type')}', title='{title}')"
|
15
|
-
|
16
|
-
|
17
|
-
read_chart.tool_name = "read_chart"
|
18
|
-
|
19
|
-
|
20
|
-
# Plugin metadata
|
21
|
-
__plugin_name__ = "dev.visualization"
|
22
|
-
__plugin_description__ = "Data visualization and charts"
|
23
|
-
__plugin_tools__ = [read_chart]
|
@@ -1,259 +0,0 @@
|
|
1
|
-
from janito.tools.tool_base import ToolBase, ToolPermissions
|
2
|
-
from janito.report_events import ReportAction
|
3
|
-
from janito.tools.adapters.local.adapter import register_local_tool
|
4
|
-
from janito.tools.tool_utils import display_path
|
5
|
-
from janito.i18n import tr
|
6
|
-
import json
|
7
|
-
import os
|
8
|
-
from janito.tools.loop_protection_decorator import protect_against_loops
|
9
|
-
|
10
|
-
|
11
|
-
@register_local_tool
|
12
|
-
class ReadChartTool(ToolBase):
|
13
|
-
"""
|
14
|
-
Display charts and data visualizations in the terminal using rich.
|
15
|
-
|
16
|
-
Args:
|
17
|
-
data (dict): Chart data in JSON format. Should contain 'type' (bar, line, pie, table) and 'data' keys.
|
18
|
-
title (str, optional): Chart title. Defaults to "Chart".
|
19
|
-
width (int, optional): Chart width. Defaults to 80.
|
20
|
-
height (int, optional): Chart height. Defaults to 20.
|
21
|
-
|
22
|
-
Returns:
|
23
|
-
str: Formatted chart display in terminal or error message.
|
24
|
-
"""
|
25
|
-
|
26
|
-
permissions = ToolPermissions(read=True)
|
27
|
-
tool_name = "read_chart"
|
28
|
-
|
29
|
-
@protect_against_loops(max_calls=5, time_window=10.0, key_field="data")
|
30
|
-
def run(
|
31
|
-
self, data: dict, title: str = "Chart", width: int = 80, height: int = 20
|
32
|
-
) -> str:
|
33
|
-
try:
|
34
|
-
from rich.console import Console
|
35
|
-
from rich.table import Table
|
36
|
-
from rich.text import Text
|
37
|
-
from rich.layout import Layout
|
38
|
-
from rich.panel import Panel
|
39
|
-
from rich.columns import Columns
|
40
|
-
from rich import box
|
41
|
-
|
42
|
-
console = Console(width=width)
|
43
|
-
|
44
|
-
if not isinstance(data, dict):
|
45
|
-
return "❌ Error: Data must be a dictionary"
|
46
|
-
|
47
|
-
chart_type = data.get("type", "table").lower()
|
48
|
-
chart_data = data.get("data", [])
|
49
|
-
|
50
|
-
if not chart_data:
|
51
|
-
return "⚠️ Warning: No data provided for chart"
|
52
|
-
|
53
|
-
self.report_action(
|
54
|
-
tr(
|
55
|
-
"📊 Displaying {chart_type} chart: {title}",
|
56
|
-
chart_type=chart_type,
|
57
|
-
title=title,
|
58
|
-
),
|
59
|
-
ReportAction.READ,
|
60
|
-
)
|
61
|
-
|
62
|
-
if chart_type == "table":
|
63
|
-
return self._display_table(console, chart_data, title, width)
|
64
|
-
elif chart_type == "bar":
|
65
|
-
return self._display_bar(console, chart_data, title, width, height)
|
66
|
-
elif chart_type == "line":
|
67
|
-
return self._display_line(console, chart_data, title, width, height)
|
68
|
-
elif chart_type == "pie":
|
69
|
-
return self._display_pie(console, chart_data, title, width)
|
70
|
-
else:
|
71
|
-
return f"❌ Error: Unsupported chart type '{chart_type}'. Use: table, bar, line, pie"
|
72
|
-
|
73
|
-
except ImportError:
|
74
|
-
return "❌ Error: rich library not available for chart display"
|
75
|
-
except Exception as e:
|
76
|
-
return f"❌ Error displaying chart: {e}"
|
77
|
-
|
78
|
-
def _display_table(self, console, data, title, width):
|
79
|
-
"""Display data as a rich table."""
|
80
|
-
from rich.table import Table
|
81
|
-
|
82
|
-
if not data:
|
83
|
-
return "No data to display"
|
84
|
-
|
85
|
-
table = Table(title=title, show_header=True, header_style="bold magenta")
|
86
|
-
|
87
|
-
# Handle different data formats
|
88
|
-
if isinstance(data, dict):
|
89
|
-
# Dictionary format: key-value pairs
|
90
|
-
table.add_column("Key", style="cyan")
|
91
|
-
table.add_column("Value", style="green")
|
92
|
-
for key, value in data.items():
|
93
|
-
table.add_row(str(key), str(value))
|
94
|
-
elif isinstance(data, list):
|
95
|
-
if data and isinstance(data[0], dict):
|
96
|
-
# List of dictionaries (records)
|
97
|
-
headers = list(data[0].keys()) if data else []
|
98
|
-
for header in headers:
|
99
|
-
table.add_column(str(header).title(), style="cyan")
|
100
|
-
for row in data:
|
101
|
-
table.add_row(*[str(row.get(h, "")) for h in headers])
|
102
|
-
else:
|
103
|
-
# Simple list
|
104
|
-
table.add_column("Items", style="cyan")
|
105
|
-
for item in data:
|
106
|
-
table.add_row(str(item))
|
107
|
-
|
108
|
-
console.print(table)
|
109
|
-
return f"✅ Table chart displayed: {title}"
|
110
|
-
|
111
|
-
def _display_bar(self, console, data, title, width, height):
|
112
|
-
"""Display data as a simple bar chart using unicode blocks."""
|
113
|
-
try:
|
114
|
-
if isinstance(data, dict):
|
115
|
-
items = list(data.items())
|
116
|
-
elif isinstance(data, list) and data and isinstance(data[0], dict):
|
117
|
-
# Assume first two keys are labels and values
|
118
|
-
keys = list(data[0].keys())
|
119
|
-
if len(keys) >= 2:
|
120
|
-
label_key, value_key = keys[0], keys[1]
|
121
|
-
items = [(item[label_key], item[value_key]) for item in data]
|
122
|
-
else:
|
123
|
-
items = [(str(i), v) for i, v in enumerate(data)]
|
124
|
-
else:
|
125
|
-
items = [(str(i), v) for i, v in enumerate(data)]
|
126
|
-
|
127
|
-
if not items:
|
128
|
-
return "No data to display"
|
129
|
-
|
130
|
-
# Convert values to numbers
|
131
|
-
numeric_items = []
|
132
|
-
for label, value in items:
|
133
|
-
try:
|
134
|
-
numeric_items.append((str(label), float(value)))
|
135
|
-
except (ValueError, TypeError):
|
136
|
-
numeric_items.append((str(label), 0.0))
|
137
|
-
|
138
|
-
if not numeric_items:
|
139
|
-
return "No valid numeric data to display"
|
140
|
-
|
141
|
-
max_val = max(val for _, val in numeric_items) if numeric_items else 1
|
142
|
-
|
143
|
-
console.print(f"\n[bold]{title}[/bold]")
|
144
|
-
console.print("=" * min(len(title), width))
|
145
|
-
|
146
|
-
for label, value in numeric_items:
|
147
|
-
bar_length = int((value / max_val) * (width - 20)) if max_val > 0 else 0
|
148
|
-
bar = "█" * bar_length
|
149
|
-
console.print(f"{label:<15} {bar} {value:.1f}")
|
150
|
-
|
151
|
-
return f"✅ Bar chart displayed: {title}"
|
152
|
-
|
153
|
-
except Exception as e:
|
154
|
-
return f"❌ Error displaying bar chart: {e}"
|
155
|
-
|
156
|
-
def _display_line(self, console, data, title, width, height):
|
157
|
-
"""Display data as a simple line chart using unicode characters."""
|
158
|
-
try:
|
159
|
-
if isinstance(data, dict):
|
160
|
-
items = list(data.items())
|
161
|
-
elif isinstance(data, list):
|
162
|
-
if data and isinstance(data[0], dict):
|
163
|
-
keys = list(data[0].keys())
|
164
|
-
if len(keys) >= 2:
|
165
|
-
label_key, value_key = keys[0], keys[1]
|
166
|
-
items = [(item[label_key], item[value_key]) for item in data]
|
167
|
-
else:
|
168
|
-
items = [(str(i), v) for i, v in enumerate(data)]
|
169
|
-
else:
|
170
|
-
items = [(str(i), v) for i, v in enumerate(data)]
|
171
|
-
else:
|
172
|
-
return "Unsupported data format"
|
173
|
-
|
174
|
-
# Convert to numeric values
|
175
|
-
points = []
|
176
|
-
for x, y in items:
|
177
|
-
try:
|
178
|
-
points.append((float(x), float(y)))
|
179
|
-
except (ValueError, TypeError):
|
180
|
-
continue
|
181
|
-
|
182
|
-
if len(points) < 2:
|
183
|
-
return "Need at least 2 data points for line chart"
|
184
|
-
|
185
|
-
points.sort(key=lambda p: p[0])
|
186
|
-
|
187
|
-
# Simple ASCII line chart
|
188
|
-
min_x, max_x = min(p[0] for p in points), max(p[0] for p in points)
|
189
|
-
min_y, max_y = min(p[1] for p in points), max(p[1] for p in points)
|
190
|
-
|
191
|
-
if max_x == min_x or max_y == min_y:
|
192
|
-
return "Cannot display line chart: all values are the same"
|
193
|
-
|
194
|
-
console.print(f"\n[bold]{title}[/bold]")
|
195
|
-
console.print("=" * min(len(title), width))
|
196
|
-
|
197
|
-
# Simple representation
|
198
|
-
for x, y in points:
|
199
|
-
x_norm = int(((x - min_x) / (max_x - min_x)) * (width - 20))
|
200
|
-
y_norm = int(((y - min_y) / (max_y - min_y)) * 10)
|
201
|
-
line = " " * x_norm + "●" + " " * (width - 20 - x_norm)
|
202
|
-
console.print(f"{x:>8.1f}: {line} {y:.1f}")
|
203
|
-
|
204
|
-
return f"✅ Line chart displayed: {title}"
|
205
|
-
|
206
|
-
except Exception as e:
|
207
|
-
return f"❌ Error displaying line chart: {e}"
|
208
|
-
|
209
|
-
def _display_pie(self, console, data, title, width):
|
210
|
-
"""Display data as a simple pie chart representation."""
|
211
|
-
try:
|
212
|
-
if isinstance(data, dict):
|
213
|
-
items = list(data.items())
|
214
|
-
elif isinstance(data, list) and data and isinstance(data[0], dict):
|
215
|
-
keys = list(data[0].keys())
|
216
|
-
if len(keys) >= 2:
|
217
|
-
label_key, value_key = keys[0], keys[1]
|
218
|
-
items = [(item[label_key], item[value_key]) for item in data]
|
219
|
-
else:
|
220
|
-
items = [(str(i), v) for i, v in enumerate(data)]
|
221
|
-
else:
|
222
|
-
items = [(str(i), v) for i, v in enumerate(data)]
|
223
|
-
|
224
|
-
# Convert to numeric values
|
225
|
-
values = []
|
226
|
-
for label, value in items:
|
227
|
-
try:
|
228
|
-
values.append((str(label), float(value)))
|
229
|
-
except (ValueError, TypeError):
|
230
|
-
continue
|
231
|
-
|
232
|
-
if not values:
|
233
|
-
return "No valid numeric data to display"
|
234
|
-
|
235
|
-
total = sum(val for _, val in values)
|
236
|
-
if total == 0:
|
237
|
-
return "Cannot display pie chart: total is zero"
|
238
|
-
|
239
|
-
console.print(f"\n[bold]{title}[/bold]")
|
240
|
-
console.print("=" * min(len(title), width))
|
241
|
-
|
242
|
-
# Unicode pie chart segments
|
243
|
-
segments = ["🟦", "🟥", "🟩", "🟨", "🟪", "🟧", "⬛", "⬜"]
|
244
|
-
|
245
|
-
for i, (label, value) in enumerate(values):
|
246
|
-
percentage = (value / total) * 100
|
247
|
-
segment = segments[i % len(segments)]
|
248
|
-
bar_length = int((value / total) * (width - 30))
|
249
|
-
bar = "█" * bar_length
|
250
|
-
console.print(
|
251
|
-
f"{segment} {label:<15} {bar} {percentage:5.1f}% ({value})"
|
252
|
-
)
|
253
|
-
|
254
|
-
console.print(f"\n[dim]Total: {total}[/dim]")
|
255
|
-
|
256
|
-
return f"✅ Pie chart displayed: {title}"
|
257
|
-
|
258
|
-
except Exception as e:
|
259
|
-
return f"❌ Error displaying pie chart: {e}"
|