Wed, 13 Jul 2022 14:55:47 +0200
Reformatted the source code using the 'Black' utility.
832
eb5ff61f927b
Added a checker for PEP 8 compliance.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
eb5ff61f927b
Added a checker for PEP 8 compliance.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
8881
54e42bc2437a
Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8801
diff
changeset
|
3 | # Copyright (c) 2011 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
832
eb5ff61f927b
Added a checker for PEP 8 compliance.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
eb5ff61f927b
Added a checker for PEP 8 compliance.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
eb5ff61f927b
Added a checker for PEP 8 compliance.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
2980
2cb4e3c50b37
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2979
diff
changeset
|
7 | Module implementing the code style checker. |
832
eb5ff61f927b
Added a checker for PEP 8 compliance.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
eb5ff61f927b
Added a checker for PEP 8 compliance.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
7637
c878e8255972
Removed some more Python2 related code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7635
diff
changeset
|
10 | import queue |
7619
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
11 | import ast |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
12 | import sys |
4218
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
13 | import multiprocessing |
8243
cc717c2ae956
Applied some more code simplifications suggested by the new Simplify checker (Y105: use contextlib.suppress) (batch 2).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8218
diff
changeset
|
14 | import contextlib |
3056
9986ec0e559a
Merge with default branch before style changes.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2929
diff
changeset
|
15 | |
5147
d39dd5cee0c8
Renamed pep8.py to pycodestyle.py in order to track the upstream renaming.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
16 | import pycodestyle |
8790
548df4df8256
Continued implementing a checker for import statements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8650
diff
changeset
|
17 | |
548df4df8256
Continued implementing a checker for import statements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8650
diff
changeset
|
18 | from Complexity.ComplexityChecker import ComplexityChecker |
548df4df8256
Continued implementing a checker for import statements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8650
diff
changeset
|
19 | from DocStyle.DocStyleChecker import DocStyleChecker |
548df4df8256
Continued implementing a checker for import statements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8650
diff
changeset
|
20 | from Imports.ImportsChecker import ImportsChecker |
548df4df8256
Continued implementing a checker for import statements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8650
diff
changeset
|
21 | from Miscellaneous.MiscellaneousChecker import MiscellaneousChecker |
7784
3257703e10c5
Finished refactoring the code style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7782
diff
changeset
|
22 | from Naming.NamingStyleChecker import NamingStyleChecker |
8790
548df4df8256
Continued implementing a checker for import statements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8650
diff
changeset
|
23 | from PathLib.PathlibChecker import PathlibChecker |
548df4df8256
Continued implementing a checker for import statements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8650
diff
changeset
|
24 | from Security.SecurityChecker import SecurityChecker |
548df4df8256
Continued implementing a checker for import statements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8650
diff
changeset
|
25 | from Simplify.SimplifyChecker import SimplifyChecker |
843
522c8befcf49
Continued implementing a PRP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
832
diff
changeset
|
26 | |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
27 | # register the name checker |
5147
d39dd5cee0c8
Renamed pep8.py to pycodestyle.py in order to track the upstream renaming.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
28 | pycodestyle.register_check(NamingStyleChecker, NamingStyleChecker.Codes) |
832
eb5ff61f927b
Added a checker for PEP 8 compliance.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | |
eb5ff61f927b
Added a checker for PEP 8 compliance.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
31 | def initService(): |
843
522c8befcf49
Continued implementing a PRP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
832
diff
changeset
|
32 | """ |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
33 | Initialize the service and return the entry point. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
34 | |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
35 | @return the entry point for the background client (function) |
843
522c8befcf49
Continued implementing a PRP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
832
diff
changeset
|
36 | """ |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
37 | return codeStyleCheck |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
38 | |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
39 | |
4218
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
40 | def initBatchService(): |
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
41 | """ |
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
42 | Initialize the batch service and return the entry point. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
43 | |
4218
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
44 | @return the entry point for the background client (function) |
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
45 | """ |
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
46 | return codeStyleBatchCheck |
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
47 | |
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
48 | |
5147
d39dd5cee0c8
Renamed pep8.py to pycodestyle.py in order to track the upstream renaming.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
49 | class CodeStyleCheckerReport(pycodestyle.BaseReport): |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
50 | """ |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
51 | Class implementing a special report to be used with our dialog. |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
52 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
53 | |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
54 | def __init__(self, options): |
843
522c8befcf49
Continued implementing a PRP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
832
diff
changeset
|
55 | """ |
522c8befcf49
Continued implementing a PRP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
832
diff
changeset
|
56 | Constructor |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
57 | |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
58 | @param options options for the report (optparse.Values) |
843
522c8befcf49
Continued implementing a PRP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
832
diff
changeset
|
59 | """ |
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8205
diff
changeset
|
60 | super().__init__(options) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
61 | |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
62 | self.__repeat = options.repeat |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
63 | self.errors = [] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
64 | |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
65 | def error_args(self, line_number, offset, code, check, *args): |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
66 | """ |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
67 | Public method to collect the error messages. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
68 | |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
69 | @param line_number line number of the issue (integer) |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
70 | @param offset position within line of the issue (integer) |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
71 | @param code message code (string) |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
72 | @param check reference to the checker function (function) |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
73 | @param args arguments for the message (list) |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
74 | @return error code (string) |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
75 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
76 | code = super().error_args(line_number, offset, code, check, *args) |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
77 | if code and (self.counters[code] == 1 or self.__repeat): |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
78 | self.errors.append( |
7610
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
79 | { |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
80 | "file": self.filename, |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
81 | "line": line_number, |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
82 | "offset": offset, |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
83 | "code": code, |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
84 | "args": args, |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
85 | } |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
86 | ) |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
87 | return code |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
88 | |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
89 | |
5586
0e5421d679e7
Added capability to place line flags (e.g. __IGNORE...) on the line following the one to be ignored.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
90 | def extractLineFlags(line, startComment="#", endComment="", flagsLine=False): |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
91 | """ |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
92 | Function to extract flags starting and ending with '__' from a line |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
93 | comment. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
94 | |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
95 | @param line line to extract flags from (string) |
7900
72b88fb20261
Corrected the use of '@keyparam' in the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7784
diff
changeset
|
96 | @param startComment string identifying the start of the comment (string) |
72b88fb20261
Corrected the use of '@keyparam' in the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7784
diff
changeset
|
97 | @param endComment string identifying the end of a comment (string) |
72b88fb20261
Corrected the use of '@keyparam' in the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7784
diff
changeset
|
98 | @param flagsLine flag indicating to check for a flags only line (bool) |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
99 | @return list containing the extracted flags (list of strings) |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
100 | """ |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
101 | flags = [] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
102 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
103 | if not flagsLine or (flagsLine and line.strip().startswith(startComment)): |
5586
0e5421d679e7
Added capability to place line flags (e.g. __IGNORE...) on the line following the one to be ignored.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
104 | pos = line.rfind(startComment) |
0e5421d679e7
Added capability to place line flags (e.g. __IGNORE...) on the line following the one to be ignored.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
105 | if pos >= 0: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
106 | comment = line[pos + len(startComment) :].strip() |
5586
0e5421d679e7
Added capability to place line flags (e.g. __IGNORE...) on the line following the one to be ignored.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
107 | if endComment: |
0e5421d679e7
Added capability to place line flags (e.g. __IGNORE...) on the line following the one to be ignored.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
108 | endPos = line.rfind(endComment) |
0e5421d679e7
Added capability to place line flags (e.g. __IGNORE...) on the line following the one to be ignored.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
109 | if endPos >= 0: |
0e5421d679e7
Added capability to place line flags (e.g. __IGNORE...) on the line following the one to be ignored.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
110 | comment = comment[:endPos] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
111 | flags = [ |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
112 | f.strip() |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
113 | for f in comment.split() |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
114 | if (f.startswith("__") and f.endswith("__")) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
115 | ] |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
116 | flags += [ |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
117 | f.strip().lower() |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
118 | for f in comment.split() |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
119 | if f in ("noqa", "NOQA", "nosec", "NOSEC", "secok", "SECOK") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
120 | ] |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
121 | return flags |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
122 | |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
123 | |
5725
671561c52802
Finetuned the coding style checker a little bit to allow groups of messages to be ignored (e.g. __IGNORE_WARNING_N10__ for all N10x warnings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
124 | def ignoreCode(code, lineFlags): |
671561c52802
Finetuned the coding style checker a little bit to allow groups of messages to be ignored (e.g. __IGNORE_WARNING_N10__ for all N10x warnings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
125 | """ |
671561c52802
Finetuned the coding style checker a little bit to allow groups of messages to be ignored (e.g. __IGNORE_WARNING_N10__ for all N10x warnings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
126 | Function to check, if the given code should be ignored as per line flags. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
127 | |
5725
671561c52802
Finetuned the coding style checker a little bit to allow groups of messages to be ignored (e.g. __IGNORE_WARNING_N10__ for all N10x warnings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
128 | @param code error code to be checked |
671561c52802
Finetuned the coding style checker a little bit to allow groups of messages to be ignored (e.g. __IGNORE_WARNING_N10__ for all N10x warnings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
129 | @type str |
671561c52802
Finetuned the coding style checker a little bit to allow groups of messages to be ignored (e.g. __IGNORE_WARNING_N10__ for all N10x warnings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
130 | @param lineFlags list of line flags to check against |
671561c52802
Finetuned the coding style checker a little bit to allow groups of messages to be ignored (e.g. __IGNORE_WARNING_N10__ for all N10x warnings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
131 | @type list of str |
5737
6820ae39114e
Fixed a source docu issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5725
diff
changeset
|
132 | @return flag indicating to ignore the code |
6820ae39114e
Fixed a source docu issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5725
diff
changeset
|
133 | @rtype bool |
5725
671561c52802
Finetuned the coding style checker a little bit to allow groups of messages to be ignored (e.g. __IGNORE_WARNING_N10__ for all N10x warnings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
134 | """ |
671561c52802
Finetuned the coding style checker a little bit to allow groups of messages to be ignored (e.g. __IGNORE_WARNING_N10__ for all N10x warnings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
135 | if lineFlags: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
136 | |
7256
4ef3b78ebb4e
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7247
diff
changeset
|
137 | if ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
138 | "__IGNORE_WARNING__" in lineFlags |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
139 | or "noqa" in lineFlags |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
140 | or "nosec" in lineFlags |
7256
4ef3b78ebb4e
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7247
diff
changeset
|
141 | ): |
5725
671561c52802
Finetuned the coding style checker a little bit to allow groups of messages to be ignored (e.g. __IGNORE_WARNING_N10__ for all N10x warnings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
142 | # ignore all warning codes |
671561c52802
Finetuned the coding style checker a little bit to allow groups of messages to be ignored (e.g. __IGNORE_WARNING_N10__ for all N10x warnings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
143 | return True |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
144 | |
5725
671561c52802
Finetuned the coding style checker a little bit to allow groups of messages to be ignored (e.g. __IGNORE_WARNING_N10__ for all N10x warnings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
145 | for flag in lineFlags: |
671561c52802
Finetuned the coding style checker a little bit to allow groups of messages to be ignored (e.g. __IGNORE_WARNING_N10__ for all N10x warnings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
146 | # check individual warning code |
671561c52802
Finetuned the coding style checker a little bit to allow groups of messages to be ignored (e.g. __IGNORE_WARNING_N10__ for all N10x warnings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
147 | if flag.startswith("__IGNORE_WARNING_"): |
671561c52802
Finetuned the coding style checker a little bit to allow groups of messages to be ignored (e.g. __IGNORE_WARNING_N10__ for all N10x warnings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
148 | ignoredCode = flag[2:-2].rsplit("_", 1)[-1] |
671561c52802
Finetuned the coding style checker a little bit to allow groups of messages to be ignored (e.g. __IGNORE_WARNING_N10__ for all N10x warnings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
149 | if code.startswith(ignoredCode): |
671561c52802
Finetuned the coding style checker a little bit to allow groups of messages to be ignored (e.g. __IGNORE_WARNING_N10__ for all N10x warnings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
150 | return True |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
151 | |
5725
671561c52802
Finetuned the coding style checker a little bit to allow groups of messages to be ignored (e.g. __IGNORE_WARNING_N10__ for all N10x warnings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
152 | return False |
671561c52802
Finetuned the coding style checker a little bit to allow groups of messages to be ignored (e.g. __IGNORE_WARNING_N10__ for all N10x warnings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
153 | |
671561c52802
Finetuned the coding style checker a little bit to allow groups of messages to be ignored (e.g. __IGNORE_WARNING_N10__ for all N10x warnings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
154 | |
7615
ca2949b1a29a
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7611
diff
changeset
|
155 | def securityOk(code, lineFlags): |
ca2949b1a29a
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7611
diff
changeset
|
156 | """ |
ca2949b1a29a
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7611
diff
changeset
|
157 | Function to check, if the given code is an acknowledged security report. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
158 | |
7615
ca2949b1a29a
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7611
diff
changeset
|
159 | @param code error code to be checked |
ca2949b1a29a
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7611
diff
changeset
|
160 | @type str |
ca2949b1a29a
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7611
diff
changeset
|
161 | @param lineFlags list of line flags to check against |
ca2949b1a29a
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7611
diff
changeset
|
162 | @type list of str |
ca2949b1a29a
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7611
diff
changeset
|
163 | @return flag indicating an acknowledged security report |
ca2949b1a29a
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7611
diff
changeset
|
164 | @rtype bool |
ca2949b1a29a
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7611
diff
changeset
|
165 | """ |
ca2949b1a29a
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7611
diff
changeset
|
166 | if lineFlags: |
ca2949b1a29a
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7611
diff
changeset
|
167 | return "secok" in lineFlags |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
168 | |
7615
ca2949b1a29a
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7611
diff
changeset
|
169 | return False |
ca2949b1a29a
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7611
diff
changeset
|
170 | |
ca2949b1a29a
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7611
diff
changeset
|
171 | |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
172 | def codeStyleCheck(filename, source, args): |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
173 | """ |
6264
04a671fa4adb
code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6235
diff
changeset
|
174 | Do the code style check and/or fix found errors. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
175 | |
6264
04a671fa4adb
code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6235
diff
changeset
|
176 | @param filename source filename |
04a671fa4adb
code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6235
diff
changeset
|
177 | @type str |
04a671fa4adb
code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6235
diff
changeset
|
178 | @param source string containing the code to check |
04a671fa4adb
code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6235
diff
changeset
|
179 | @type str |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
180 | @param args arguments used by the codeStyleCheck function (list of |
6264
04a671fa4adb
code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6235
diff
changeset
|
181 | excludeMessages, includeMessages, repeatMessages, fixCodes, |
6786
701b511ba8f5
Added option to set the documentation line length.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
6645
diff
changeset
|
182 | noFixCodes, fixIssues, maxLineLength, maxDocLineLength, blankLines, |
8801
8fbb21be8579
Continued implementing a checker for import statements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8790
diff
changeset
|
183 | hangClosing, docType, codeComplexityArgs, miscellaneousArgs, |
8fbb21be8579
Continued implementing a checker for import statements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8790
diff
changeset
|
184 | annotationArgs, securityArgs, importsArgs, errors, eol, encoding, |
8fbb21be8579
Continued implementing a checker for import statements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8790
diff
changeset
|
185 | backup) |
6264
04a671fa4adb
code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6235
diff
changeset
|
186 | @type list of (str, str, bool, str, str, bool, int, list of (int, int), |
8801
8fbb21be8579
Continued implementing a checker for import statements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8790
diff
changeset
|
187 | bool, str, dict, dict, dict, dict, list of str, str, str, bool) |
6264
04a671fa4adb
code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6235
diff
changeset
|
188 | @return tuple of statistics (dict) and list of results (tuple for each |
04a671fa4adb
code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6235
diff
changeset
|
189 | found violation of style (lineno, position, text, ignored, fixed, |
04a671fa4adb
code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6235
diff
changeset
|
190 | autofixing, fixedMsg)) |
04a671fa4adb
code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6235
diff
changeset
|
191 | @rtype tuple of (dict, list of tuples of (int, int, str, bool, bool, bool, |
04a671fa4adb
code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6235
diff
changeset
|
192 | str)) |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
193 | """ |
4218
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
194 | return __checkCodeStyle(filename, source, args) |
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
195 | |
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
196 | |
5762
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5737
diff
changeset
|
197 | def codeStyleBatchCheck(argumentsList, send, fx, cancelled, maxProcesses=0): |
4218
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
198 | """ |
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
199 | Module function to check code style for a batch of files. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
200 | |
4218
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
201 | @param argumentsList list of arguments tuples as given for codeStyleCheck |
5762
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5737
diff
changeset
|
202 | @type list |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5737
diff
changeset
|
203 | @param send reference to send function |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5737
diff
changeset
|
204 | @type func |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5737
diff
changeset
|
205 | @param fx registered service name |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5737
diff
changeset
|
206 | @type str |
4221
c9fdc07753a7
Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4218
diff
changeset
|
207 | @param cancelled reference to function checking for a cancellation |
5762
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5737
diff
changeset
|
208 | @type func |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5737
diff
changeset
|
209 | @param maxProcesses number of processes to be used |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5737
diff
changeset
|
210 | @type int |
4218
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
211 | """ |
5762
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5737
diff
changeset
|
212 | if maxProcesses == 0: |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5737
diff
changeset
|
213 | # determine based on CPU count |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5737
diff
changeset
|
214 | try: |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5737
diff
changeset
|
215 | NumberOfProcesses = multiprocessing.cpu_count() |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5737
diff
changeset
|
216 | if NumberOfProcesses >= 1: |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5737
diff
changeset
|
217 | NumberOfProcesses -= 1 |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5737
diff
changeset
|
218 | except NotImplementedError: |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5737
diff
changeset
|
219 | NumberOfProcesses = 1 |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5737
diff
changeset
|
220 | else: |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5737
diff
changeset
|
221 | NumberOfProcesses = maxProcesses |
4218
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
222 | |
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
223 | # Create queues |
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
224 | taskQueue = multiprocessing.Queue() |
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
225 | doneQueue = multiprocessing.Queue() |
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
226 | |
4221
c9fdc07753a7
Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4218
diff
changeset
|
227 | # Submit tasks (initially two time number of processes |
c9fdc07753a7
Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4218
diff
changeset
|
228 | initialTasks = 2 * NumberOfProcesses |
9219
964a326c58d4
Did some code optimizations in the code style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
229 | for _ in range(initialTasks): |
964a326c58d4
Did some code optimizations in the code style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
230 | taskQueue.put(argumentsList.pop(0)) |
4218
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
231 | |
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
232 | # Start worker processes |
8650
100726f55a9a
Changed the 'multiprocessing.Process()' code of the background batch services to (hopefully) cure the slow down when used multiple times.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
233 | workers = [ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
234 | multiprocessing.Process(target=workerTask, args=(taskQueue, doneQueue)) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
235 | for _ in range(NumberOfProcesses) |
8650
100726f55a9a
Changed the 'multiprocessing.Process()' code of the background batch services to (hopefully) cure the slow down when used multiple times.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
236 | ] |
100726f55a9a
Changed the 'multiprocessing.Process()' code of the background batch services to (hopefully) cure the slow down when used multiple times.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
237 | for worker in workers: |
100726f55a9a
Changed the 'multiprocessing.Process()' code of the background batch services to (hopefully) cure the slow down when used multiple times.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
238 | worker.start() |
4218
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
239 | |
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
240 | # Get and send results |
4221
c9fdc07753a7
Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4218
diff
changeset
|
241 | endIndex = len(argumentsList) - initialTasks |
4218
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
242 | for i in range(len(argumentsList)): |
5672
495b53f37f6c
Corrected an issue in various checker services that caused them to block, if an exception was thrown in a checker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5661
diff
changeset
|
243 | resultSent = False |
495b53f37f6c
Corrected an issue in various checker services that caused them to block, if an exception was thrown in a checker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5661
diff
changeset
|
244 | wasCancelled = False |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
245 | |
5672
495b53f37f6c
Corrected an issue in various checker services that caused them to block, if an exception was thrown in a checker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5661
diff
changeset
|
246 | while not resultSent: |
495b53f37f6c
Corrected an issue in various checker services that caused them to block, if an exception was thrown in a checker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5661
diff
changeset
|
247 | try: |
495b53f37f6c
Corrected an issue in various checker services that caused them to block, if an exception was thrown in a checker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5661
diff
changeset
|
248 | # get result (waiting max. 3 seconds and send it to frontend |
495b53f37f6c
Corrected an issue in various checker services that caused them to block, if an exception was thrown in a checker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5661
diff
changeset
|
249 | filename, result = doneQueue.get(timeout=3) |
495b53f37f6c
Corrected an issue in various checker services that caused them to block, if an exception was thrown in a checker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5661
diff
changeset
|
250 | send(fx, filename, result) |
495b53f37f6c
Corrected an issue in various checker services that caused them to block, if an exception was thrown in a checker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5661
diff
changeset
|
251 | resultSent = True |
495b53f37f6c
Corrected an issue in various checker services that caused them to block, if an exception was thrown in a checker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5661
diff
changeset
|
252 | except queue.Empty: |
495b53f37f6c
Corrected an issue in various checker services that caused them to block, if an exception was thrown in a checker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5661
diff
changeset
|
253 | # ignore empty queue, just carry on |
495b53f37f6c
Corrected an issue in various checker services that caused them to block, if an exception was thrown in a checker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5661
diff
changeset
|
254 | if cancelled(): |
495b53f37f6c
Corrected an issue in various checker services that caused them to block, if an exception was thrown in a checker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5661
diff
changeset
|
255 | wasCancelled = True |
495b53f37f6c
Corrected an issue in various checker services that caused them to block, if an exception was thrown in a checker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5661
diff
changeset
|
256 | break |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
257 | |
5672
495b53f37f6c
Corrected an issue in various checker services that caused them to block, if an exception was thrown in a checker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5661
diff
changeset
|
258 | if wasCancelled or cancelled(): |
4221
c9fdc07753a7
Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4218
diff
changeset
|
259 | # just exit the loop ignoring the results of queued tasks |
c9fdc07753a7
Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4218
diff
changeset
|
260 | break |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
261 | |
4221
c9fdc07753a7
Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4218
diff
changeset
|
262 | if i < endIndex: |
9219
964a326c58d4
Did some code optimizations in the code style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
263 | taskQueue.put(argumentsList.pop(0)) |
4218
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
264 | |
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
265 | # Tell child processes to stop |
6188
5a6ae3be31e6
Fixed some loop related coding issues detected by the extended code style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
266 | for _ in range(NumberOfProcesses): |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
267 | taskQueue.put("STOP") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
268 | |
8650
100726f55a9a
Changed the 'multiprocessing.Process()' code of the background batch services to (hopefully) cure the slow down when used multiple times.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
269 | for worker in workers: |
100726f55a9a
Changed the 'multiprocessing.Process()' code of the background batch services to (hopefully) cure the slow down when used multiple times.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
270 | worker.join() |
100726f55a9a
Changed the 'multiprocessing.Process()' code of the background batch services to (hopefully) cure the slow down when used multiple times.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
271 | worker.close() |
4218
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
272 | |
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
273 | |
8650
100726f55a9a
Changed the 'multiprocessing.Process()' code of the background batch services to (hopefully) cure the slow down when used multiple times.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
274 | def workerTask(inputQueue, outputQueue): |
4218
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
275 | """ |
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
276 | Module function acting as the parallel worker for the style check. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
277 | |
5588
6ba512d9f46a
Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5586
diff
changeset
|
278 | @param inputQueue input queue (multiprocessing.Queue) |
6ba512d9f46a
Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5586
diff
changeset
|
279 | @param outputQueue output queue (multiprocessing.Queue) |
4218
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
280 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
281 | for filename, source, args in iter(inputQueue.get, "STOP"): |
4218
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
282 | result = __checkCodeStyle(filename, source, args) |
5588
6ba512d9f46a
Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5586
diff
changeset
|
283 | outputQueue.put((filename, result)) |
4218
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
284 | |
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
285 | |
7619
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
286 | def __checkSyntax(filename, source): |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
287 | """ |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
288 | Private module function to perform a syntax check. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
289 | |
7619
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
290 | @param filename source filename |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
291 | @type str |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
292 | @param source string containing the code to check |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
293 | @type str |
8198
1c765dc90c21
Code Style Checker: changed code such, that the AST tree is built only once and passed to each checker module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8194
diff
changeset
|
294 | @return tuple containing the error dictionary with syntax error details, |
1c765dc90c21
Code Style Checker: changed code such, that the AST tree is built only once and passed to each checker module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8194
diff
changeset
|
295 | a statistics dictionary and None or a tuple containing two None and |
1c765dc90c21
Code Style Checker: changed code such, that the AST tree is built only once and passed to each checker module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8194
diff
changeset
|
296 | the generated AST tree |
1c765dc90c21
Code Style Checker: changed code such, that the AST tree is built only once and passed to each checker module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8194
diff
changeset
|
297 | @rtype tuple of (dict, dict, None) or tuple of (None, None, ast.Module) |
7619
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
298 | """ |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
299 | src = "".join(source) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
300 | |
7619
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
301 | try: |
8259
2bbec88047dd
Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8244
diff
changeset
|
302 | tree = ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
303 | ast.parse(src, filename, "exec", type_comments=True) |
8243
cc717c2ae956
Applied some more code simplifications suggested by the new Simplify checker (Y105: use contextlib.suppress) (batch 2).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8218
diff
changeset
|
304 | # need the 'type_comments' parameter to include type annotations |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
305 | if sys.version_info >= (3, 8) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
306 | else ast.parse(src, filename, "exec") |
8259
2bbec88047dd
Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8244
diff
changeset
|
307 | ) |
8198
1c765dc90c21
Code Style Checker: changed code such, that the AST tree is built only once and passed to each checker module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8194
diff
changeset
|
308 | return None, None, tree |
7619
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
309 | except (SyntaxError, TypeError): |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
310 | exc_type, exc = sys.exc_info()[:2] |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
311 | if len(exc.args) > 1: |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
312 | offset = exc.args[1] |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
313 | if len(offset) > 2: |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
314 | offset = offset[1:3] |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
315 | else: |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
316 | offset = (1, 0) |
8205
4a0f1f896341
Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8198
diff
changeset
|
317 | return ( |
4a0f1f896341
Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8198
diff
changeset
|
318 | { |
4a0f1f896341
Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8198
diff
changeset
|
319 | "file": filename, |
4a0f1f896341
Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8198
diff
changeset
|
320 | "line": offset[0], |
4a0f1f896341
Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8198
diff
changeset
|
321 | "offset": offset[1], |
4a0f1f896341
Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8198
diff
changeset
|
322 | "code": "E901", |
4a0f1f896341
Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8198
diff
changeset
|
323 | "args": [exc_type.__name__, exc.args[0]], |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
324 | }, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
325 | { |
8205
4a0f1f896341
Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8198
diff
changeset
|
326 | "E901": 1, |
4a0f1f896341
Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8198
diff
changeset
|
327 | }, |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
328 | None, |
8205
4a0f1f896341
Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8198
diff
changeset
|
329 | ) |
7619
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
330 | |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
331 | |
4218
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
332 | def __checkCodeStyle(filename, source, args): |
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
333 | """ |
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
334 | Private module function to perform the code style check and/or fix |
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
335 | found errors. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
336 | |
6264
04a671fa4adb
code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6235
diff
changeset
|
337 | @param filename source filename |
04a671fa4adb
code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6235
diff
changeset
|
338 | @type str |
04a671fa4adb
code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6235
diff
changeset
|
339 | @param source string containing the code to check |
04a671fa4adb
code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6235
diff
changeset
|
340 | @type str |
4218
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
341 | @param args arguments used by the codeStyleCheck function (list of |
6264
04a671fa4adb
code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6235
diff
changeset
|
342 | excludeMessages, includeMessages, repeatMessages, fixCodes, |
6786
701b511ba8f5
Added option to set the documentation line length.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
6645
diff
changeset
|
343 | noFixCodes, fixIssues, maxLineLength, maxDocLineLength, blankLines, |
7247
bf9379f964f3
Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7246
diff
changeset
|
344 | hangClosing, docType, codeComplexityArgs, miscellaneousArgs, |
8801
8fbb21be8579
Continued implementing a checker for import statements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8790
diff
changeset
|
345 | annotationArgs, securityArgs, importsArgs, errors, eol, encoding, |
8fbb21be8579
Continued implementing a checker for import statements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8790
diff
changeset
|
346 | backup) |
6264
04a671fa4adb
code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6235
diff
changeset
|
347 | @type list of (str, str, bool, str, str, bool, int, list of (int, int), |
8801
8fbb21be8579
Continued implementing a checker for import statements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8790
diff
changeset
|
348 | bool, str, dict, dict, dict, dict, list of str, str, str, bool) |
7610
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
349 | @return tuple of statistics data and list of result dictionaries with |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
350 | keys: |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
351 | <ul> |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
352 | <li>file: file name</li> |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
353 | <li>line: line_number</li> |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
354 | <li>offset: offset within line</li> |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
355 | <li>code: message code</li> |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
356 | <li>args: list of arguments to format the message</li> |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
357 | <li>ignored: flag indicating this issue was ignored</li> |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
358 | <li>fixed: flag indicating this issue was fixed</li> |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
359 | <li>autofixing: flag indicating that a fix can be done</li> |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
360 | <li>fixcode: message code for the fix</li> |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
361 | <li>fixargs: list of arguments to format the fix message</li> |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
362 | </ul> |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
363 | @rtype tuple of (dict, list of dict) |
4218
f542ad1f76c5
Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
364 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
365 | ( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
366 | excludeMessages, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
367 | includeMessages, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
368 | repeatMessages, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
369 | fixCodes, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
370 | noFixCodes, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
371 | fixIssues, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
372 | maxLineLength, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
373 | maxDocLineLength, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
374 | blankLines, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
375 | hangClosing, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
376 | docType, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
377 | codeComplexityArgs, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
378 | miscellaneousArgs, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
379 | annotationArgs, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
380 | securityArgs, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
381 | importsArgs, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
382 | errors, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
383 | eol, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
384 | encoding, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
385 | backup, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
386 | ) = args |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
387 | |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
388 | stats = {} |
3616 | 389 | |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
390 | if fixIssues: |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
391 | from CodeStyleFixer import CodeStyleFixer |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
392 | |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
393 | fixer = CodeStyleFixer( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
394 | filename, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
395 | source, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
396 | fixCodes, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
397 | noFixCodes, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
398 | maxLineLength, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
399 | blankLines, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
400 | True, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
401 | eol, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
402 | backup, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
403 | ) |
6264
04a671fa4adb
code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6235
diff
changeset
|
404 | # always fix in place |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
405 | else: |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
406 | fixer = None |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
407 | |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
408 | if not errors: |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
409 | if includeMessages: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
410 | select = [s.strip() for s in includeMessages.split(",") if s.strip()] |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
411 | else: |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
412 | select = [] |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
413 | if excludeMessages: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
414 | ignore = [i.strip() for i in excludeMessages.split(",") if i.strip()] |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
415 | else: |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
416 | ignore = [] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
417 | |
8198
1c765dc90c21
Code Style Checker: changed code such, that the AST tree is built only once and passed to each checker module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8194
diff
changeset
|
418 | syntaxError, syntaxStats, tree = __checkSyntax(filename, source) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
419 | |
8198
1c765dc90c21
Code Style Checker: changed code such, that the AST tree is built only once and passed to each checker module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8194
diff
changeset
|
420 | # perform the checks only, if syntax is ok and AST tree was generated |
1c765dc90c21
Code Style Checker: changed code such, that the AST tree is built only once and passed to each checker module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8194
diff
changeset
|
421 | if tree: |
7619
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
422 | # check coding style |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
423 | pycodestyle.BLANK_LINES_CONFIG = { |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
424 | # Top level class and function. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
425 | "top_level": blankLines[0], |
7619
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
426 | # Methods and nested class and function. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
427 | "method": blankLines[1], |
7619
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
428 | } |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
429 | styleGuide = pycodestyle.StyleGuide( |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
430 | reporter=CodeStyleCheckerReport, |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
431 | repeat=repeatMessages, |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
432 | select=select, |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
433 | ignore=ignore, |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
434 | max_line_length=maxLineLength, |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
435 | max_doc_length=maxDocLineLength, |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
436 | hang_closing=hangClosing, |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
437 | ) |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
438 | report = styleGuide.check_files([filename]) |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
439 | stats.update(report.counters) |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
440 | errors = report.errors |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
441 | |
7619
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
442 | # check documentation style |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
443 | docStyleChecker = DocStyleChecker( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
444 | source, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
445 | filename, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
446 | select, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
447 | ignore, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
448 | [], |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
449 | repeatMessages, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
450 | maxLineLength=maxDocLineLength, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
451 | docType=docType, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
452 | ) |
7619
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
453 | docStyleChecker.run() |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
454 | stats.update(docStyleChecker.counters) |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
455 | errors += docStyleChecker.errors |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
456 | |
7619
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
457 | # miscellaneous additional checks |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
458 | miscellaneousChecker = MiscellaneousChecker( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
459 | source, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
460 | filename, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
461 | tree, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
462 | select, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
463 | ignore, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
464 | [], |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
465 | repeatMessages, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
466 | miscellaneousArgs, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
467 | ) |
7619
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
468 | miscellaneousChecker.run() |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
469 | stats.update(miscellaneousChecker.counters) |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
470 | errors += miscellaneousChecker.errors |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
471 | |
7619
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
472 | # check code complexity |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
473 | complexityChecker = ComplexityChecker( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
474 | source, filename, tree, select, ignore, codeComplexityArgs |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
475 | ) |
7619
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
476 | complexityChecker.run() |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
477 | stats.update(complexityChecker.counters) |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
478 | errors += complexityChecker.errors |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
479 | |
7619
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
480 | # check function annotations |
8244
ed8cb108b27b
Code Style Checker: reworked the type annotations checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8243
diff
changeset
|
481 | if sys.version_info >= (3, 8, 0): |
ed8cb108b27b
Code Style Checker: reworked the type annotations checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8243
diff
changeset
|
482 | # annotations with type comments are supported from |
ed8cb108b27b
Code Style Checker: reworked the type annotations checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8243
diff
changeset
|
483 | # Python 3.8 on |
7782
976d3b19ba7f
Started refactoring the code style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7639
diff
changeset
|
484 | from Annotations.AnnotationsChecker import AnnotationsChecker |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
485 | |
7619
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
486 | annotationsChecker = AnnotationsChecker( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
487 | source, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
488 | filename, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
489 | tree, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
490 | select, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
491 | ignore, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
492 | [], |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
493 | repeatMessages, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
494 | annotationArgs, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
495 | ) |
7619
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
496 | annotationsChecker.run() |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
497 | stats.update(annotationsChecker.counters) |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
498 | errors += annotationsChecker.errors |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
499 | |
8186
655b658aa7ee
Code Style Checker
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8166
diff
changeset
|
500 | # check for security issues |
7619
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
501 | securityChecker = SecurityChecker( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
502 | source, filename, tree, select, ignore, [], repeatMessages, securityArgs |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
503 | ) |
7619
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
504 | securityChecker.run() |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
505 | stats.update(securityChecker.counters) |
ef2b5af23ce7
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7615
diff
changeset
|
506 | errors += securityChecker.errors |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
507 | |
8186
655b658aa7ee
Code Style Checker
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8166
diff
changeset
|
508 | # check for pathlib usage |
8166
bd5cd5858503
Code Style Checker
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
509 | pathlibChecker = PathlibChecker( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
510 | source, filename, tree, select, ignore, [], repeatMessages |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
511 | ) |
8166
bd5cd5858503
Code Style Checker
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
512 | pathlibChecker.run() |
bd5cd5858503
Code Style Checker
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
513 | stats.update(pathlibChecker.counters) |
bd5cd5858503
Code Style Checker
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
514 | errors += pathlibChecker.errors |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
515 | |
8186
655b658aa7ee
Code Style Checker
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8166
diff
changeset
|
516 | # check for code simplifications |
8194
b925628bf91f
Code Style Checker
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8186
diff
changeset
|
517 | simplifyChecker = SimplifyChecker( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
518 | source, filename, tree, select, ignore, [], repeatMessages |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
519 | ) |
8186
655b658aa7ee
Code Style Checker
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8166
diff
changeset
|
520 | simplifyChecker.run() |
655b658aa7ee
Code Style Checker
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8166
diff
changeset
|
521 | stats.update(simplifyChecker.counters) |
655b658aa7ee
Code Style Checker
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8166
diff
changeset
|
522 | errors += simplifyChecker.errors |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
523 | |
8790
548df4df8256
Continued implementing a checker for import statements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8650
diff
changeset
|
524 | # check import statements |
548df4df8256
Continued implementing a checker for import statements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8650
diff
changeset
|
525 | importsChecker = ImportsChecker( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
526 | source, filename, tree, select, ignore, [], repeatMessages, importsArgs |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
527 | ) |
8790
548df4df8256
Continued implementing a checker for import statements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8650
diff
changeset
|
528 | importsChecker.run() |
548df4df8256
Continued implementing a checker for import statements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8650
diff
changeset
|
529 | stats.update(importsChecker.counters) |
548df4df8256
Continued implementing a checker for import statements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8650
diff
changeset
|
530 | errors += importsChecker.errors |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
531 | |
8198
1c765dc90c21
Code Style Checker: changed code such, that the AST tree is built only once and passed to each checker module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8194
diff
changeset
|
532 | elif syntaxError: |
1c765dc90c21
Code Style Checker: changed code such, that the AST tree is built only once and passed to each checker module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8194
diff
changeset
|
533 | errors = [syntaxError] |
1c765dc90c21
Code Style Checker: changed code such, that the AST tree is built only once and passed to each checker module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8194
diff
changeset
|
534 | stats.update(syntaxStats) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
535 | |
4444
4867c8189b62
Multiple pep8 fixes in one line doesn't mix up syntax any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4423
diff
changeset
|
536 | errorsDict = {} |
7610
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
537 | for error in errors: |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
538 | if error["line"] > len(source): |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
539 | error["line"] = len(source) |
4444
4867c8189b62
Multiple pep8 fixes in one line doesn't mix up syntax any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4423
diff
changeset
|
540 | # inverse processing of messages and fixes |
7610
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
541 | errorLine = errorsDict.setdefault(error["line"], []) |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
542 | errorLine.append((error["offset"], error)) |
4444
4867c8189b62
Multiple pep8 fixes in one line doesn't mix up syntax any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4423
diff
changeset
|
543 | deferredFixes = {} |
4867c8189b62
Multiple pep8 fixes in one line doesn't mix up syntax any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4423
diff
changeset
|
544 | results = [] |
7610
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
545 | for lineno, errorsList in errorsDict.items(): |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
546 | errorsList.sort(key=lambda x: x[0], reverse=True) |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
547 | for _, error in errorsList: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
548 | error.update( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
549 | { |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
550 | "ignored": False, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
551 | "fixed": False, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
552 | "autofixing": False, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
553 | "fixcode": "", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
554 | "fixargs": [], |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
555 | "securityOk": False, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
556 | } |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
557 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
558 | |
4444
4867c8189b62
Multiple pep8 fixes in one line doesn't mix up syntax any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4423
diff
changeset
|
559 | if source: |
7610
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
560 | code = error["code"] |
5172
f35c7e0db572
Added capaibility to ignore warnings by code (use __IGNORE_WARNING_<code>__, e.g. __IGNORE_WARNING_M613__).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5147
diff
changeset
|
561 | lineFlags = extractLineFlags(source[lineno - 1].strip()) |
8243
cc717c2ae956
Applied some more code simplifications suggested by the new Simplify checker (Y105: use contextlib.suppress) (batch 2).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8218
diff
changeset
|
562 | with contextlib.suppress(IndexError): |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
563 | lineFlags += extractLineFlags( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
564 | source[lineno].strip(), flagsLine=True |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
565 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
566 | |
7615
ca2949b1a29a
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7611
diff
changeset
|
567 | if securityOk(code, lineFlags): |
ca2949b1a29a
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7611
diff
changeset
|
568 | error["securityOk"] = True |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
569 | |
7615
ca2949b1a29a
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7611
diff
changeset
|
570 | if ignoreCode(code, lineFlags): |
ca2949b1a29a
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7611
diff
changeset
|
571 | error["ignored"] = True |
ca2949b1a29a
Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7611
diff
changeset
|
572 | else: |
4444
4867c8189b62
Multiple pep8 fixes in one line doesn't mix up syntax any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4423
diff
changeset
|
573 | if fixer: |
7610
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
574 | res, fixcode, fixargs, id_ = fixer.fixIssue( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
575 | lineno, error["offset"], code |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
576 | ) |
4444
4867c8189b62
Multiple pep8 fixes in one line doesn't mix up syntax any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4423
diff
changeset
|
577 | if res == -1: |
7610
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
578 | deferredFixes[id_] = error |
4444
4867c8189b62
Multiple pep8 fixes in one line doesn't mix up syntax any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4423
diff
changeset
|
579 | else: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
580 | error.update( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
581 | { |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
582 | "fixed": res == 1, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
583 | "autofixing": True, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
584 | "fixcode": fixcode, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
585 | "fixargs": fixargs, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
586 | } |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
587 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
588 | |
7610
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
589 | results.append(error) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
590 | |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
591 | if fixer: |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
592 | deferredResults = fixer.finalize() |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
593 | for id_ in deferredResults: |
7610
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
594 | fixed, fixcode, fixargs = deferredResults[id_] |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
595 | error = deferredFixes[id_] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
596 | error.update( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
597 | { |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
598 | "ignored": False, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
599 | "fixed": fixed == 1, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
600 | "autofixing": True, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
601 | "fixcode": fixcode, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
602 | "fixargs": fixargs, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
603 | } |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
604 | ) |
3413
5e63f809732a
Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3228
diff
changeset
|
605 | |
7610
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
606 | saveError = fixer.saveFile(encoding) |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
607 | if saveError: |
df7025fe26a3
Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
608 | for error in results: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
609 | error.update( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
610 | { |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
611 | "fixcode": saveError[0], |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
612 | "fixargs": saveError[1], |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
613 | } |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9219
diff
changeset
|
614 | ) |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
615 | |
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset
|
616 | return stats, results |