Skip to content

Commit 4677822

Browse files
committed
Refonte de l'orchestration de compilation GUI et corrections de bugs critiques
1 parent f418ab1 commit 4677822

5 files changed

Lines changed: 83 additions & 58 deletions

File tree

Ui/Gui/Compilation/compiler.py

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from __future__ import annotations
2424

2525
import os
26+
import re
2627
from datetime import datetime
2728
from enum import Enum
2829
from pathlib import Path
@@ -43,6 +44,14 @@ class CompilationStatus(Enum):
4344
FAILED = "failed"
4445

4546

47+
# Pre-compiled regex patterns for progress detection
48+
PROGRESS_PATTERNS = [
49+
re.compile(r"\[(\d+)%\]"),
50+
re.compile(r"Progress:\s*(\d+)"),
51+
re.compile(r"(\d+)/(\d+)"),
52+
]
53+
54+
4655
class CompilationThread(QThread):
4756
"""
4857
Thread used to run compilation without blocking the UI.
@@ -60,7 +69,7 @@ def __init__(
6069
engine_id: str,
6170
context: BuildContext,
6271
engine_config: Optional[Dict[str, Any]] = None,
63-
is_rebuild: any = False,
72+
is_rebuild: bool = False,
6473
):
6574
"""
6675
Initialize the compilation thread.
@@ -114,27 +123,25 @@ def _stop_signal():
114123

115124
def _update_progress(self, line: str) -> None:
116125
"""Update progress based on process output."""
117-
# Détecter les patterns de progression courants
118-
progress_patterns = [
119-
r"\[(\d+)%\]",
120-
r"Progress:\s*(\d+)",
121-
r"(\d+)/(\d+)",
122-
]
123-
124-
import re
125-
126-
for pattern in progress_patterns:
127-
match = re.search(pattern, line)
126+
for pattern in PROGRESS_PATTERNS:
127+
match = pattern.search(line)
128128
if match:
129-
if len(match.groups()) == 1:
130-
progress = int(match.group(1))
131-
self.progress_update.emit(progress, line)
132-
elif len(match.groups()) == 2:
133-
current = int(match.group(1))
134-
total = int(match.group(2))
135-
if total > 0:
136-
progress = int((current / total) * 100)
129+
groups = match.groups()
130+
if len(groups) == 1:
131+
try:
132+
progress = int(groups[0])
137133
self.progress_update.emit(progress, line)
134+
except (ValueError, TypeError):
135+
pass
136+
elif len(groups) == 2:
137+
try:
138+
current = int(groups[0])
139+
total = int(groups[1])
140+
if total > 0:
141+
progress = int((current / total) * 100)
142+
self.progress_update.emit(progress, line)
143+
except (ValueError, TypeError):
144+
pass
138145
break
139146

140147
def cancel(self) -> None:
@@ -180,7 +187,7 @@ def status(self) -> CompilationStatus:
180187
return self._status
181188

182189
@property
183-
def is_running(self) -> any:
190+
def is_running(self) -> bool:
184191
"""Return True when a compilation is currently running."""
185192
return self._status == CompilationStatus.RUNNING
186193

@@ -200,7 +207,7 @@ def compile(
200207
engine_id: Optional[str] = None,
201208
file_path: Optional[str] = None,
202209
workspace_dir: Optional[str] = None,
203-
) -> any:
210+
) -> bool:
204211
"""
205212
Legacy compile method. Use compile_from_context instead.
206213
"""
@@ -226,8 +233,8 @@ def compile_from_context(
226233
engine_id: str,
227234
context: BuildContext,
228235
engine_config: Optional[Dict[str, Any]] = None,
229-
is_rebuild: any = False,
230-
) -> any:
236+
is_rebuild: bool = False,
237+
) -> bool:
231238
"""
232239
Start an async compilation from a BuildContext.
233240
"""
@@ -272,7 +279,7 @@ def compile_from_context(
272279

273280
return True
274281

275-
def cancel(self) -> any:
282+
def cancel(self) -> bool:
276283
"""
277284
Cancel current compilation.
278285
"""

Ui/Gui/Compilation/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def run_bcasl_before_compile(
8383
pass
8484

8585

86-
def bcasl_report_allows_compile(gui_instance, report) -> any:
86+
def bcasl_report_allows_compile(gui_instance, report) -> bool:
8787
"""Return True when BCASL pre-compile report allows compilation to continue."""
8888
try:
8989
if report is None:

Ui/Gui/Compilation/mainprocess.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,21 @@ def current_engine(self) -> Optional[str]:
140140
return self._current_engine
141141

142142
@property
143-
def is_ready(self) -> any:
143+
def is_ready(self) -> bool:
144144
"""Return True when the process is ready."""
145145
return self._state in (ProcessState.READY, ProcessState.IDLE)
146146

147147
@property
148-
def is_compiling(self) -> any:
148+
def is_compiling(self) -> bool:
149149
"""Return True when a compilation is currently running."""
150150
return self._state == ProcessState.COMPILING
151151

152152
@property
153-
def is_idle(self) -> any:
153+
def is_idle(self) -> bool:
154154
"""Return True when the process is idle."""
155155
return self._state == ProcessState.IDLE
156156

157-
def set_workspace(self, workspace_dir: str) -> any:
157+
def set_workspace(self, workspace_dir: str) -> bool:
158158
"""
159159
Set workspace directory.
160160
@@ -180,7 +180,7 @@ def set_workspace(self, workspace_dir: str) -> any:
180180

181181
return True
182182

183-
def set_file(self, file_path: str) -> any:
183+
def set_file(self, file_path: str) -> bool:
184184
"""
185185
Set file to compile.
186186
@@ -218,7 +218,7 @@ def compile(
218218
engine_id: Optional[str] = None,
219219
file_path: Optional[str] = None,
220220
workspace_dir: Optional[str] = None,
221-
) -> any:
221+
) -> bool:
222222
"""
223223
Start a compilation.
224224
@@ -296,7 +296,7 @@ def compile(
296296

297297
return success
298298

299-
def cancel(self) -> any:
299+
def cancel(self) -> bool:
300300
"""
301301
Cancel current compilation.
302302
@@ -385,8 +385,8 @@ def compile_from_context(
385385
engine_id: str,
386386
context: BuildContext,
387387
engine_config: Optional[Dict[str, Any]] = None,
388-
is_rebuild: any = False,
389-
) -> any:
388+
is_rebuild: bool = False,
389+
) -> bool:
390390
"""
391391
Start an async compilation from a :class:`BuildContext`.
392392
@@ -455,7 +455,7 @@ def get_exclusion_patterns(self) -> List[str]:
455455
pass
456456
return DEFAULT_EXCLUDE_PATTERNS
457457

458-
def should_exclude(self, file_path: str) -> any:
458+
def should_exclude(self, file_path: str) -> bool:
459459
"""
460460
Determine whether a file must be excluded from compilation.
461461

0 commit comments

Comments
 (0)