Skip to content

Commit 08d4585

Browse files
committed
Refactor ensure_tools_installed method in CompilerEngine class
1 parent a5a11e4 commit 08d4585

1 file changed

Lines changed: 18 additions & 21 deletions

File tree

Core/engines_loader/base.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ def required_tools(self) -> dict[str, list[str]]:
9898

9999
def ensure_tools_installed(self, gui) -> bool:
100100
"""
101-
Ensure all required tools are installed.
102-
Returns True if all tools are ready, False if installation failed or was cancelled.
103-
Handles both Python (pip) and system packages.
101+
Check if all required tools are installed.
102+
Returns True if all tools are available, False if any tool is missing.
103+
This is a synchronous check - actual installation should be handled asynchronously by the UI.
104104
"""
105105
try:
106106
tools = self.required_tools
@@ -109,36 +109,33 @@ def ensure_tools_installed(self, gui) -> bool:
109109

110110
# Check if VenvManager is available
111111
if hasattr(gui, 'venv_manager') and gui.venv_manager:
112-
venv_root = gui.venv_manager.resolve_project_venv()
113-
if venv_root:
114-
# Install Python tools via VenvManager
112+
venv_path = gui.venv_manager.resolve_project_venv()
113+
if venv_path:
114+
# Check Python tools in venv
115115
if python_tools:
116-
try:
117-
gui.venv_manager.ensure_tools_installed(venv_root, python_tools)
118-
# Wait for completion (simplified - in practice would need async handling)
119-
except Exception as e:
120-
if hasattr(gui, 'log') and gui.log:
121-
gui.log.append(f"⚠️ Failed to install Python tools {python_tools}: {e}")
122-
return False
123-
124-
# Install system tools
116+
for tool in python_tools:
117+
if not gui.venv_manager.is_tool_installed(venv_path, tool):
118+
if hasattr(gui, 'log') and gui.log:
119+
gui.log.append(f"⚠️ Python tool '{tool}' not found in venv")
120+
return False
121+
122+
# Check system tools
125123
if system_tools:
126124
try:
127-
from Core.sys_deps import install_system_packages
128-
success = install_system_packages(system_tools, gui)
129-
if not success:
125+
from Core.sys_deps import check_system_packages
126+
if not check_system_packages(system_tools):
130127
if hasattr(gui, 'log') and gui.log:
131-
gui.log.append(f"⚠️ Failed to install system tools {system_tools}")
128+
gui.log.append(f"⚠️ System tools {system_tools} not available")
132129
return False
133130
except Exception as e:
134131
if hasattr(gui, 'log') and gui.log:
135-
gui.log.append(f"⚠️ Failed to install system tools {system_tools}: {e}")
132+
gui.log.append(f"⚠️ Error checking system tools {system_tools}: {e}")
136133
return False
137134

138135
return True
139136
except Exception as e:
140137
if hasattr(gui, 'log') and gui.log:
141-
gui.log.append(f"⚠️ Error ensuring tools installed: {e}")
138+
gui.log.append(f"⚠️ Error checking tools: {e}")
142139
return False
143140

144141
def apply_i18n(self, gui, tr: dict) -> None:

0 commit comments

Comments
 (0)