Plugins/PluginPep8Checker.py

branch
Py2 comp.
changeset 3056
9986ec0e559a
parent 2791
a9577f248f04
parent 2916
a8628dfdfe04
equal deleted inserted replaced
2911:ce77f0b1ee67 3056:9986ec0e559a
25 autoactivate = True 25 autoactivate = True
26 deactivateable = True 26 deactivateable = True
27 version = "5.4.0" 27 version = "5.4.0"
28 className = "Pep8CheckerPlugin" 28 className = "Pep8CheckerPlugin"
29 packageName = "__core__" 29 packageName = "__core__"
30 shortDescription = "Show the PEP 8 Checker dialog." 30 shortDescription = "Show the Python Code Style Checker dialog."
31 longDescription = """This plugin implements the PEP 8 Checker dialog.""" \ 31 longDescription = """This plugin implements the Python Code Style""" \
32 """ PEP 8 Checker is used to check Python source files for compliance""" \ 32 """ Checker dialog. PEP-8 checker is used to check Python source""" \
33 """ to the conventions given in PEP 8.""" 33 """ files for compliance to the code style conventions given in PEP-8.""" \
34 """ PEP-257 checker is used to check Python source files for""" \
35 """ compliance to docstring conventions given in PEP-257."""
34 pyqtApi = 2 36 pyqtApi = 2
35 # End-Of-Header 37 # End-Of-Header
38
36 39
37 error = "" 40 error = ""
38 41
39 42
40 class Pep8CheckerPlugin(QObject): 43 class Pep8CheckerPlugin(QObject):
72 75
73 @return tuple of None and activation status (boolean) 76 @return tuple of None and activation status (boolean)
74 """ 77 """
75 menu = e5App().getObject("Project").getMenu("Checks") 78 menu = e5App().getObject("Project").getMenu("Checks")
76 if menu: 79 if menu:
77 self.__projectAct = E5Action(self.trUtf8('Check PEP 8 Compliance'), 80 self.__projectAct = E5Action(
78 self.trUtf8('PEP &8 Compliance...'), 0, 0, 81 self.trUtf8('Check Code Style'),
79 self, 'project_check_pep8') 82 self.trUtf8('&Code Style...'), 0, 0,
83 self, 'project_check_pep8')
80 self.__projectAct.setStatusTip( 84 self.__projectAct.setStatusTip(
81 self.trUtf8('Check PEP 8 compliance.')) 85 self.trUtf8('Check PEP 8 compliance.'))
82 self.__projectAct.setWhatsThis(self.trUtf8( 86 self.__projectAct.setWhatsThis(self.trUtf8(
83 """<b>Check PEP 8 Compliance...</b>""" 87 """<b>Check Code Style...</b>"""
84 """<p>This checks Python files for compliance to the""" 88 """<p>This checks Python files for compliance to the"""
85 """ conventions given in PEP 8.</p>""" 89 """ code style conventions given in various PEPs.</p>"""
86 )) 90 ))
87 self.__projectAct.triggered[()].connect(self.__projectPep8Check) 91 self.__projectAct.triggered[()].connect(self.__projectPep8Check)
88 e5App().getObject("Project").addE5Actions([self.__projectAct]) 92 e5App().getObject("Project").addE5Actions([self.__projectAct])
89 menu.addAction(self.__projectAct) 93 menu.addAction(self.__projectAct)
90 94
91 self.__editorAct = E5Action(self.trUtf8('Check PEP 8 Compliance'), 95 self.__editorAct = E5Action(
92 self.trUtf8('PEP &8 Compliance...'), 0, 0, 96 self.trUtf8('Check Code Style'),
93 self, "") 97 self.trUtf8('&Code Style...'), 0, 0,
98 self, "")
94 self.__editorAct.setWhatsThis(self.trUtf8( 99 self.__editorAct.setWhatsThis(self.trUtf8(
95 """<b>Check PEP 8 Compliance...</b>""" 100 """<b>Check Code Style...</b>"""
96 """<p>This checks Python files for compliance to the""" 101 """<p>This checks Python files for compliance to the"""
97 """ conventions given in PEP 8.</p>""" 102 """ code style conventions given in various PEPs.</p>"""
98 )) 103 ))
99 self.__editorAct.triggered[()].connect(self.__editorPep8Check) 104 self.__editorAct.triggered[()].connect(self.__editorPep8Check)
100 105
101 e5App().getObject("Project").showMenu.connect(self.__projectShowMenu) 106 e5App().getObject("Project").showMenu.connect(self.__projectShowMenu)
102 e5App().getObject("ProjectBrowser").getProjectBrowser("sources")\ 107 e5App().getObject("ProjectBrowser").getProjectBrowser("sources")\
149 @param menuName name of the menu to be shown (string) 154 @param menuName name of the menu to be shown (string)
150 @param menu reference to the menu (QMenu) 155 @param menu reference to the menu (QMenu)
151 """ 156 """
152 if menuName == "Checks" and self.__projectAct is not None: 157 if menuName == "Checks" and self.__projectAct is not None:
153 self.__projectAct.setEnabled( 158 self.__projectAct.setEnabled(
154 e5App().getObject("Project").getProjectLanguage() in \ 159 e5App().getObject("Project").getProjectLanguage() in
155 ["Python3", "Python2", "Python"]) 160 ["Python3", "Python2", "Python"])
156 161
157 def __projectBrowserShowMenu(self, menuName, menu): 162 def __projectBrowserShowMenu(self, menuName, menu):
158 """ 163 """
159 Private slot called, when the the project browser menu or a submenu is 164 Private slot called, when the the project browser menu or a submenu is
160 about to be shown. 165 about to be shown.
166 e5App().getObject("Project").getProjectLanguage() in \ 171 e5App().getObject("Project").getProjectLanguage() in \
167 ["Python3", "Python2", "Python"]: 172 ["Python3", "Python2", "Python"]:
168 self.__projectBrowserMenu = menu 173 self.__projectBrowserMenu = menu
169 if self.__projectBrowserAct is None: 174 if self.__projectBrowserAct is None:
170 self.__projectBrowserAct = E5Action( 175 self.__projectBrowserAct = E5Action(
171 self.trUtf8('Check PEP 8 Compliance'), 176 self.trUtf8('Check Code Style'),
172 self.trUtf8('PEP &8 Compliance...'), 0, 0, 177 self.trUtf8('&Code Style...'), 0, 0,
173 self, "") 178 self, "")
174 self.__projectBrowserAct.setWhatsThis(self.trUtf8( 179 self.__projectBrowserAct.setWhatsThis(self.trUtf8(
175 """<b>Check PEP 8 Compliance...</b>""" 180 """<b>Check Code Style...</b>"""
176 """<p>This checks Python files for compliance to the""" 181 """<p>This checks Python files for compliance to the"""
177 """ conventions given in PEP 8.</p>""" 182 """ code style conventions given in various PEPs.</p>"""
178 )) 183 ))
179 self.__projectBrowserAct.triggered[()].connect( 184 self.__projectBrowserAct.triggered[()].connect(
180 self.__projectBrowserPep8Check) 185 self.__projectBrowserPep8Check)
181 if not self.__projectBrowserAct in menu.actions(): 186 if not self.__projectBrowserAct in menu.actions():
182 menu.addAction(self.__projectBrowserAct) 187 menu.addAction(self.__projectBrowserAct)
186 Public slot used to check the project files for PEP 8 compliance. 191 Public slot used to check the project files for PEP 8 compliance.
187 """ 192 """
188 project = e5App().getObject("Project") 193 project = e5App().getObject("Project")
189 project.saveAllScripts() 194 project.saveAllScripts()
190 ppath = project.getProjectPath() 195 ppath = project.getProjectPath()
191 files = [os.path.join(ppath, file) \ 196 files = [os.path.join(ppath, file)
192 for file in project.pdata["SOURCES"] \ 197 for file in project.pdata["SOURCES"]
193 if file.endswith( 198 if file.endswith(
194 tuple(Preferences.getPython("Python3Extensions")) + 199 tuple(Preferences.getPython("Python3Extensions")) +
195 tuple(Preferences.getPython("PythonExtensions")))] 200 tuple(Preferences.getPython("PythonExtensions")))]
196 201
197 from CheckerPlugins.Pep8.Pep8Dialog import Pep8Dialog 202 from CheckerPlugins.Pep8.Pep8Dialog import Pep8Dialog
198 self.__projectPep8CheckerDialog = Pep8Dialog() 203 self.__projectPep8CheckerDialog = Pep8Dialog()
199 self.__projectPep8CheckerDialog.show() 204 self.__projectPep8CheckerDialog.show()
200 self.__projectPep8CheckerDialog.prepare(files, project) 205 self.__projectPep8CheckerDialog.prepare(files, project)
257 @param editor reference to the editor 262 @param editor reference to the editor
258 """ 263 """
259 if menuName == "Checks": 264 if menuName == "Checks":
260 if not self.__editorAct in menu.actions(): 265 if not self.__editorAct in menu.actions():
261 menu.addAction(self.__editorAct) 266 menu.addAction(self.__editorAct)
262 self.__editorAct.setEnabled(editor.isPy3File() or editor.isPy2File()) 267 self.__editorAct.setEnabled(
268 editor.isPy3File() or editor.isPy2File())
263 269
264 def __editorPep8Check(self): 270 def __editorPep8Check(self):
265 """ 271 """
266 Private slot to handle the PEP 8 check context menu action 272 Private slot to handle the PEP 8 check context menu action
267 of the editors. 273 of the editors.

eric ide

mercurial