Thu, 08 Dec 2022 14:46:06 +0100
Added the "__IGNORE_FLAKES_WARNING__" flag to the syntax checker to suppress a pyflakes warning.
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
2 | |
8881
54e42bc2437a
Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8650
diff
changeset
|
3 | # Copyright (c) 2011 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
4 | # |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
5 | |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
6 | """ |
7639
422fd05e9c91
Removed some more Python2 related code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7637
diff
changeset
|
7 | Module implementing the syntax check for Python 3. |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
8 | """ |
4543
2e6a880670e9
Fixed a few code style issues (forgotten future imports, copyrights,...).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4385
diff
changeset
|
9 | |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9462
diff
changeset
|
10 | import ast |
9482
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
11 | import builtins |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9462
diff
changeset
|
12 | import contextlib |
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9462
diff
changeset
|
13 | import multiprocessing |
7637
c878e8255972
Removed some more Python2 related code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7635
diff
changeset
|
14 | import queue |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
15 | import re |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
16 | import traceback |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
17 | |
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:
8234
diff
changeset
|
18 | with contextlib.suppress(ImportError): |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3159
diff
changeset
|
19 | from pyflakes.checker import Checker |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9462
diff
changeset
|
20 | from pyflakes.messages import ImportStarUsage, ImportStarUsed |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3159
diff
changeset
|
21 | |
6107
78dabf542c6b
Extended the check for VCS conflict markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
22 | VcsConflictMarkerRegExpList = ( |
78dabf542c6b
Extended the check for VCS conflict markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
23 | re.compile( |
6109
041715a2f703
Another fix for the VCS conflict markers regexp.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6108
diff
changeset
|
24 | r"""^<<<<<<< .*?\|\|\|\|\|\|\| .*?=======.*?>>>>>>> .*?$""", |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
25 | re.MULTILINE | re.DOTALL, |
6107
78dabf542c6b
Extended the check for VCS conflict markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
26 | ), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
27 | re.compile(r"""^<<<<<<< .*?=======.*?>>>>>>> .*?$""", re.MULTILINE | re.DOTALL), |
6107
78dabf542c6b
Extended the check for VCS conflict markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
28 | ) |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3159
diff
changeset
|
29 | |
6119
18fb5d765f3a
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6109
diff
changeset
|
30 | |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3159
diff
changeset
|
31 | def initService(): |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3159
diff
changeset
|
32 | """ |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3159
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:
9209
diff
changeset
|
34 | |
9508
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
35 | @return the entry point for the background client |
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
36 | @rtype function |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3159
diff
changeset
|
37 | """ |
9508
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
38 | return pySyntaxAndPyflakesCheck |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
39 | |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
40 | |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
41 | def initBatchService(): |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
42 | """ |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
43 | 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:
9209
diff
changeset
|
44 | |
9508
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
45 | @return the entry point for the background client |
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
46 | @rtype function |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
47 | """ |
9508
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
48 | return pySyntaxAndPyflakesBatchCheck |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
49 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
50 | |
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
|
51 | def extractLineFlags(line, startComment="#", endComment="", flagsLine=False): |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
52 | """ |
3065
070b35dde35e
Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2571
diff
changeset
|
53 | Function to extract flags starting and ending with '__' from a line |
070b35dde35e
Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2571
diff
changeset
|
54 | comment. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
55 | |
9508
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
56 | @param line line to extract flags from |
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
57 | @type str |
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
58 | @param startComment string identifying the start of the comment |
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
59 | @type str |
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
60 | @param endComment string identifying the end of a comment |
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
61 | @type str |
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
62 | @param flagsLine flag indicating to check for a flags only line |
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
63 | @type bool |
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
64 | @return list containing the extracted flags |
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
65 | @rtype list of str |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
66 | """ |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
67 | flags = [] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
68 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
69 | 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
|
70 | 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
|
71 | if pos >= 0: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
72 | 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
|
73 | 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
|
74 | 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
|
75 | 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
|
76 | comment = comment[:endPos] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
77 | flags = [ |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
78 | f.strip() |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
79 | for f in comment.split() |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
80 | if (f.startswith("__") and f.endswith("__")) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
81 | ] |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
82 | flags += [ |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
83 | f.strip().lower() for f in comment.split() if f in ("noqa", "NOQA") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
84 | ] |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
85 | return flags |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
86 | |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
87 | |
9508
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
88 | def pySyntaxAndPyflakesCheck( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
89 | filename, codestring, checkFlakes=True, ignoreStarImportWarnings=False |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
90 | ): |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
91 | """ |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
92 | Function to compile one Python source file to Python bytecode |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
93 | and to perform a pyflakes check. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
94 | |
9508
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
95 | @param filename source filename |
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
96 | @type str |
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
97 | @param codestring string containing the code to compile |
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
98 | @type str |
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
99 | @param checkFlakes flag indicating to do a pyflakes check |
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
100 | @type bool |
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
101 | @param ignoreStarImportWarnings flag indicating to ignore 'star import' warnings |
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
102 | @type bool |
3412
9364dab2d472
Plug-in docu updated, now the return values of the syntax checker is a dictionary
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3228
diff
changeset
|
103 | @return dictionary with the keys 'error' and 'warnings' which |
9508
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
104 | hold a list containing details about the error/warnings |
3412
9364dab2d472
Plug-in docu updated, now the return values of the syntax checker is a dictionary
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3228
diff
changeset
|
105 | (file name, line number, column, codestring (only at syntax |
9364dab2d472
Plug-in docu updated, now the return values of the syntax checker is a dictionary
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3228
diff
changeset
|
106 | errors), the message, a list with arguments for the message) |
9508
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
107 | @rtype dict |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
108 | """ |
9508
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
109 | return __pySyntaxAndPyflakesCheck( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
110 | filename, codestring, checkFlakes, ignoreStarImportWarnings |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
111 | ) |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
112 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
113 | |
9508
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
114 | def pySyntaxAndPyflakesBatchCheck(argumentsList, send, fx, cancelled, maxProcesses=0): |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
115 | """ |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
116 | Module function to check syntax for a batch of files. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
117 | |
9508
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
118 | @param argumentsList list of arguments tuples as given for pySyntaxAndPyflakesCheck |
5762
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
119 | @type list |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
120 | @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:
5683
diff
changeset
|
121 | @type func |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
122 | @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:
5683
diff
changeset
|
123 | @type str |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
124 | @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:
5683
diff
changeset
|
125 | @type func |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
126 | @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:
5683
diff
changeset
|
127 | @type int |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
128 | """ |
5762
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
129 | if maxProcesses == 0: |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
130 | # 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:
5683
diff
changeset
|
131 | try: |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
132 | NumberOfProcesses = multiprocessing.cpu_count() |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
133 | if NumberOfProcesses >= 1: |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
134 | NumberOfProcesses -= 1 |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
135 | except NotImplementedError: |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
136 | NumberOfProcesses = 1 |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
137 | else: |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
138 | NumberOfProcesses = maxProcesses |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
139 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
140 | # Create queues |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
141 | taskQueue = multiprocessing.Queue() |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
142 | doneQueue = multiprocessing.Queue() |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
143 | |
9289
ba49c41e8f63
Did some optimizations in the multiprocessing code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9284
diff
changeset
|
144 | # Submit tasks (initially two times the number of processes) |
ba49c41e8f63
Did some optimizations in the multiprocessing code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9284
diff
changeset
|
145 | tasks = len(argumentsList) |
9292
a5c8a0213fe3
Fixed an issue in the multiprocessing usage causing a traceback when then number of tasks is smaller than the number of worker processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9289
diff
changeset
|
146 | initialTasks = min(2 * NumberOfProcesses, tasks) |
9289
ba49c41e8f63
Did some optimizations in the multiprocessing code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9284
diff
changeset
|
147 | for _ in range(initialTasks): |
ba49c41e8f63
Did some optimizations in the multiprocessing code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9284
diff
changeset
|
148 | taskQueue.put(argumentsList.pop(0)) |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
149 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
150 | # 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
|
151 | workers = [ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
152 | multiprocessing.Process(target=workerTask, args=(taskQueue, doneQueue)) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
153 | 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
|
154 | ] |
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
|
155 | 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
|
156 | worker.start() |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
157 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
158 | # Get and send results |
9289
ba49c41e8f63
Did some optimizations in the multiprocessing code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9284
diff
changeset
|
159 | for _ in range(tasks): |
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:
5616
diff
changeset
|
160 | 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:
5616
diff
changeset
|
161 | wasCancelled = False |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
162 | |
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:
5616
diff
changeset
|
163 | 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:
5616
diff
changeset
|
164 | 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:
5616
diff
changeset
|
165 | # 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:
5616
diff
changeset
|
166 | filename, result = doneQueue.get() |
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:
5616
diff
changeset
|
167 | 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:
5616
diff
changeset
|
168 | 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:
5616
diff
changeset
|
169 | 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:
5616
diff
changeset
|
170 | # 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:
5616
diff
changeset
|
171 | 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:
5616
diff
changeset
|
172 | 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:
5616
diff
changeset
|
173 | break |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
174 | |
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:
5616
diff
changeset
|
175 | if wasCancelled or cancelled(): |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
176 | # just exit the loop ignoring the results of queued tasks |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
177 | break |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
178 | |
9289
ba49c41e8f63
Did some optimizations in the multiprocessing code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9284
diff
changeset
|
179 | if argumentsList: |
ba49c41e8f63
Did some optimizations in the multiprocessing code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9284
diff
changeset
|
180 | taskQueue.put(argumentsList.pop(0)) |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
181 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
182 | # 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:
6119
diff
changeset
|
183 | for _ in range(NumberOfProcesses): |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
184 | taskQueue.put("STOP") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
185 | |
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
|
186 | 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
|
187 | 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
|
188 | worker.close() |
9284
3b3a4f659782
"Blacked" the sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9279
diff
changeset
|
189 | |
9279
e252f827aaa7
Added code to explicitly close the queues to/from the workers at the end of a batch check.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
190 | taskQueue.close() |
e252f827aaa7
Added code to explicitly close the queues to/from the workers at the end of a batch check.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
191 | doneQueue.close() |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
192 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
193 | |
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
|
194 | def workerTask(inputQueue, outputQueue): |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
195 | """ |
7335
07ed3d73bf58
Syntax Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7256
diff
changeset
|
196 | Module function acting as the parallel worker for the syntax check. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
197 | |
9508
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
198 | @param inputQueue input queue |
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
199 | @type multiprocessing.Queue |
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
200 | @param outputQueue output queue |
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
201 | @type multiprocessing.Queue |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
202 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
203 | for filename, args in iter(inputQueue.get, "STOP"): |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
204 | source, checkFlakes, ignoreStarImportWarnings = args |
9508
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
205 | result = __pySyntaxAndPyflakesCheck( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
206 | filename, source, checkFlakes, ignoreStarImportWarnings |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
207 | ) |
5588
6ba512d9f46a
Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5586
diff
changeset
|
208 | outputQueue.put((filename, result)) |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
209 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
210 | |
9508
5a02bdb1dcba
Harmonized the naming of some code in the syntax checker plugin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9507
diff
changeset
|
211 | def __pySyntaxAndPyflakesCheck( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
212 | filename, codestring, checkFlakes=True, ignoreStarImportWarnings=False |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
213 | ): |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
214 | """ |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
215 | Function to compile one Python source file to Python bytecode |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
216 | and to perform a pyflakes check. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
217 | |
8205
4a0f1f896341
Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
218 | @param filename source filename |
4a0f1f896341
Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
219 | @type str |
4a0f1f896341
Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
220 | @param codestring string containing the code to compile |
4a0f1f896341
Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
221 | @type str |
4a0f1f896341
Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
222 | @param checkFlakes flag indicating to do a pyflakes check |
4a0f1f896341
Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
223 | @type bool |
7900
72b88fb20261
Corrected the use of '@keyparam' in the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7639
diff
changeset
|
224 | @param ignoreStarImportWarnings flag indicating to |
8205
4a0f1f896341
Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
225 | ignore 'star import' warnings |
4a0f1f896341
Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
226 | @type bool |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
227 | @return dictionary with the keys 'error' and 'warnings' which |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
228 | hold a list containing details about the error/ warnings |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
229 | (file name, line number, column, codestring (only at syntax |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
230 | errors), the message, a list with arguments for the message) |
8205
4a0f1f896341
Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
231 | @rtype dict |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
232 | """ |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
233 | try: |
3635
fc024806236d
Extended the syntax checker to check for VCS conflict markers left over from failed merges.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3630
diff
changeset
|
234 | # Check for VCS conflict markers |
6107
78dabf542c6b
Extended the check for VCS conflict markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
235 | for conflictMarkerRe in VcsConflictMarkerRegExpList: |
78dabf542c6b
Extended the check for VCS conflict markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
236 | conflict = conflictMarkerRe.search(codestring) |
78dabf542c6b
Extended the check for VCS conflict markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
237 | if conflict is not None: |
78dabf542c6b
Extended the check for VCS conflict markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
238 | start, i = conflict.span() |
78dabf542c6b
Extended the check for VCS conflict markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
239 | lineindex = 1 + codestring.count("\n", 0, start) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
240 | return [ |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
241 | {"error": (filename, lineindex, 0, "", "VCS conflict marker found")} |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
242 | ] |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
243 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
244 | if filename.endswith(".ptl"): |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
245 | try: |
9482
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
246 | import quixote.ptl_compile # __IGNORE_WARNING_I10__ |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
247 | except ImportError: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
248 | return [{"error": (filename, 0, 0, "", "Quixote plugin not found.")}] |
7637
c878e8255972
Removed some more Python2 related code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7635
diff
changeset
|
249 | template = quixote.ptl_compile.Template(codestring, filename) |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
250 | template.compile() |
3412
9364dab2d472
Plug-in docu updated, now the return values of the syntax checker is a dictionary
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3228
diff
changeset
|
251 | else: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
252 | module = builtins.compile(codestring, filename, "exec", ast.PyCF_ONLY_AST) |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
253 | except SyntaxError as detail: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
254 | index = 0 |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
255 | code = "" |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
256 | error = "" |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
257 | lines = traceback.format_exception_only(SyntaxError, detail) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
258 | match = re.match( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
259 | r'\s*File "(.+)", line (\d+)', lines[0].replace("<string>", filename) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
260 | ) |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
261 | if match is not None: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
262 | fn, line = match.group(1, 2) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
263 | if lines[1].startswith("SyntaxError:"): |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
264 | error = re.match("SyntaxError: (.+)", lines[1]).group(1) |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
265 | else: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
266 | code = re.match("(.+)", lines[1]).group(1) |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
267 | for seLine in lines[2:]: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
268 | if seLine.startswith("SyntaxError:"): |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
269 | error = re.match("SyntaxError: (.+)", seLine).group(1) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
270 | elif seLine.rstrip().endswith("^"): |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
271 | index = len(seLine.rstrip()) - 4 |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
272 | else: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
273 | fn = detail.filename |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
274 | line = detail.lineno or 1 |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
275 | error = detail.msg |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
276 | return [{"error": (fn, int(line), index, code.strip(), error)}] |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
277 | except ValueError as detail: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
278 | try: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
279 | fn = detail.filename |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
280 | line = detail.lineno |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
281 | error = detail.msg |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
282 | except AttributeError: |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3065
diff
changeset
|
283 | fn = filename |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
284 | line = 1 |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
285 | error = str(detail) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
286 | return [{"error": (fn, line, 0, "", error)}] |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
287 | except Exception as detail: |
9462
e65379fdbd97
Changed code to resolve or acknowledge some potential security issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9292
diff
changeset
|
288 | with contextlib.suppress(AttributeError): |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
289 | fn = detail.filename |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
290 | line = detail.lineno |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
291 | error = detail.msg |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
292 | return [{"error": (fn, line, 0, "", error)}] |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
293 | |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
294 | # pyflakes |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
295 | if not checkFlakes: |
3412
9364dab2d472
Plug-in docu updated, now the return values of the syntax checker is a dictionary
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3228
diff
changeset
|
296 | return [{}] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
297 | |
3412
9364dab2d472
Plug-in docu updated, now the return values of the syntax checker is a dictionary
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3228
diff
changeset
|
298 | results = [] |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
299 | lines = codestring.splitlines() |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
300 | try: |
3544
431c842fd09a
updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3525
diff
changeset
|
301 | warnings = Checker(module, filename, withDoctest=True) |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
302 | warnings.messages.sort(key=lambda a: a.lineno) |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
303 | for warning in warnings.messages: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
304 | if ignoreStarImportWarnings and isinstance( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
305 | warning, (ImportStarUsed, ImportStarUsage) |
5363
cbe61c2f9772
Extended the code of the flakes checker plug-in to really ignore the * imports warnings, if configured that way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
306 | ): |
3065
070b35dde35e
Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2571
diff
changeset
|
307 | continue |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
308 | |
3177
5af61402d74d
Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3173
diff
changeset
|
309 | _fn, lineno, col, message, msg_args = warning.getMessageData() |
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
|
310 | lineFlags = extractLineFlags(lines[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:
8234
diff
changeset
|
311 | with contextlib.suppress(IndexError): |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
312 | lineFlags += extractLineFlags(lines[lineno].strip(), flagsLine=True) |
9591
3c56c81a70be
Added the "__IGNORE_FLAKES_WARNING__" flag to the syntax checker to suppress a pyflakes warning.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9508
diff
changeset
|
313 | if ( |
3c56c81a70be
Added the "__IGNORE_FLAKES_WARNING__" flag to the syntax checker to suppress a pyflakes warning.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9508
diff
changeset
|
314 | "__IGNORE_WARNING__" not in lineFlags |
3c56c81a70be
Added the "__IGNORE_FLAKES_WARNING__" flag to the syntax checker to suppress a pyflakes warning.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9508
diff
changeset
|
315 | and "__IGNORE_FLAKES_WARNING__" not in lineFlags |
3c56c81a70be
Added the "__IGNORE_FLAKES_WARNING__" flag to the syntax checker to suppress a pyflakes warning.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9508
diff
changeset
|
316 | and "noqa" not in lineFlags |
3c56c81a70be
Added the "__IGNORE_FLAKES_WARNING__" flag to the syntax checker to suppress a pyflakes warning.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9508
diff
changeset
|
317 | ): |
3412
9364dab2d472
Plug-in docu updated, now the return values of the syntax checker is a dictionary
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3228
diff
changeset
|
318 | results.append((_fn, lineno, col, "", message, msg_args)) |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
319 | except SyntaxError as err: |
8234
fcb6b4b96274
Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator) (batch 2).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8217
diff
changeset
|
320 | msg = err.text.strip() if err.text.strip() else err.msg |
3412
9364dab2d472
Plug-in docu updated, now the return values of the syntax checker is a dictionary
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3228
diff
changeset
|
321 | results.append((filename, err.lineno, 0, "FLAKES_ERROR", msg, [])) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
322 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
323 | return [{"warnings": results}] |