@@ -70,22 +70,45 @@ def on_pre_compile(self, ctx: PreCompileContext):
7070 if response :
7171 self .cleaned_files = 0
7272 self .cleaned_dirs = 0
73-
74- # Parcourir tous les fichiers du workspace
75- for file_path in ctx .iter_files (["**/*.pyc" ], []):
73+
74+ # Build list of targets first to show accurate progress
75+ workspace_path = Path (getattr (ctx , 'workspace' , Path .cwd ()))
76+ file_targets = list (ctx .iter_files (["**/*.pyc" ], []))
77+ dir_targets = list (workspace_path .rglob ("__pycache__" ))
78+ total = len (file_targets ) + len (dir_targets )
79+
80+ # Create a progress dialog
81+ prog_title = self ._get_translation ("cleaner_progress_title" ) or f"{ title } - Progress"
82+ prog_text = self ._get_translation ("cleaner_progress_text" ) or "Cleaning workspace..."
83+ progress = None
84+ try :
85+ progress = dialog .progress (title = prog_title , text = prog_text , maximum = total if total > 0 else 0 )
86+ except Exception :
87+ progress = None
88+
89+ current = 0
90+
91+ # Process .pyc files
92+ for file_path in file_targets :
7693 try :
7794 Path (file_path ).unlink ()
7895 self .cleaned_files += 1
7996 except Exception as e :
8097 error_msg = (
81- self ._get_translation ("cleaner_error_file" )
98+ self ._get_translation ("cleaner_error_file" )
8299 or "Failed to remove {path}: {error}"
83100 ).format (path = file_path , error = e )
84101 log .log_warn (error_msg )
85-
86- # Parcourir et supprimer les dossiers __pycache__
87- workspace_path = Path (ctx .workspace ) if hasattr (ctx , 'workspace' ) else Path .cwd ()
88- for pycache_dir in workspace_path .rglob ("__pycache__" ):
102+ finally :
103+ current += 1
104+ try :
105+ if progress :
106+ progress .update (value = current , text = f"{ prog_text } ({ current } /{ total } )" )
107+ except Exception :
108+ pass
109+
110+ # Process __pycache__ directories
111+ for pycache_dir in dir_targets :
89112 try :
90113 shutil .rmtree (pycache_dir )
91114 self .cleaned_dirs += 1
@@ -95,12 +118,26 @@ def on_pre_compile(self, ctx: PreCompileContext):
95118 or "Failed to remove {path}: {error}"
96119 ).format (path = pycache_dir , error = e )
97120 log .log_warn (error_msg )
98-
121+ finally :
122+ current += 1
123+ try :
124+ if progress :
125+ progress .update (value = current , text = f"{ prog_text } ({ current } /{ total } )" )
126+ except Exception :
127+ pass
128+
99129 completed_msg = (
100130 self ._get_translation ("cleaner_completed" )
101131 or "Cleaner completed: {files} .pyc files and {dirs} __pycache__ directories removed"
102132 ).format (files = self .cleaned_files , dirs = self .cleaned_dirs )
103133 log .log_info (completed_msg )
134+
135+ # Close progress
136+ try :
137+ if progress :
138+ progress .close ()
139+ except Exception :
140+ pass
104141 else :
105142 cancelled_msg = self ._get_translation ("cleaner_cancelled" ) or "Cleaner cancelled by user"
106143 log .log_info (cancelled_msg )
0 commit comments