2323from __future__ import annotations
2424
2525import os
26+ import re
2627from datetime import datetime
2728from enum import Enum
2829from 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+
4655class 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 """
0 commit comments