eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py

branch
maintenance
changeset 8043
0acf98cd089a
parent 7980
2c3f14a3c595
child 8143
2c730d5fd177
equal deleted inserted replaced
7991:866adc8c315b 8043:0acf98cd089a
7 Module implementing a dialog to show the results of the code style check. 7 Module implementing a dialog to show the results of the code style check.
8 """ 8 """
9 9
10 import os 10 import os
11 import fnmatch 11 import fnmatch
12 import copy
12 13
13 from PyQt5.QtCore import pyqtSlot, Qt, QTimer, QCoreApplication 14 from PyQt5.QtCore import pyqtSlot, Qt, QTimer, QCoreApplication
14 from PyQt5.QtGui import QIcon 15 from PyQt5.QtGui import QIcon
15 from PyQt5.QtWidgets import ( 16 from PyQt5.QtWidgets import (
16 QDialog, QTreeWidgetItem, QAbstractButton, QDialogButtonBox, QApplication, 17 QDialog, QTreeWidgetItem, QAbstractButton, QDialogButtonBox, QApplication,
17 QHeaderView, QListWidgetItem 18 QHeaderView, QListWidgetItem, QInputDialog, QLineEdit
18 ) 19 )
19 20
20 from E5Gui.E5Application import e5App 21 from E5Gui.E5Application import e5App
21 22
22 from .Ui_CodeStyleCheckerDialog import Ui_CodeStyleCheckerDialog 23 from .Ui_CodeStyleCheckerDialog import Ui_CodeStyleCheckerDialog
24 import UI.PixmapCache 25 import UI.PixmapCache
25 import Preferences 26 import Preferences
26 import Utilities 27 import Utilities
27 28
28 from . import pycodestyle 29 from . import pycodestyle
30
31 from .Miscellaneous.MiscellaneousDefaults import (
32 MiscellaneousCheckerDefaultArgs
33 )
29 34
30 try: 35 try:
31 basestring # __IGNORE_WARNING__ 36 basestring # __IGNORE_WARNING__
32 except Exception: 37 except Exception:
33 basestring = str # define for Python3 38 basestring = str # define for Python3
153 self.resultList.headerItem().setText(self.resultList.columnCount(), "") 158 self.resultList.headerItem().setText(self.resultList.columnCount(), "")
154 self.resultList.header().setSortIndicator(0, Qt.AscendingOrder) 159 self.resultList.header().setSortIndicator(0, Qt.AscendingOrder)
155 160
156 self.addBuiltinButton.setIcon(UI.PixmapCache.getIcon("plus")) 161 self.addBuiltinButton.setIcon(UI.PixmapCache.getIcon("plus"))
157 self.deleteBuiltinButton.setIcon(UI.PixmapCache.getIcon("minus")) 162 self.deleteBuiltinButton.setIcon(UI.PixmapCache.getIcon("minus"))
163 self.addWhitelistButton.setIcon(UI.PixmapCache.getIcon("plus"))
164 self.deleteWhitelistButton.setIcon(UI.PixmapCache.getIcon("minus"))
158 165
159 self.restartButton.setEnabled(False) 166 self.restartButton.setEnabled(False)
160 self.fixButton.setEnabled(False) 167 self.fixButton.setEnabled(False)
161 168
162 self.checkProgress.setVisible(False) 169 self.checkProgress.setVisible(False)
447 if "LineComplexity" not in self.__data: 454 if "LineComplexity" not in self.__data:
448 self.__data["LineComplexity"] = 15 455 self.__data["LineComplexity"] = 15
449 if "LineComplexityScore" not in self.__data: 456 if "LineComplexityScore" not in self.__data:
450 self.__data["LineComplexityScore"] = 10 457 self.__data["LineComplexityScore"] = 10
451 if "ValidEncodings" not in self.__data: 458 if "ValidEncodings" not in self.__data:
452 self.__data["ValidEncodings"] = "latin-1, utf-8" 459 self.__data["ValidEncodings"] = (
460 MiscellaneousCheckerDefaultArgs["CodingChecker"]
461 )
453 if ( 462 if (
454 "CopyrightMinFileSize" not in self.__data or 463 "CopyrightMinFileSize" not in self.__data or
455 "CopyrightAuthor" not in self.__data 464 "CopyrightAuthor" not in self.__data
456 ): 465 ):
457 self.__data["CopyrightMinFileSize"] = 0 466 self.__data["CopyrightMinFileSize"] = (
458 self.__data["CopyrightAuthor"] = "" 467 MiscellaneousCheckerDefaultArgs[
468 "CopyrightChecker"]["MinFilesize"]
469 )
470 self.__data["CopyrightAuthor"] = (
471 MiscellaneousCheckerDefaultArgs["CopyrightChecker"]["Author"]
472 )
459 if "FutureChecker" not in self.__data: 473 if "FutureChecker" not in self.__data:
460 self.__data["FutureChecker"] = "" 474 self.__data["FutureChecker"] = ""
461 if "BuiltinsChecker" not in self.__data: 475 if "BuiltinsChecker" not in self.__data:
462 self.__data["BuiltinsChecker"] = { 476 self.__data["BuiltinsChecker"] = copy.deepcopy(
463 "str": ["unicode", ], 477 MiscellaneousCheckerDefaultArgs["BuiltinsChecker"]
464 "chr": ["unichr", ], 478 )
465 } 479
466 if "CommentedCodeChecker" not in self.__data: 480 if "CommentedCodeChecker" not in self.__data:
467 self.__data["CommentedCodeChecker"] = { 481 self.__data["CommentedCodeChecker"] = copy.deepcopy(
468 "Aggressive": False, 482 MiscellaneousCheckerDefaultArgs["CommentedCodeChecker"]
469 } 483 )
484 if "WhiteList" not in self.__data["CommentedCodeChecker"]:
485 self.__data["CommentedCodeChecker"]["WhiteList"] = (
486 MiscellaneousCheckerDefaultArgs[
487 "CommentedCodeChecker"]["WhiteList"][:]
488 )
489
470 if "AnnotationsChecker" not in self.__data: 490 if "AnnotationsChecker" not in self.__data:
471 self.__data["AnnotationsChecker"] = { 491 self.__data["AnnotationsChecker"] = {
472 "MinimumCoverage": 75, 492 "MinimumCoverage": 75,
473 "MaximumComplexity": 3, 493 "MaximumComplexity": 3,
474 } 494 }
524 self.copyrightAuthorEdit.setText(self.__data["CopyrightAuthor"]) 544 self.copyrightAuthorEdit.setText(self.__data["CopyrightAuthor"])
525 self.__initFuturesList(self.__data["FutureChecker"]) 545 self.__initFuturesList(self.__data["FutureChecker"])
526 self.__initBuiltinsIgnoreList(self.__data["BuiltinsChecker"]) 546 self.__initBuiltinsIgnoreList(self.__data["BuiltinsChecker"])
527 self.aggressiveCheckBox.setChecked( 547 self.aggressiveCheckBox.setChecked(
528 self.__data["CommentedCodeChecker"]["Aggressive"]) 548 self.__data["CommentedCodeChecker"]["Aggressive"])
549 self.__initCommentedCodeCheckerWhiteList(
550 self.__data["CommentedCodeChecker"]["WhiteList"])
529 self.minAnnotationsCoverageSpinBox.setValue( 551 self.minAnnotationsCoverageSpinBox.setValue(
530 self.__data["AnnotationsChecker"]["MinimumCoverage"]) 552 self.__data["AnnotationsChecker"]["MinimumCoverage"])
531 self.maxAnnotationsComplexitySpinBox.setValue( 553 self.maxAnnotationsComplexitySpinBox.setValue(
532 self.__data["AnnotationsChecker"]["MaximumComplexity"]) 554 self.__data["AnnotationsChecker"]["MaximumComplexity"])
533 555
675 }, 697 },
676 "FutureChecker": self.__getSelectedFutureImports(), 698 "FutureChecker": self.__getSelectedFutureImports(),
677 "BuiltinsChecker": self.__getBuiltinsIgnoreList(), 699 "BuiltinsChecker": self.__getBuiltinsIgnoreList(),
678 "CommentedCodeChecker": { 700 "CommentedCodeChecker": {
679 "Aggressive": self.aggressiveCheckBox.isChecked(), 701 "Aggressive": self.aggressiveCheckBox.isChecked(),
702 "WhiteList": self.__getCommentedCodeCheckerWhiteList(),
680 } 703 }
681 } 704 }
682 annotationArgs = { 705 annotationArgs = {
683 "MinimumCoverage": 706 "MinimumCoverage":
684 self.minAnnotationsCoverageSpinBox.value(), 707 self.minAnnotationsCoverageSpinBox.value(),
1080 "CopyrightAuthor": self.copyrightAuthorEdit.text(), 1103 "CopyrightAuthor": self.copyrightAuthorEdit.text(),
1081 "FutureChecker": self.__getSelectedFutureImports(), 1104 "FutureChecker": self.__getSelectedFutureImports(),
1082 "BuiltinsChecker": self.__getBuiltinsIgnoreList(), 1105 "BuiltinsChecker": self.__getBuiltinsIgnoreList(),
1083 "CommentedCodeChecker": { 1106 "CommentedCodeChecker": {
1084 "Aggressive": self.aggressiveCheckBox.isChecked(), 1107 "Aggressive": self.aggressiveCheckBox.isChecked(),
1108 "WhiteList": self.__getCommentedCodeCheckerWhiteList(),
1085 }, 1109 },
1086 "AnnotationsChecker": { 1110 "AnnotationsChecker": {
1087 "MinimumCoverage": 1111 "MinimumCoverage":
1088 self.minAnnotationsCoverageSpinBox.value(), 1112 self.minAnnotationsCoverageSpinBox.value(),
1089 "MaximumComplexity": 1113 "MaximumComplexity":
1329 "PEP8/LineComplexity", 15))) 1353 "PEP8/LineComplexity", 15)))
1330 self.lineComplexityScoreSpinBox.setValue( 1354 self.lineComplexityScoreSpinBox.setValue(
1331 int(Preferences.Prefs.settings.value( 1355 int(Preferences.Prefs.settings.value(
1332 "PEP8/LineComplexityScore", 10))) 1356 "PEP8/LineComplexityScore", 10)))
1333 self.encodingsEdit.setText(Preferences.Prefs.settings.value( 1357 self.encodingsEdit.setText(Preferences.Prefs.settings.value(
1334 "PEP8/ValidEncodings", "latin-1, utf-8")) 1358 "PEP8/ValidEncodings",
1359 MiscellaneousCheckerDefaultArgs["CodingChecker"]
1360 ))
1335 self.copyrightFileSizeSpinBox.setValue(int( 1361 self.copyrightFileSizeSpinBox.setValue(int(
1336 Preferences.Prefs.settings.value("PEP8/CopyrightMinFileSize", 0))) 1362 Preferences.Prefs.settings.value(
1363 "PEP8/CopyrightMinFileSize",
1364 MiscellaneousCheckerDefaultArgs[
1365 "CopyrightChecker"]["MinFilesize"]
1366 )
1367 ))
1337 self.copyrightAuthorEdit.setText( 1368 self.copyrightAuthorEdit.setText(
1338 Preferences.Prefs.settings.value("PEP8/CopyrightAuthor", "")) 1369 Preferences.Prefs.settings.value(
1370 "PEP8/CopyrightAuthor",
1371 MiscellaneousCheckerDefaultArgs["CopyrightChecker"]["Author"]
1372 )
1373 )
1339 self.__initFuturesList( 1374 self.__initFuturesList(
1340 Preferences.Prefs.settings.value("PEP8/FutureChecker", "")) 1375 Preferences.Prefs.settings.value("PEP8/FutureChecker", ""))
1341 self.__initBuiltinsIgnoreList(Preferences.toDict( 1376 self.__initBuiltinsIgnoreList(Preferences.toDict(
1342 Preferences.Prefs.settings.value("PEP8/BuiltinsChecker", { 1377 Preferences.Prefs.settings.value(
1343 "str": ["unicode", ], 1378 "PEP8/BuiltinsChecker",
1344 "chr": ["unichr", ], 1379 MiscellaneousCheckerDefaultArgs["BuiltinsChecker"]
1345 }))) 1380 ))
1381 )
1346 self.aggressiveCheckBox.setChecked(Preferences.toBool( 1382 self.aggressiveCheckBox.setChecked(Preferences.toBool(
1347 Preferences.Prefs.settings.value("PEP8/AggressiveSearch", False))) 1383 Preferences.Prefs.settings.value(
1384 "PEP8/AggressiveSearch",
1385 MiscellaneousCheckerDefaultArgs[
1386 "CommentedCodeChecker"]["Aggressive"]
1387 )))
1388 self.__initCommentedCodeCheckerWhiteList(Preferences.toList(
1389 Preferences.Prefs.settings.value(
1390 "PEP8/CommentedCodeWhitelist",
1391 MiscellaneousCheckerDefaultArgs[
1392 "CommentedCodeChecker"]["WhiteList"]
1393 )
1394 ))
1348 self.minAnnotationsCoverageSpinBox.setValue(int( 1395 self.minAnnotationsCoverageSpinBox.setValue(int(
1349 Preferences.Prefs.settings.value( 1396 Preferences.Prefs.settings.value(
1350 "PEP8/MinimumAnnotationsCoverage", 75))) 1397 "PEP8/MinimumAnnotationsCoverage", 75)))
1351 self.maxAnnotationsComplexitySpinBox.setValue(int( 1398 self.maxAnnotationsComplexitySpinBox.setValue(int(
1352 Preferences.Prefs.settings.value( 1399 Preferences.Prefs.settings.value(
1454 Preferences.Prefs.settings.setValue( 1501 Preferences.Prefs.settings.setValue(
1455 "PEP8/BuiltinsChecker", self.__getBuiltinsIgnoreList()) 1502 "PEP8/BuiltinsChecker", self.__getBuiltinsIgnoreList())
1456 Preferences.Prefs.settings.setValue( 1503 Preferences.Prefs.settings.setValue(
1457 "PEP8/AggressiveSearch", self.aggressiveCheckBox.isChecked()) 1504 "PEP8/AggressiveSearch", self.aggressiveCheckBox.isChecked())
1458 Preferences.Prefs.settings.setValue( 1505 Preferences.Prefs.settings.setValue(
1506 "PEP8/CommentedCodeWhitelist",
1507 self.__getCommentedCodeCheckerWhiteList())
1508 Preferences.Prefs.settings.setValue(
1459 "PEP8/MinimumAnnotationsCoverage", 1509 "PEP8/MinimumAnnotationsCoverage",
1460 self.minAnnotationsCoverageSpinBox.value()) 1510 self.minAnnotationsCoverageSpinBox.value())
1461 Preferences.Prefs.settings.setValue( 1511 Preferences.Prefs.settings.setValue(
1462 "PEP8/MaximumAnnotationComplexity", 1512 "PEP8/MaximumAnnotationComplexity",
1463 self.maxAnnotationsComplexitySpinBox.value()) 1513 self.maxAnnotationsComplexitySpinBox.value())
1530 Preferences.Prefs.settings.setValue("PEP8/DocstringType", "pep257") 1580 Preferences.Prefs.settings.setValue("PEP8/DocstringType", "pep257")
1531 Preferences.Prefs.settings.setValue("PEP8/MaxCodeComplexity", 10) 1581 Preferences.Prefs.settings.setValue("PEP8/MaxCodeComplexity", 10)
1532 Preferences.Prefs.settings.setValue("PEP8/LineComplexity", 15) 1582 Preferences.Prefs.settings.setValue("PEP8/LineComplexity", 15)
1533 Preferences.Prefs.settings.setValue("PEP8/LineComplexityScore", 10) 1583 Preferences.Prefs.settings.setValue("PEP8/LineComplexityScore", 10)
1534 Preferences.Prefs.settings.setValue( 1584 Preferences.Prefs.settings.setValue(
1535 "PEP8/ValidEncodings", "latin-1, utf-8") 1585 "PEP8/ValidEncodings",
1536 Preferences.Prefs.settings.setValue("PEP8/CopyrightMinFileSize", 0) 1586 MiscellaneousCheckerDefaultArgs["CodingChecker"]
1537 Preferences.Prefs.settings.setValue("PEP8/CopyrightAuthor", "") 1587 )
1588 Preferences.Prefs.settings.setValue(
1589 "PEP8/CopyrightMinFileSize",
1590 MiscellaneousCheckerDefaultArgs["CopyrightChecker"]["MinFilesize"]
1591 )
1592 Preferences.Prefs.settings.setValue(
1593 "PEP8/CopyrightAuthor",
1594 MiscellaneousCheckerDefaultArgs["CopyrightChecker"]["Author"]
1595 )
1538 Preferences.Prefs.settings.setValue("PEP8/FutureChecker", "") 1596 Preferences.Prefs.settings.setValue("PEP8/FutureChecker", "")
1539 Preferences.Prefs.settings.setValue("PEP8/BuiltinsChecker", { 1597 Preferences.Prefs.settings.setValue(
1540 "str": ["unicode", ], 1598 "PEP8/BuiltinsChecker",
1541 "chr": ["unichr", ], 1599 MiscellaneousCheckerDefaultArgs["BuiltinsChecker"]
1542 }) 1600 )
1543 Preferences.Prefs.settings.setValue("PEP8/AggressiveSearch", False) 1601 Preferences.Prefs.settings.setValue(
1602 "PEP8/AggressiveSearch",
1603 MiscellaneousCheckerDefaultArgs[
1604 "CommentedCodeChecker"]["Aggressive"]
1605 )
1606 Preferences.Prefs.settings.setValue(
1607 "PEP8/CommentedCodeWhitelist",
1608 MiscellaneousCheckerDefaultArgs[
1609 "CommentedCodeChecker"]["WhiteList"]
1610 )
1544 Preferences.Prefs.settings.setValue( 1611 Preferences.Prefs.settings.setValue(
1545 "PEP8/MinimumAnnotationsCoverage", 75) 1612 "PEP8/MinimumAnnotationsCoverage", 75)
1546 Preferences.Prefs.settings.setValue( 1613 Preferences.Prefs.settings.setValue(
1547 "PEP8/MaximumAnnotationComplexity", 3) 1614 "PEP8/MaximumAnnotationComplexity", 3)
1548 1615
1880 if message[0] in disabledCheckers: 1947 if message[0] in disabledCheckers:
1881 excludedMessages.remove(message) 1948 excludedMessages.remove(message)
1882 1949
1883 self.excludeMessagesEdit.setText(",".join(excludedMessages)) 1950 self.excludeMessagesEdit.setText(",".join(excludedMessages))
1884 self.__initCategoriesList(",".join(enabledCheckers)) 1951 self.__initCategoriesList(",".join(enabledCheckers))
1952
1953 def __initCommentedCodeCheckerWhiteList(self, whitelist):
1954 """
1955 Private method to populate the list of commented code whitelist
1956 patterns.
1957
1958 @param whitelist list of commented code whitelist patterns
1959 @type list of str
1960 """
1961 self.whitelistWidget.clear()
1962
1963 for pattern in whitelist:
1964 QListWidgetItem(pattern, self.whitelistWidget)
1965
1966 self.on_whitelistWidget_itemSelectionChanged()
1967
1968 def __getCommentedCodeCheckerWhiteList(self):
1969 """
1970 Private method to get the list of commented code whitelist patterns.
1971
1972 @return list of commented code whitelist patterns
1973 @rtype list of str
1974 """
1975 whitelist = []
1976
1977 for row in range(self.whitelistWidget.count()):
1978 whitelist.append(self.whitelistWidget.item(row).text())
1979
1980 return whitelist
1981
1982 @pyqtSlot()
1983 def on_whitelistWidget_itemSelectionChanged(self):
1984 """
1985 Private slot to react upon changes of the selected whitelist patterns.
1986 """
1987 self.deleteWhitelistButton.setEnabled(
1988 len(self.whitelistWidget.selectedItems()) > 0)
1989
1990 @pyqtSlot()
1991 def on_addWhitelistButton_clicked(self):
1992 """
1993 Private slot to add a commented code whitelist pattern.
1994 """
1995 pattern, ok = QInputDialog.getText(
1996 self,
1997 self.tr("Commented Code Whitelist Pattern"),
1998 self.tr("Enter a Commented Code Whitelist Pattern"),
1999 QLineEdit.Normal)
2000 if ok and pattern:
2001 QListWidgetItem(pattern, self.whitelistWidget)
2002
2003 @pyqtSlot()
2004 def on_deleteWhitelistButton_clicked(self):
2005 """
2006 Private slot to delete the selected items from the list.
2007 """
2008 for itm in self.whitelistWidget.selectedItems():
2009 row = self.whitelistWidget.row(itm)
2010 self.whitelistWidget.takeItem(row)
2011 del itm

eric ide

mercurial