7 Module implementing the vulture plug-in. |
7 Module implementing the vulture plug-in. |
8 """ |
8 """ |
9 |
9 |
10 import os |
10 import os |
11 |
11 |
12 from PyQt5.QtCore import pyqtSignal, QObject, QTranslator |
12 from PyQt6.QtCore import pyqtSignal, QObject, QTranslator |
13 |
13 |
14 from E5Gui.E5Application import e5App |
14 from EricWidgets.EricApplication import ericApp |
15 from E5Gui.E5Action import E5Action |
15 from EricGui.EricAction import EricAction |
16 |
16 |
17 import Preferences |
17 import Preferences |
18 from Utilities import determinePythonVersion |
18 from Utilities import determinePythonVersion |
19 |
19 |
20 # Start-Of-Header |
20 # Start-Of-Header |
21 name = "Unused Code Checker Plug-in" |
21 name = "Unused Code Checker Plug-in" |
22 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
22 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
23 autoactivate = True |
23 autoactivate = True |
24 deactivateable = True |
24 deactivateable = True |
25 version = "5.0.0" |
25 version = "1.0.0" |
26 className = "VulturePlugin" |
26 className = "VulturePlugin" |
27 packageName = "VultureChecker" |
27 packageName = "VultureChecker" |
28 shortDescription = "Plug-in to detect unused code using the vulture library" |
28 shortDescription = "Plug-in to detect unused code using the 'vulture' library" |
29 longDescription = ( |
29 longDescription = ( |
30 """Plug-in to detect unused code using the vulture library.""" |
30 """Plug-in to detect unused code using the 'vulture' library.""" |
31 ) |
31 ) |
32 needsRestart = False |
32 needsRestart = False |
33 pyqtApi = 2 |
33 pyqtApi = 2 |
34 # End-Of-Header |
34 # End-Of-Header |
35 |
35 |
51 |
51 |
52 def __init__(self, ui): |
52 def __init__(self, ui): |
53 """ |
53 """ |
54 Constructor |
54 Constructor |
55 |
55 |
56 @param ui reference to the user interface object (UI.UserInterface) |
56 @param ui reference to the user interface object |
|
57 @type UserInterface |
57 """ |
58 """ |
58 super().__init__(ui) |
59 super().__init__(ui) |
59 self.__ui = ui |
60 self.__ui = ui |
60 self.__initialize() |
61 self.__initialize() |
61 |
62 |
62 self.backgroundService = e5App().getObject("BackgroundService") |
63 self.backgroundService = ericApp().getObject("BackgroundService") |
63 |
64 |
64 path = os.path.join(os.path.dirname(__file__), packageName) |
65 path = os.path.join(os.path.dirname(__file__), packageName) |
65 self.backgroundService.serviceConnect( |
66 self.backgroundService.serviceConnect( |
66 'vulture', 'Python3', path, 'VultureCheckerService', |
67 'vulture', 'Python3', path, 'VultureCheckerService', |
67 self.vultureCheckDone, |
68 self.vultureCheckDone, |
194 |
195 |
195 def activate(self): |
196 def activate(self): |
196 """ |
197 """ |
197 Public method to activate this plug-in. |
198 Public method to activate this plug-in. |
198 |
199 |
199 @return tuple of None and activation status (boolean) |
200 @return tuple of None and activation status |
|
201 @rtype tuple of (None, bool) |
200 """ |
202 """ |
201 global error |
203 global error |
202 error = "" # clear previous error |
204 error = "" # clear previous error |
203 |
205 |
204 menu = e5App().getObject("Project").getMenu("Checks") |
206 menu = ericApp().getObject("Project").getMenu("Checks") |
205 if menu: |
207 if menu: |
206 self.__projectAct = E5Action( |
208 self.__projectAct = EricAction( |
207 self.tr('Check Unused Code'), |
209 self.tr('Check Unused Code'), |
208 self.tr('&Unused Code...'), 0, 0, |
210 self.tr('&Unused Code...'), 0, 0, |
209 self, 'project_check_vulture') |
211 self, 'project_check_vulture') |
210 self.__projectAct.setStatusTip( |
212 self.__projectAct.setStatusTip( |
211 self.tr('Check for unused code')) |
213 self.tr('Check for unused code')) |
213 """<b>Check Unused Code...</b>""" |
215 """<b>Check Unused Code...</b>""" |
214 """<p>This checks a Python project for unused code.</p>""" |
216 """<p>This checks a Python project for unused code.</p>""" |
215 )) |
217 )) |
216 self.__projectAct.triggered.connect( |
218 self.__projectAct.triggered.connect( |
217 self.__projectVultureCheck) |
219 self.__projectVultureCheck) |
218 e5App().getObject("Project").addE5Actions([self.__projectAct]) |
220 ericApp().getObject("Project").addEricActions([self.__projectAct]) |
219 menu.addAction(self.__projectAct) |
221 menu.addAction(self.__projectAct) |
220 |
222 |
221 e5App().getObject("Project").showMenu.connect(self.__projectShowMenu) |
223 ericApp().getObject("Project").showMenu.connect(self.__projectShowMenu) |
222 e5App().getObject("Project").projectClosed.connect( |
224 ericApp().getObject("Project").projectClosed.connect( |
223 self.__projectClosed) |
225 self.__projectClosed) |
224 |
226 |
225 return None, True |
227 return None, True |
226 |
228 |
227 def deactivate(self): |
229 def deactivate(self): |
228 """ |
230 """ |
229 Public method to deactivate this plug-in. |
231 Public method to deactivate this plug-in. |
230 """ |
232 """ |
231 e5App().getObject("Project").showMenu.disconnect( |
233 ericApp().getObject("Project").showMenu.disconnect( |
232 self.__projectShowMenu) |
234 self.__projectShowMenu) |
233 e5App().getObject("Project").projectClosed.disconnect( |
235 ericApp().getObject("Project").projectClosed.disconnect( |
234 self.__projectClosed) |
236 self.__projectClosed) |
235 |
237 |
236 menu = e5App().getObject("Project").getMenu("Checks") |
238 menu = ericApp().getObject("Project").getMenu("Checks") |
237 if menu is not None and self.__projectAct is not None: |
239 if menu is not None and self.__projectAct is not None: |
238 menu.removeAction(self.__projectAct) |
240 menu.removeAction(self.__projectAct) |
239 e5App().getObject("Project").removeE5Actions( |
241 ericApp().getObject("Project").removeEricActions( |
240 [self.__projectAct]) |
242 [self.__projectAct]) |
241 |
243 |
242 self.__initialize() |
244 self.__initialize() |
243 |
245 |
244 def __loadTranslator(self): |
246 def __loadTranslator(self): |
253 translation = "vulture_{0}".format(loc) |
255 translation = "vulture_{0}".format(loc) |
254 translator = QTranslator(None) |
256 translator = QTranslator(None) |
255 loaded = translator.load(translation, locale_dir) |
257 loaded = translator.load(translation, locale_dir) |
256 if loaded: |
258 if loaded: |
257 self.__translator = translator |
259 self.__translator = translator |
258 e5App().installTranslator(self.__translator) |
260 ericApp().installTranslator(self.__translator) |
259 else: |
261 else: |
260 print("Warning: translation file '{0}' could not be" |
262 print("Warning: translation file '{0}' could not be" |
261 " loaded.".format(translation)) |
263 " loaded.".format(translation)) |
262 print("Using default.") |
264 print("Using default.") |
263 |
265 |
271 @param menu reference to the menu |
273 @param menu reference to the menu |
272 @type QMenu |
274 @type QMenu |
273 """ |
275 """ |
274 if menuName == "Check" and self.__projectAct is not None: |
276 if menuName == "Check" and self.__projectAct is not None: |
275 self.__projectAct.setEnabled( |
277 self.__projectAct.setEnabled( |
276 e5App().getObject("Project") |
278 ericApp().getObject("Project") |
277 .getProjectLanguage() == "Python3" |
279 .getProjectLanguage() == "Python3" |
278 ) |
280 ) |
279 |
281 |
280 def __projectVultureCheck(self): |
282 def __projectVultureCheck(self): |
281 """ |
283 """ |
282 Private slot used to check the project for unused code. |
284 Private slot used to check the project for unused code. |
283 """ |
285 """ |
284 project = e5App().getObject("Project") |
286 project = ericApp().getObject("Project") |
285 project.saveAllScripts() |
287 project.saveAllScripts() |
286 ppath = project.getProjectPath() |
288 ppath = project.getProjectPath() |
287 files = [os.path.join(ppath, file_) |
289 files = [ |
288 for file_ in project.getSources() |
290 os.path.join(ppath, file_) |
289 if file_.endswith( |
291 for file_ in project.getSources() |
290 tuple(Preferences.getPython("Python3Extensions")) + |
292 if file_.endswith( |
291 tuple(Preferences.getPython("PythonExtensions")))] |
293 tuple(Preferences.getPython("Python3Extensions")) |
|
294 ) |
|
295 ] |
292 |
296 |
293 if self.__projectVultureCheckerDialog is None: |
297 if self.__projectVultureCheckerDialog is None: |
294 from VultureChecker.VultureCheckerDialog import ( |
298 from VultureChecker.VultureCheckerDialog import ( |
295 VultureCheckerDialog |
299 VultureCheckerDialog |
296 ) |
300 ) |