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, |
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 } |
|
466 |
479 |
467 if "CommentedCodeChecker" not in self.__data: |
480 if "CommentedCodeChecker" not in self.__data: |
468 self.__data["CommentedCodeChecker"] = { |
481 self.__data["CommentedCodeChecker"] = copy.deepcopy( |
469 "Aggressive": False, |
482 MiscellaneousCheckerDefaultArgs["CommentedCodeChecker"] |
470 } |
483 ) |
471 if "WhiteList" not in self.__data["CommentedCodeChecker"]: |
484 if "WhiteList" not in self.__data["CommentedCodeChecker"]: |
472 self.__data["CommentedCodeChecker"]["WhiteList"] = [ |
485 self.__data["CommentedCodeChecker"]["WhiteList"] = ( |
473 r'pylint', |
486 MiscellaneousCheckerDefaultArgs[ |
474 r'pyright', |
487 "CommentedCodeChecker"]["WhiteList"][:] |
475 r'noqa', |
488 ) |
476 r'type:\s*ignore', |
|
477 r'fmt:\s*(on|off)', |
|
478 r'TODO', |
|
479 r'FIXME', |
|
480 r'WARNING', |
|
481 r'NOTE', |
|
482 r'TEST', |
|
483 r'DOCU', |
|
484 r'XXX', |
|
485 r'~ ', |
|
486 r'- ', |
|
487 ] |
|
488 |
489 |
489 if "AnnotationsChecker" not in self.__data: |
490 if "AnnotationsChecker" not in self.__data: |
490 self.__data["AnnotationsChecker"] = { |
491 self.__data["AnnotationsChecker"] = { |
491 "MinimumCoverage": 75, |
492 "MinimumCoverage": 75, |
492 "MaximumComplexity": 3, |
493 "MaximumComplexity": 3, |
1352 "PEP8/LineComplexity", 15))) |
1353 "PEP8/LineComplexity", 15))) |
1353 self.lineComplexityScoreSpinBox.setValue( |
1354 self.lineComplexityScoreSpinBox.setValue( |
1354 int(Preferences.Prefs.settings.value( |
1355 int(Preferences.Prefs.settings.value( |
1355 "PEP8/LineComplexityScore", 10))) |
1356 "PEP8/LineComplexityScore", 10))) |
1356 self.encodingsEdit.setText(Preferences.Prefs.settings.value( |
1357 self.encodingsEdit.setText(Preferences.Prefs.settings.value( |
1357 "PEP8/ValidEncodings", "latin-1, utf-8")) |
1358 "PEP8/ValidEncodings", |
|
1359 MiscellaneousCheckerDefaultArgs["CodingChecker"] |
|
1360 )) |
1358 self.copyrightFileSizeSpinBox.setValue(int( |
1361 self.copyrightFileSizeSpinBox.setValue(int( |
1359 Preferences.Prefs.settings.value("PEP8/CopyrightMinFileSize", 0))) |
1362 Preferences.Prefs.settings.value( |
|
1363 "PEP8/CopyrightMinFileSize", |
|
1364 MiscellaneousCheckerDefaultArgs[ |
|
1365 "CopyrightChecker"]["MinFilesize"] |
|
1366 ) |
|
1367 )) |
1360 self.copyrightAuthorEdit.setText( |
1368 self.copyrightAuthorEdit.setText( |
1361 Preferences.Prefs.settings.value("PEP8/CopyrightAuthor", "")) |
1369 Preferences.Prefs.settings.value( |
|
1370 "PEP8/CopyrightAuthor", |
|
1371 MiscellaneousCheckerDefaultArgs["CopyrightChecker"]["Author"] |
|
1372 ) |
|
1373 ) |
1362 self.__initFuturesList( |
1374 self.__initFuturesList( |
1363 Preferences.Prefs.settings.value("PEP8/FutureChecker", "")) |
1375 Preferences.Prefs.settings.value("PEP8/FutureChecker", "")) |
1364 self.__initBuiltinsIgnoreList(Preferences.toDict( |
1376 self.__initBuiltinsIgnoreList(Preferences.toDict( |
1365 Preferences.Prefs.settings.value("PEP8/BuiltinsChecker", { |
1377 Preferences.Prefs.settings.value( |
1366 "str": ["unicode", ], |
1378 "PEP8/BuiltinsChecker", |
1367 "chr": ["unichr", ], |
1379 MiscellaneousCheckerDefaultArgs["BuiltinsChecker"] |
1368 }))) |
1380 )) |
|
1381 ) |
1369 self.aggressiveCheckBox.setChecked(Preferences.toBool( |
1382 self.aggressiveCheckBox.setChecked(Preferences.toBool( |
1370 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 )) |
1371 self.minAnnotationsCoverageSpinBox.setValue(int( |
1395 self.minAnnotationsCoverageSpinBox.setValue(int( |
1372 Preferences.Prefs.settings.value( |
1396 Preferences.Prefs.settings.value( |
1373 "PEP8/MinimumAnnotationsCoverage", 75))) |
1397 "PEP8/MinimumAnnotationsCoverage", 75))) |
1374 self.maxAnnotationsComplexitySpinBox.setValue(int( |
1398 self.maxAnnotationsComplexitySpinBox.setValue(int( |
1375 Preferences.Prefs.settings.value( |
1399 Preferences.Prefs.settings.value( |
1477 Preferences.Prefs.settings.setValue( |
1501 Preferences.Prefs.settings.setValue( |
1478 "PEP8/BuiltinsChecker", self.__getBuiltinsIgnoreList()) |
1502 "PEP8/BuiltinsChecker", self.__getBuiltinsIgnoreList()) |
1479 Preferences.Prefs.settings.setValue( |
1503 Preferences.Prefs.settings.setValue( |
1480 "PEP8/AggressiveSearch", self.aggressiveCheckBox.isChecked()) |
1504 "PEP8/AggressiveSearch", self.aggressiveCheckBox.isChecked()) |
1481 Preferences.Prefs.settings.setValue( |
1505 Preferences.Prefs.settings.setValue( |
|
1506 "PEP8/CommentedCodeWhitelist", |
|
1507 self.__getCommentedCodeCheckerWhiteList()) |
|
1508 Preferences.Prefs.settings.setValue( |
1482 "PEP8/MinimumAnnotationsCoverage", |
1509 "PEP8/MinimumAnnotationsCoverage", |
1483 self.minAnnotationsCoverageSpinBox.value()) |
1510 self.minAnnotationsCoverageSpinBox.value()) |
1484 Preferences.Prefs.settings.setValue( |
1511 Preferences.Prefs.settings.setValue( |
1485 "PEP8/MaximumAnnotationComplexity", |
1512 "PEP8/MaximumAnnotationComplexity", |
1486 self.maxAnnotationsComplexitySpinBox.value()) |
1513 self.maxAnnotationsComplexitySpinBox.value()) |
1553 Preferences.Prefs.settings.setValue("PEP8/DocstringType", "pep257") |
1580 Preferences.Prefs.settings.setValue("PEP8/DocstringType", "pep257") |
1554 Preferences.Prefs.settings.setValue("PEP8/MaxCodeComplexity", 10) |
1581 Preferences.Prefs.settings.setValue("PEP8/MaxCodeComplexity", 10) |
1555 Preferences.Prefs.settings.setValue("PEP8/LineComplexity", 15) |
1582 Preferences.Prefs.settings.setValue("PEP8/LineComplexity", 15) |
1556 Preferences.Prefs.settings.setValue("PEP8/LineComplexityScore", 10) |
1583 Preferences.Prefs.settings.setValue("PEP8/LineComplexityScore", 10) |
1557 Preferences.Prefs.settings.setValue( |
1584 Preferences.Prefs.settings.setValue( |
1558 "PEP8/ValidEncodings", "latin-1, utf-8") |
1585 "PEP8/ValidEncodings", |
1559 Preferences.Prefs.settings.setValue("PEP8/CopyrightMinFileSize", 0) |
1586 MiscellaneousCheckerDefaultArgs["CodingChecker"] |
1560 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 ) |
1561 Preferences.Prefs.settings.setValue("PEP8/FutureChecker", "") |
1596 Preferences.Prefs.settings.setValue("PEP8/FutureChecker", "") |
1562 Preferences.Prefs.settings.setValue("PEP8/BuiltinsChecker", { |
1597 Preferences.Prefs.settings.setValue( |
1563 "str": ["unicode", ], |
1598 "PEP8/BuiltinsChecker", |
1564 "chr": ["unichr", ], |
1599 MiscellaneousCheckerDefaultArgs["BuiltinsChecker"] |
1565 }) |
1600 ) |
1566 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 ) |
1567 Preferences.Prefs.settings.setValue( |
1611 Preferences.Prefs.settings.setValue( |
1568 "PEP8/MinimumAnnotationsCoverage", 75) |
1612 "PEP8/MinimumAnnotationsCoverage", 75) |
1569 Preferences.Prefs.settings.setValue( |
1613 Preferences.Prefs.settings.setValue( |
1570 "PEP8/MaximumAnnotationComplexity", 3) |
1614 "PEP8/MaximumAnnotationComplexity", 3) |
1571 |
1615 |