Thu, 10 Mar 2011 17:40:11 +0100
Implemented some speed improvements for the PEP 8 checker dialog.
Plugins/CheckerPlugins/Pep8/Pep8Dialog.py | file | annotate | diff | comparison | revisions | |
eric5.e4p | file | annotate | diff | comparison | revisions |
--- a/Plugins/CheckerPlugins/Pep8/Pep8Dialog.py Thu Mar 10 16:22:08 2011 +0100 +++ b/Plugins/CheckerPlugins/Pep8/Pep8Dialog.py Thu Mar 10 17:40:11 2011 +0100 @@ -215,6 +215,8 @@ self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True) self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) + self.statisticsButton.setEnabled(False) + self.showButton.setEnabled(False) if repeat is not None: self.repeatCheckBox.setChecked(repeat) QApplication.processEvents() @@ -265,72 +267,81 @@ fixCodes = self.fixIssuesEdit.text() fixIssues = self.fixIssuesCheckBox.isChecked() and repeatMessages - # now go through all the files - progress = 0 - for file in py3files + py2files: - self.checkProgress.setValue(progress) - QApplication.processEvents() - - if self.cancelled: - self.__resort() - return - - self.__lastFileItem = None - - try: - source, encoding = Utilities.readEncodedFile(file) - source = source.splitlines(True) - except (UnicodeError, IOError) as msg: - self.noResults = False - self.__createResultItem(file, "1", "1", - self.trUtf8("Error: {0}").format(str(msg))\ - .rstrip()[1:-1], False) - progress += 1 - continue + try: + # disable updates of the list for speed + self.resultList.setUpdatesEnabled(False) + self.resultList.setSortingEnabled(False) - flags = Utilities.extractFlags(source) - ext = os.path.splitext(file)[1] - if fixIssues: - fixer = Pep8Fixer(self.__project, file, source, - fixCodes, True) # always fix in place - else: - fixer = None - if ("FileType" in flags and - flags["FileType"] in ["Python", "Python2"]) or \ - file in py2files or \ - (ext in [".py", ".pyw"] and \ - Preferences.getProject("DeterminePyFromProject") and \ - self.__project.isOpen() and \ - self.__project.isProjectFile(file) and \ - self.__project.getProjectLanguage() in ["Python", - "Python2"]): - checker = Pep8Py2Checker(file, [], - repeat = repeatMessages, - select = includeMessages, - ignore = excludeMessages) - else: - checker = Pep8Checker(file, source, - repeat = repeatMessages, - select = includeMessages, - ignore = excludeMessages) - checker.check_all() - checker.messages.sort(key = lambda a: a[1]) - for message in checker.messages: - fname, lineno, position, text = message - if not source[lineno - 1].strip()\ - .endswith("__IGNORE_WARNING__"): + # now go through all the files + progress = 0 + for file in py3files + py2files: + self.checkProgress.setValue(progress) + QApplication.processEvents() + + if self.cancelled: + self.__resort() + return + + self.__lastFileItem = None + + try: + source, encoding = Utilities.readEncodedFile(file) + source = source.splitlines(True) + except (UnicodeError, IOError) as msg: self.noResults = False - fixed = False - if fixer: - fixed, msg = fixer.fixIssue(lineno, position, text) - if fixed: - text += "\n" + \ - self.trUtf8("Fix: {0}").format(msg) - self.__createResultItem( - fname, lineno, position, text, fixed) - fixer and fixer.saveFile(encoding) - self.__updateStatistics(checker.statistics, fixer) - progress += 1 + self.__createResultItem(file, "1", "1", + self.trUtf8("Error: {0}").format(str(msg))\ + .rstrip()[1:-1], False) + progress += 1 + continue + + flags = Utilities.extractFlags(source) + ext = os.path.splitext(file)[1] + if fixIssues: + fixer = Pep8Fixer(self.__project, file, source, + fixCodes, True) # always fix in place + else: + fixer = None + if ("FileType" in flags and + flags["FileType"] in ["Python", "Python2"]) or \ + file in py2files or \ + (ext in [".py", ".pyw"] and \ + Preferences.getProject("DeterminePyFromProject") and \ + self.__project.isOpen() and \ + self.__project.isProjectFile(file) and \ + self.__project.getProjectLanguage() in ["Python", + "Python2"]): + checker = Pep8Py2Checker(file, [], + repeat = repeatMessages, + select = includeMessages, + ignore = excludeMessages) + else: + checker = Pep8Checker(file, source, + repeat = repeatMessages, + select = includeMessages, + ignore = excludeMessages) + checker.check_all() + checker.messages.sort(key = lambda a: a[1]) + for message in checker.messages: + fname, lineno, position, text = message + if not source[lineno - 1].strip()\ + .endswith("__IGNORE_WARNING__"): + self.noResults = False + fixed = False + if fixer: + fixed, msg = fixer.fixIssue(lineno, position, text) + if fixed: + text += "\n" + \ + self.trUtf8("Fix: {0}").format(msg) + self.__createResultItem( + fname, lineno, position, text, fixed) + fixer and fixer.saveFile(encoding) + self.__updateStatistics(checker.statistics, fixer) + progress += 1 + finally: + # reenable updates of the list + self.resultList.setSortingEnabled(True) + self.resultList.setUpdatesEnabled(True) self.checkProgress.setValue(progress) QApplication.processEvents() self.__resort() @@ -348,6 +359,8 @@ self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) + self.statisticsButton.setEnabled(True) + self.showButton.setEnabled(True) if self.noResults: QTreeWidgetItem(self.resultList, [self.trUtf8('No issues found.')])
--- a/eric5.e4p Thu Mar 10 16:22:08 2011 +0100 +++ b/eric5.e4p Thu Mar 10 17:40:11 2011 +0100 @@ -1538,7 +1538,7 @@ <string>ExcludeFiles</string> </key> <value> - <string>*/coverage/*, */ThirdParty/*</string> + <string>*/ThirdParty/*, */coverage/*</string> </value> <key> <string>ExcludeMessages</string> @@ -1547,6 +1547,18 @@ <string>E24, W293</string> </value> <key> + <string>FixCodes</string> + </key> + <value> + <string></string> + </value> + <key> + <string>FixIssues</string> + </key> + <value> + <bool>False</bool> + </value> + <key> <string>IncludeMessages</string> </key> <value>