Skip to content

Commit 3534f83

Browse files
committed
Optimisations de performance et correction du bug de validation BCASL
1 parent 20f5984 commit 3534f83

3 files changed

Lines changed: 107 additions & 60 deletions

File tree

Ui/Gui/Compilation/helpers.py

Lines changed: 79 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -52,97 +52,127 @@ def resolve_default_engine_id() -> str:
5252

5353

5454
def run_bcasl_before_compile(
55-
gui_instance, on_done, build_context: Optional[Any] = None
55+
gui_instance, on_done, build_context: Optional[Any] = None, ark_config: Optional[dict] = None
5656
) -> None:
57-
"""Run BCASL pre-compile stage, then invoke `on_done(report)`."""
57+
"""
58+
Run BCASL pre-compile stage, then invoke `on_done(report)`.
59+
Optimized: Checks activation state before launching the async thread.
60+
"""
5861
try:
62+
from bcasl.Loader import BCASL_DISABLED_REPORT, _is_bcasl_enabled
5963
from Ui.Gui.Dialogs.BcaslDialog import run_pre_compile_async
64+
from pathlib import Path
6065
except Exception:
6166
if callable(on_done):
62-
try:
63-
on_done(None)
64-
except Exception:
65-
pass
67+
on_done(None)
68+
return
69+
70+
ws = getattr(gui_instance, "workspace_dir", None)
71+
if not ws:
72+
if callable(on_done):
73+
on_done(None)
6674
return
75+
76+
# Optimization: Short-circuit if BCASL is disabled to avoid thread overhead
77+
enabled = True
78+
try:
79+
if ark_config:
80+
enabled = bool(ark_config.get("plugins", {}).get("bcasl_enabled", True))
81+
else:
82+
enabled = _is_bcasl_enabled(Path(ws))
83+
except Exception:
84+
pass
85+
86+
if not enabled:
87+
try:
88+
log_i18n_level(
89+
gui_instance,
90+
"info",
91+
"BCASL désactivé dans ark.yml. Exécution ignorée.",
92+
"BCASL disabled in ark.yml. Skipping execution.",
93+
)
94+
except Exception:
95+
pass
96+
if callable(on_done):
97+
on_done(dict(BCASL_DISABLED_REPORT))
98+
return
99+
67100
try:
68101
log_i18n_level(
69102
gui_instance,
70103
"info",
71-
"Pré-compilation (BCASL) si activée...",
72-
"Pre-compilation (BCASL) if enabled...",
104+
"Pré-compilation (BCASL)...",
105+
"Pre-compilation (BCASL)...",
73106
)
74107
except Exception:
75108
pass
109+
76110
try:
77111
run_pre_compile_async(gui_instance, on_done, build_context=build_context)
78112
except Exception:
79113
if callable(on_done):
80-
try:
81-
on_done(None)
82-
except Exception:
83-
pass
114+
on_done(None)
84115

85116

86117
def bcasl_report_allows_compile(gui_instance, report) -> bool:
87-
"""Return True when BCASL pre-compile report allows compilation to continue."""
118+
"""
119+
Return True when BCASL pre-compile report allows compilation to continue.
120+
Robustly handles dicts, objects, and lists.
121+
"""
88122
try:
89123
if report is None:
124+
# Fallback check if the thread returned nothing
90125
try:
91126
from pathlib import Path
92-
93127
from bcasl.Loader import _is_bcasl_enabled
94-
95128
ws = getattr(gui_instance, "workspace_dir", None)
96129
if ws and not _is_bcasl_enabled(Path(ws).resolve()):
97130
return True
98131
except Exception:
99132
pass
100-
log_i18n_level(
101-
gui_instance,
102-
"error",
103-
"BCASL a échoué ou n'a pas retourné de rapport. Compilation bloquée.",
104-
"BCASL failed or returned no report. Compilation blocked.",
105-
)
106133
return False
107134

135+
# 1. Handle Disabled Report (Dict)
108136
if isinstance(report, dict):
109137
try:
110138
from bcasl.Loader import is_bcasl_disabled_report
111-
112139
if is_bcasl_disabled_report(report):
113140
return True
114141
except Exception:
115-
status = str(report.get("status", "")).strip().lower()
116-
if status in {"disabled", "skipped"}:
117-
return True
142+
pass
143+
144+
# Simple check for 'ok' key
118145
if "ok" in report:
119-
ok = any(report.get("ok"))
120-
if not ok:
121-
log_i18n_level(
122-
gui_instance,
123-
"error",
124-
"BCASL a signalé un échec. Compilation bloquée.",
125-
"BCASL reported a failure. Compilation blocked.",
126-
)
127-
return ok
146+
res = report.get("ok")
147+
return bool(res) if not isinstance(res, (list, tuple, set)) else all(res)
128148
return True
129149

