Plugins/PluginPep8Checker.py

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

eric ide

mercurial