@@ -86,27 +86,18 @@ def __init__(self):
8686
8787 def _get_config (self , ctx : PreCompileContext ) -> dict :
8888 try :
89- cfg = ctx .get_workspace_config () or {}
90- plugins_cfg = cfg .get ("plugins" , {}) if isinstance (cfg , dict ) else {}
91- entry = (
92- plugins_cfg .get (self .meta .id , {})
93- if isinstance (plugins_cfg , dict )
94- else {}
95- )
96- plugin_cfg = entry .get ("config" , {}) if isinstance (entry , dict ) else {}
97- if isinstance (plugin_cfg , dict ):
98- return dict (plugin_cfg )
89+ plugins_cfg = ctx .config .get ("plugins" , {})
90+ entry = plugins_cfg .get (self .meta .id , {})
91+ return entry .get ("config" , {}) if isinstance (entry , dict ) else {}
9992 except Exception :
100- pass
101- return {}
93+ return {}
10294
10395 def build_config_tab (self , parent , ctx : PreCompileContext , config : dict ):
10496 try :
10597 from PySide6 .QtWidgets import (
10698 QCheckBox ,
10799 QFormLayout ,
108100 QGroupBox ,
109- QHBoxLayout ,
110101 QLabel ,
111102 QSizePolicy ,
112103 QVBoxLayout ,
@@ -153,7 +144,6 @@ def build_config_tab(self, parent, ctx: PreCompileContext, config: dict):
153144 lay .addWidget (safety_group )
154145 lay .addWidget (targets_group )
155146
156- # Compact hint
157147 hint = QLabel (
158148 translate (
159149 "cleaner" , "ui_tip" , "Tip: disable items you don't want to delete."
@@ -174,32 +164,16 @@ def on_save(cfg: dict):
174164 return ("Cleaner" , w , on_save )
175165
176166 def on_pre_compile (self , ctx : PreCompileContext ) -> None :
177- """Nettoie le workspace avant la compilation.
178-
179- Args:
180- ctx: PreCompileContext avec les informations du workspace depuis bcasl.yml
181- """
167+ """Nettoie le workspace avant la compilation."""
182168 try :
183- # Vérifier que le workspace est valide et configuré dans bcasl.yml
184- if not ctx .is_workspace_valid ():
185- log .log_warn ("Workspace is not valid or bcasl.yml not found" )
186- return
187-
188169 cfg = self ._get_config (ctx )
189170 ask_confirm = bool (cfg .get ("confirm" , True ))
190171 clean_pyc = bool (cfg .get ("clean_pyc" , True ))
191172 clean_pycache = bool (cfg .get ("clean_pycache" , True ))
173+
192174 if not clean_pyc and not clean_pycache :
193- log .log_info (
194- translate (
195- "cleaner" ,
196- "log_noop" ,
197- "Cleaner: nothing to do (both options disabled)" ,
198- )
199- )
200175 return
201176
202- # Demander confirmation à l'utilisateur
203177 if ask_confirm :
204178 response = dialog .msg_question (
205179 title = "Cleaner" ,
@@ -210,90 +184,47 @@ def on_pre_compile(self, ctx: PreCompileContext) -> None:
210184 ),
211185 default_yes = True ,
212186 )
213-
214187 if not response :
215- log .log_info (
216- translate ("cleaner" , "log_cancel" , "Cleaner cancelled by user" )
217- )
218188 return
219189
220- # Réinitialiser les compteurs
221190 self .cleaned_files = 0
222191 self .cleaned_dirs = 0
223192
224- # Obtenir le chemin du workspace depuis bcasl.yml
225- workspace_path = ctx .get_workspace_root ()
226- workspace_name = ctx .get_workspace_name ()
227-
228- log .log_info (f"Cleaning workspace: { workspace_name } ({ workspace_path } )" )
229-
230- # Créer le dialog de progression
193+ log .log_info (f"Cleaning workspace: { ctx .name } ({ ctx .root } )" )
231194 progress = dialog .progress (title = "Cleaning workspace..." , cancelable = True )
232195 progress .show ()
233196
234197 try :
235- # Étape 1: Parcourir et supprimer les fichiers .pyc
236- progress .set_message (
237- "Scanning for .pyc files and __pycache__ directories..."
238- )
239-
240- pyc_files = []
241- try :
242- # Utiliser les patterns d'exclusion depuis bcasl.yml
243- exclude_patterns = ctx .get_exclude_patterns ()
244- if clean_pyc :
245- for file_path in ctx .iter_files (["**/*.pyc" ], exclude_patterns ):
246- pyc_files .append (file_path )
247- except Exception as e :
248- log .log_warn (f"Error iterating .pyc files: { e } " )
249-
250- # Étape 2: Supprimer les fichiers .pyc
198+ progress .set_message ("Scanning files..." )
199+
251200 if clean_pyc :
201+ pyc_files = list (ctx .iter_files (["**/*.pyc" ]))
252202 progress .set_message ("Removing .pyc files..." )
253203 progress .set_progress (0 , len (pyc_files ))
254-
255204 for idx , file_path in enumerate (pyc_files ):
256- if progress .is_canceled ():
257- break
205+ if progress .is_canceled (): break
258206 try :
259- Path ( file_path ) .unlink ()
207+ file_path .unlink ()
260208 self .cleaned_files += 1
261- except Exception as e :
262- log .log_warn (f"Failed to remove { file_path } : { e } " )
209+ except Exception : pass
263210 progress .set_progress (idx + 1 , len (pyc_files ))
264211
265- # Étape 3: Parcourir et supprimer les dossiers __pycache__
266212 if clean_pycache :
267213 progress .set_message ("Removing __pycache__ directories..." )
268-
269- pycache_dirs = []
270- try :
271- if clean_pycache :
272- for pycache_dir in workspace_path .rglob ("__pycache__" ):
273- pycache_dirs .append (pycache_dir )
274- except Exception as e :
275- log .log_warn (f"Error iterating __pycache__ directories: { e } " )
276-
277- if clean_pycache :
214+ pycache_dirs = list (ctx .root .rglob ("__pycache__" ))
278215 progress .set_progress (0 , len (pycache_dirs ))
279-
280216 for idx , pycache_dir in enumerate (pycache_dirs ):
281- if progress .is_canceled ():
282- break
217+ if progress .is_canceled (): break
283218 try :
284219 shutil .rmtree (pycache_dir )
285220 self .cleaned_dirs += 1
286- except Exception as e :
287- log .log_warn (f"Failed to remove { pycache_dir } : { e } " )
221+ except Exception : pass
288222 progress .set_progress (idx + 1 , len (pycache_dirs ))
289-
290223 finally :
291224 progress .close ()
292225
293- # Afficher le résumé
294226 log .log_info (
295- f"Cleaner completed: { self .cleaned_files } .pyc files and { self .cleaned_dirs } __pycache__ directories removed"
227+ f"Cleaner completed: { self .cleaned_files } files and { self .cleaned_dirs } dirs removed"
296228 )
297-
298229 except Exception as e :
299230 log .log_warn (f"Error during cleaning: { e } " )
0 commit comments