150+
# 2. Handle ExecutionReport object
130151
if hasattr(report, "ok"):
131-
ok = any(getattr(report, "ok"))
132-
if not ok:
133-
log_i18n_level(
134-
gui_instance,
135-
"error",
136-
"BCASL a signalé des erreurs plugins. Compilation bloquée.",
137-
"BCASL reported plugin errors. Compilation blocked.",
138-
)
139-
return ok
152+
ok_val = getattr(report, "ok")
153+
# If it's a property returning bool, use it directly
154+
if isinstance(ok_val, bool):
155+
return ok_val
156+
# If it's a list (legacy/compat), check all
157+
try:
158+
return all(ok_val)
159+
except Exception:
160+
return bool(ok_val)
161+
162+
# 3. Handle List of Results
163+
if isinstance(report, (list, tuple)):
164+
return all(getattr(item, "success", True) for item in report)
165+
140166
except Exception:
141-
log_i18n_level(
142-
gui_instance,
143-
"error",
144-
"Erreur lors de la validation du rapport BCASL. Compilation bloquée.",
145-
"Error while validating BCASL report. Compilation blocked.",
146-
)
167+
try:
168+
log_i18n_level(
169+
gui_instance,
170+
"error",
171+
"Erreur lors de la validation du rapport BCASL. Compilation bloquée.",
172+
"Error while validating BCASL report. Compilation blocked.",
173+
)
174+
except Exception:
175+
pass
147176
return False
177+
148178
return True

Ui/Gui/Dialogs/CompilerDialog.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,9 @@ def _after_bcasl(_report=None) -> None:
432432
)
433433

434434
self._active_bcasl_callback = _after_bcasl
435-
run_bcasl_before_compile(self, _after_bcasl, build_context=context)
435+
# Pass validated config to short-circuit if BCASL is disabled
436+
ark_cfg = getattr(validated, "config", None) if 'validated' in locals() else None
437+
run_bcasl_before_compile(self, _after_bcasl, build_context=context, ark_config=ark_cfg)
436438

437439

438440
def rebuild_from_lock(self, lock_path: Path) -> None:
@@ -837,7 +839,9 @@ def _after_bcasl(_report=None) -> None:
837839
)
838840

839841
self._active_bcasl_callback = _after_bcasl
840-
run_bcasl_before_compile(self, _after_bcasl, build_context=context)
842+
# Pass validated config to short-circuit if BCASL is disabled
843+
ark_cfg = getattr(validated, "config", None) if 'validated' in locals() else None
844+
run_bcasl_before_compile(self, _after_bcasl, build_context=context, ark_config=ark_cfg)
841845
return True
842846

843847

Ui/Gui/Dialogs/WorkspaceDialog.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,32 +222,45 @@ def apply_workspace_selection(
222222
if isinstance(workspace_cfg, dict):
223223
exclusion_patterns = workspace_cfg.get("exclude", [])
224224

225-
# Suppression de la rétro-compatibilité avec exclusion_patterns racine
226-
# exclusion_patterns = ark_config.get("exclusion_patterns", [])
227-
228225
added_count = 0
229226
excluded_count = 0
227+
228+
# Optimization: collect items and add them in batches to avoid UI overhead
229+
to_add_relative = []
230+
to_add_absolute = []
230231

231232
import time
232-
233233
last_pump = time.monotonic()
234234

235235
for full_path in files:
236236
if should_exclude_file(full_path, folder, exclusion_patterns):
237237
excluded_count += 1
238238
continue
239239

240-
gui_instance.python_files.append(full_path)
241-
if hasattr(gui_instance, "file_list"):
242-
relative_path = os.path.relpath(full_path, folder)
243-
gui_instance.file_list.addItem(relative_path)
240+
to_add_absolute.append(full_path)
241+
relative_path = os.path.relpath(full_path, folder)
242+
to_add_relative.append(relative_path)
244243

245244
added_count += 1
246-
if added_count % 200 == 0:
245+
246+
# Periodically process events to keep UI responsive during heavy filtering
247+
if added_count % 500 == 0:
247248
if time.monotonic() - last_pump > 0.05:
248249
QApplication.processEvents()
249250
last_pump = time.monotonic()
250251

252+
# Apply to GUI state
253+
gui_instance.python_files.extend(to_add_absolute)
254+
255+
# Batch update the UI list widget
256+
if hasattr(gui_instance, "file_list"):
257+
# Disabling updates during batch addition for performance
258+
gui_instance.file_list.setUpdatesEnabled(False)
259+
try:
260+
gui_instance.file_list.addItems(to_add_relative)
261+
finally:
262+
gui_instance.file_list.setUpdatesEnabled(True)
263+
251264
if excluded_count > 0:
252265
gui_instance.log_i18n(
253266
f"⏩ Exclusion appliquée : {excluded_count} fichier(s) exclu(s) selon ark.yml",

0 commit comments

Comments
 (0)