Skip to content

Commit 83262d8

Browse files
committed
Amélioration des logs pip et correction de la boucle d'événements Qt en mode CLI
1 parent 6f8e21e commit 83262d8

3 files changed

Lines changed: 87 additions & 6 deletions

File tree

Core/Compiler/engine_runner.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ def run_engine_compile(
160160
context: BuildContext,
161161
engine_config: dict[str, Any] | None = None,
162162
gui: Any = None,
163+
verbose: bool = False,
163164
) -> dict[str, Any]:
164165
"""
165166
Execute a compilation synchronously.
@@ -175,6 +176,7 @@ def run_engine_compile(
175176
engine_config: Optional per-engine config overrides (forwarded to
176177
``engine._config_overrides``).
177178
gui: Optional GUI object.
179+
verbose: Whether to enable verbose logging.
178180
179181
Returns:
180182
A result dict with success status, return code, command, stdout, stderr, and error message.
@@ -196,6 +198,7 @@ def _on_stderr(line: str):
196198
on_stdout=_on_stdout,
197199
on_stderr=_on_stderr,
198200
gui=gui,
201+
verbose=verbose,
199202
)
200203

201204
result["stdout"] = "\n".join(captured_stdout)
@@ -217,6 +220,7 @@ def run_engine_compile_streaming(
217220
on_stderr: Optional[Callable[[str], None]] = None,
218221
stop_signal: Optional[Callable[[], bool]] = None,
219222
gui: Any = None,
223+
verbose: bool = False,
220224
) -> dict[str, Any]:
221225
"""
222226
Execute a compilation with real-time output streaming.
@@ -230,6 +234,7 @@ def run_engine_compile_streaming(
230234
on_stderr: Callback for each line of stderr.
231235
stop_signal: Optional callback that returns True if cancellation is requested.
232236
gui: Optional GUI object to use instead of creating a bridge.
237+
verbose: Whether to enable verbose logging.
233238
234239
Returns:
235240
A result dict.
@@ -258,11 +263,15 @@ def _log(fr, en):
258263
if gui:
259264
bridge = gui
260265
else:
266+
from PySide6.QtCore import QObject
267+
261268
# We pass a dummy 'gui' object that supports log_i18n_level-like logging
262-
class LogBridge:
263-
def __init__(self, log_cb, workspace_path: Path):
269+
class LogBridge(QObject):
270+
def __init__(self, log_cb, workspace_path: Path, verbose: bool = False):
271+
super().__init__()
264272
self.log_cb = log_cb
265273
self.workspace_dir = str(workspace_path)
274+
self.verbose = verbose
266275
self.log = self # So gui.log.append works
267276
self.use_system_python = False # Default for CLI
268277
self.venv_path_manuel = None
@@ -273,6 +282,11 @@ def append(self, message: str):
273282
# message is already formatted by log_i18n_level
274283
self.log_cb("", message)
275284

285+
def _safe_log(self, text, text_en=None, level=None):
286+
# Fallback for VenvManager
287+
msg = text_en if text_en else text
288+
self.log_cb("", msg)
289+
276290
def tr(self, fr, en):
277291
return en # Simple fallback
278292

@@ -298,7 +312,7 @@ def sys_deps_manager(self):
298312
self._sys_deps_manager = SysDependencyManager(self)
299313
return self._sys_deps_manager
300314

301-
bridge = LogBridge(_log, workspace)
315+
bridge = LogBridge(_log, workspace, verbose=verbose)
302316

303317
# Link bridge to engine for venv/tool resolution in build_command
304318
try:

Core/Venv_Manager/Manager.py

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,24 @@ def ensure_tools_installed(self, venv_root: str, tools: list[str]) -> None:
484484
f"Verification de {tools[0]}...",
485485
)
486486
self._call_ui("update_progress_progress", "tools_check", 0, len(tools))
487+
488+
# In CLI mode without a global event loop, we might need a local one
489+
is_cli = getattr(self.parent, "verbose", False) or os.environ.get("PYCOMPILER_CLI") == "1"
490+
loop = None
491+
if is_cli:
492+
from PySide6.QtCore import QCoreApplication, QEventLoop
493+
if not QCoreApplication.instance():
494+
self._app_ref = QCoreApplication([]) # Keep alive
495+
496+
loop = QEventLoop()
497+
# We need a way to stop the loop when all tools are checked
498+
self._venv_check_loop = loop
499+
487500
self._check_next_venv_pkg()
501+
502+
if loop:
503+
loop.exec()
504+
self._venv_check_loop = None
488505
except Exception as e:
489506
self._safe_log(
490507
f"[ERROR] {self._tools_stage_prefix()}Erreur ensure_tools_installed: {e}"
@@ -530,7 +547,23 @@ def ensure_tools_installed_system(self, tools: list[str]) -> None:
530547
f"Verification de {tools[0]}...",
531548
)
532549
self._call_ui("update_progress_progress", "tools_check", 0, len(tools))
550+
551+
# In CLI mode without a global event loop, we might need a local one
552+
is_cli = getattr(self.parent, "verbose", False) or os.environ.get("PYCOMPILER_CLI") == "1"
553+
loop = None
554+
if is_cli:
555+
from PySide6.QtCore import QCoreApplication, QEventLoop
556+
if not QCoreApplication.instance():
557+
self._app_ref = QCoreApplication([]) # Keep alive
558+
559+
loop = QEventLoop()
560+
self._venv_check_loop = loop
561+
533562
self._check_next_venv_pkg()
563+
564+
if loop:
565+
loop.exec()
566+
self._venv_check_loop = None
534567
except Exception as e:
535568
self._safe_log(
536569
f"[ERROR] {self._tools_stage_prefix()}Erreur ensure_tools_installed_system: {e}"
@@ -918,6 +951,10 @@ def _check_next_venv_pkg(self):
918951
"""Execute _check_next_venv_pkg logic for this component."""
919952
if self._is_cancel_requested():
920953
self._call_ui("close_progress", "tools_check")
954+
# Exit local loop if any
955+
loop = getattr(self, "_venv_check_loop", None)
956+
if loop:
957+
loop.quit()
921958
return
922959
if self._venv_check_index >= len(self._venv_check_pkgs):
923960
self._call_ui(
@@ -931,6 +968,11 @@ def _check_next_venv_pkg(self):
931968
self._call_ui("update_progress_progress", "tools_check", total, total)
932969
self._call_ui("close_progress", "tools_check")
933970

971+
# Exit local loop if any
972+
loop = getattr(self, "_venv_check_loop", None)
973+
if loop:
974+
loop.quit()
975+
934976
# Installer les dependances du projet si un requirements.txt est present
935977
try:
936978
if getattr(self.parent, "workspace_dir", None):
@@ -996,6 +1038,11 @@ def _on_venv_pkg_checked(self, process, code, status, pkg):
9961038
level="error",
9971039
)
9981040
self._call_ui("close_progress", "tools_check")
1041+
1042+
# Exit local loop if any
1043+
loop = getattr(self, "_venv_check_loop", None)
1044+
if loop:
1045+
loop.quit()
9991046
return
10001047

10011048
self._safe_log(
@@ -1048,7 +1095,14 @@ def _on_venv_check_output(self, process, error=False):
10481095
lines = data.strip().splitlines()
10491096
if lines:
10501097
self._call_ui("update_progress_message", "tools_check", lines[-1][:200])
1051-
self._safe_log(data)
1098+
1099+
# Detailed logging for verbose mode or errors
1100+
is_verbose = getattr(self.parent, "verbose", False)
1101+
if is_verbose or error:
1102+
for line in lines:
1103+
lvl = "warning" if error else "info"
1104+
# We use a slight indentation to make it clear it's sub-output
1105+
self._safe_log(f" [pip] {line}", level=lvl)
10521106

10531107
def verify_venv_binding(self, venv_root: str) -> bool:
10541108
"""Keep synchronous verification path for internal compatibility."""
@@ -1479,7 +1533,13 @@ def _on_venv_output(self, process, error=False):
14791533
self._venv_progress_lines,
14801534
0,
14811535
)
1482-
self._safe_log(data)
1536+
1537+
# Detailed logging for verbose mode or errors
1538+
is_verbose = getattr(self.parent, "verbose", False)
1539+
if is_verbose or error:
1540+
for line in lines:
1541+
lvl = "warning" if error else "info"
1542+
self._safe_log(f" [venv] {line}", level=lvl)
14831543

14841544
def _on_venv_created(self, process, code, status, venv_path):
14851545
"""Handle the related event callback."""
@@ -1735,7 +1795,13 @@ def _on_pip_output(self, process, error=False):
17351795
self._call_ui(
17361796
"update_progress_progress", "reqs_install", self._pip_progress_lines, 0
17371797
)
1738-
self._safe_log(data)
1798+
1799+
# Detailed logging for verbose mode or errors
1800+
is_verbose = getattr(self.parent, "verbose", False)
1801+
if is_verbose or error:
1802+
for line in lines:
1803+
lvl = "warning" if error else "info"
1804+
self._safe_log(f" [pip] {line}", level=lvl)
17391805

17401806
def _on_pip_finished(self, process, code, status):
17411807
"""Handle the related event callback."""

Ui/Cli/helpers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def _on_stderr(line: str):
115115
on_stdout=_on_stdout,
116116
on_stderr=_on_stderr,
117117
stop_signal=lambda: _CLI_CANCEL_EVENT.is_set(),
118+
verbose=verbose,
118119
)
119120
except Exception as exc:
120121
result = {

0 commit comments

Comments
 (0)