Tue, 13 Mar 2018 14:54:46 +0100
Fixed some loop related coding issues detected by the extended code style checker.
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 | |
6048
82ad8ec9548c
Updated copyright for 2018.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5762
diff
changeset
|
3 | # Copyright (c) 2011 - 2018 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 | # |
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
|
5 | # pylint: disable=C0103 |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
6 | |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
7 | """ |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
8 | Module implementing the syntax check for Python 2/3. |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
9 | """ |
4543
2e6a880670e9
Fixed a few code style issues (forgotten future imports, copyrights,...).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4385
diff
changeset
|
10 | |
5683
66b11f5171e8
Fixed an issue causing eric to not start with Python2 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5672
diff
changeset
|
11 | try: # Only for Py2 |
66b11f5171e8
Fixed an issue causing eric to not start with Python2 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5672
diff
changeset
|
12 | import Queue as queue |
66b11f5171e8
Fixed an issue causing eric to not start with Python2 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5672
diff
changeset
|
13 | except ImportError: |
66b11f5171e8
Fixed an issue causing eric to not start with Python2 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5672
diff
changeset
|
14 | import queue |
66b11f5171e8
Fixed an issue causing eric to not start with Python2 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5672
diff
changeset
|
15 | |
3525
66f4b8646622
Reintegrated the js syntax checker and therefore improved the background service a little.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3515
diff
changeset
|
16 | import 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
|
17 | import re |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3065
diff
changeset
|
18 | import sys |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
19 | import traceback |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
20 | import multiprocessing |
5683
66b11f5171e8
Fixed an issue causing eric to not start with Python2 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5672
diff
changeset
|
21 | |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
22 | |
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
|
23 | try: |
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
|
24 | from pyflakes.checker import Checker |
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
|
25 | from pyflakes.messages import ImportStarUsed, ImportStarUsage |
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
|
26 | except ImportError: |
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
|
27 | pass |
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
|
28 | |
6107
78dabf542c6b
Extended the check for VCS conflict markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
29 | VcsConflictMarkerRegExpList = ( |
78dabf542c6b
Extended the check for VCS conflict markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
30 | re.compile( |
6109
041715a2f703
Another fix for the VCS conflict markers regexp.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6108
diff
changeset
|
31 | r"""^<<<<<<< .*?\|\|\|\|\|\|\| .*?=======.*?>>>>>>> .*?$""", |
6107
78dabf542c6b
Extended the check for VCS conflict markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
32 | re.MULTILINE | re.DOTALL |
78dabf542c6b
Extended the check for VCS conflict markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
33 | ), |
78dabf542c6b
Extended the check for VCS conflict markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
34 | re.compile( |
6109
041715a2f703
Another fix for the VCS conflict markers regexp.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6108
diff
changeset
|
35 | r"""^<<<<<<< .*?=======.*?>>>>>>> .*?$""", |
6107
78dabf542c6b
Extended the check for VCS conflict markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
36 | re.MULTILINE | re.DOTALL |
6109
041715a2f703
Another fix for the VCS conflict markers regexp.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6108
diff
changeset
|
37 | ), |
6107
78dabf542c6b
Extended the check for VCS conflict markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
38 | ) |
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
|
39 | |
6119
18fb5d765f3a
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6109
diff
changeset
|
40 | |
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
|
41 | 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
|
42 | """ |
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
|
43 | Initialize the service and return the entry point. |
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
|
44 | |
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
|
45 | @return the entry point for the background client (function) |
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
|
46 | """ |
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
|
47 | return syntaxAndPyflakesCheck |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
48 | |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
49 | |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
50 | def initBatchService(): |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
51 | """ |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
52 | Initialize the batch service and return the entry point. |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
53 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
54 | @return the entry point for the background client (function) |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
55 | """ |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
56 | return syntaxAndPyflakesBatchCheck |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
57 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
58 | |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
59 | def normalizeCode(codestring): |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
60 | """ |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
61 | Function to normalize the given code. |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
62 | |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
63 | @param codestring code to be normalized (string) |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
64 | @return normalized code (string) |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
65 | """ |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
66 | codestring = codestring.replace("\r\n", "\n").replace("\r", "\n") |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
67 | |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
68 | if codestring and codestring[-1] != '\n': |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
69 | codestring = codestring + '\n' |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
70 | |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
71 | # Check type for py2: if not str it's unicode |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
72 | if sys.version_info[0] == 2: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
73 | try: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
74 | codestring = codestring.encode('utf-8') |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3065
diff
changeset
|
75 | except UnicodeError: |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
76 | pass |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
77 | |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
78 | return codestring |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
79 | |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
80 | |
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
|
81 | 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
|
82 | """ |
3065
070b35dde35e
Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2571
diff
changeset
|
83 | 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
|
84 | comment. |
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 | |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
86 | @param line line to extract flags from (string) |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
87 | @keyparam startComment string identifying the start of the comment (string) |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
88 | @keyparam endComment string identifying the end of a comment (string) |
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
|
89 | @keyparam flagsLine flag indicating to check for a flags only line (bool) |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
90 | @return list containing the extracted flags (list of strings) |
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 | flags = [] |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
93 | |
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
|
94 | if not flagsLine or ( |
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
|
95 | flagsLine and line.strip().startswith(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
|
96 | 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
|
97 | if pos >= 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
|
98 | comment = line[pos + len(startComment):].strip() |
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
|
99 | 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
|
100 | 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
|
101 | 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
|
102 | comment = comment[:endPos] |
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
|
103 | flags = [f.strip() for f in comment.split() |
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 | if (f.startswith("__") and f.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
|
105 | 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
|
106 | |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
107 | |
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
|
108 | def syntaxAndPyflakesCheck(filename, codestring, checkFlakes=True, |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3065
diff
changeset
|
109 | ignoreStarImportWarnings=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
|
110 | """ |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
111 | 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
|
112 | and to perform a pyflakes check. |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
113 | |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3065
diff
changeset
|
114 | @param filename source filename (string) |
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
|
115 | @param codestring string containing the code to compile (string) |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
116 | @keyparam checkFlakes flag indicating to do a pyflakes check (boolean) |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
117 | @keyparam ignoreStarImportWarnings flag indicating to |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
118 | ignore 'star import' warnings (boolean) |
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
|
119 | @return dictionary with the keys 'error' and 'warnings' which |
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
|
120 | hold a list containing details about the error/ warnings |
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
|
121 | (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
|
122 | errors), the message, a list with arguments for the message) |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
123 | """ |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
124 | return __syntaxAndPyflakesCheck(filename, codestring, checkFlakes, |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
125 | ignoreStarImportWarnings) |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
126 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
127 | |
5762
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
128 | def syntaxAndPyflakesBatchCheck(argumentsList, send, fx, cancelled, |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
129 | maxProcesses=0): |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
130 | """ |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
131 | Module function to check syntax for a batch of files. |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
132 | |
4236
8d4e498a7af8
Fixed a few coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4231
diff
changeset
|
133 | @param argumentsList list of arguments tuples as given for |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
134 | syntaxAndPyflakesCheck |
5762
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
135 | @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
|
136 | @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
|
137 | @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
|
138 | @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
|
139 | @type str |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
140 | @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
|
141 | @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
|
142 | @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
|
143 | @type int |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
144 | """ |
5762
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
145 | 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
|
146 | # 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
|
147 | try: |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
148 | 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
|
149 | 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
|
150 | 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
|
151 | 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
|
152 | 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
|
153 | else: |
76ef5f340007
Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5683
diff
changeset
|
154 | NumberOfProcesses = maxProcesses |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
155 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
156 | # Create queues |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
157 | taskQueue = multiprocessing.Queue() |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
158 | doneQueue = multiprocessing.Queue() |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
159 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
160 | # Submit tasks (initially two time number of processes |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
161 | initialTasks = 2 * NumberOfProcesses |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
162 | for task in argumentsList[:initialTasks]: |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
163 | taskQueue.put(task) |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
164 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
165 | # Start worker processes |
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
|
166 | for _ in range(NumberOfProcesses): |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
167 | multiprocessing.Process(target=worker, args=(taskQueue, doneQueue))\ |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
168 | .start() |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
169 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
170 | # Get and send results |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
171 | endIndex = len(argumentsList) - initialTasks |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
172 | 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:
5616
diff
changeset
|
173 | 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
|
174 | wasCancelled = 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
|
175 | |
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
|
176 | 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
|
177 | 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
|
178 | # 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
|
179 | 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
|
180 | 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
|
181 | 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
|
182 | 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
|
183 | # 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
|
184 | 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
|
185 | 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
|
186 | break |
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
|
187 | |
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
|
188 | 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
|
189 | # 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
|
190 | break |
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
|
191 | |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
192 | if i < endIndex: |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
193 | taskQueue.put(argumentsList[i + initialTasks]) |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
194 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
195 | # 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
|
196 | for _ in range(NumberOfProcesses): |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
197 | taskQueue.put('STOP') |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
198 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
199 | |
5588
6ba512d9f46a
Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5586
diff
changeset
|
200 | def worker(inputQueue, outputQueue): |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
201 | """ |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
202 | Module function acting as the parallel worker for the style check. |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
203 | |
5588
6ba512d9f46a
Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5586
diff
changeset
|
204 | @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
|
205 | @param outputQueue output queue (multiprocessing.Queue) |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
206 | """ |
5588
6ba512d9f46a
Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5586
diff
changeset
|
207 | 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
|
208 | source, checkFlakes, ignoreStarImportWarnings = args |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
209 | result = __syntaxAndPyflakesCheck(filename, source, checkFlakes, |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
210 | ignoreStarImportWarnings) |
5588
6ba512d9f46a
Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5586
diff
changeset
|
211 | 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
|
212 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
213 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
214 | def __syntaxAndPyflakesCheck(filename, codestring, checkFlakes=True, |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
215 | ignoreStarImportWarnings=False): |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
216 | """ |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
217 | 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
|
218 | and to perform a pyflakes check. |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
219 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
220 | @param filename source filename (string) |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
221 | @param codestring string containing the code to compile (string) |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
222 | @keyparam checkFlakes flag indicating to do a pyflakes check (boolean) |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
223 | @keyparam ignoreStarImportWarnings flag indicating to |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
224 | ignore 'star import' warnings (boolean) |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
225 | @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
|
226 | 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
|
227 | (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
|
228 | errors), the message, a list with arguments for the message) |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
229 | """ |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
230 | try: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
231 | import builtins |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
232 | except ImportError: |
3515
1b8381afe38f
Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3456
diff
changeset
|
233 | import __builtin__ as builtins # __IGNORE_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
|
234 | |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
235 | try: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
236 | if sys.version_info[0] == 2: |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3065
diff
changeset
|
237 | file_enc = filename.encode(sys.getfilesystemencoding()) |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
238 | else: |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3065
diff
changeset
|
239 | file_enc = 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
|
240 | |
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
|
241 | # It also encode the code back to avoid 'Encoding declaration in |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3065
diff
changeset
|
242 | # unicode string' exception on Python2 |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
243 | codestring = normalizeCode(codestring) |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
244 | |
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
|
245 | # Check for VCS conflict markers |
6107
78dabf542c6b
Extended the check for VCS conflict markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
246 | for conflictMarkerRe in VcsConflictMarkerRegExpList: |
78dabf542c6b
Extended the check for VCS conflict markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
247 | conflict = conflictMarkerRe.search(codestring) |
78dabf542c6b
Extended the check for VCS conflict markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
248 | if conflict is not None: |
78dabf542c6b
Extended the check for VCS conflict markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
249 | start, i = conflict.span() |
78dabf542c6b
Extended the check for VCS conflict markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
250 | lineindex = 1 + codestring.count("\n", 0, start) |
78dabf542c6b
Extended the check for VCS conflict markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
251 | return [{'error': |
78dabf542c6b
Extended the check for VCS conflict markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
252 | (file_enc, lineindex, 0, "", |
78dabf542c6b
Extended the check for VCS conflict markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
253 | "VCS conflict marker found") |
78dabf542c6b
Extended the check for VCS conflict markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
254 | }] |
3630
e32c3cec5d7e
Added a TODO: in the syntax checker to check for common VCS conflict markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3544
diff
changeset
|
255 | |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3065
diff
changeset
|
256 | 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
|
257 | try: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
258 | import quixote.ptl_compile |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
259 | except ImportError: |
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
|
260 | return [{'error': (filename, 0, 0, '', |
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
|
261 | 'Quixote plugin not found.')}] |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
262 | template = quixote.ptl_compile.Template(codestring, file_enc) |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
263 | 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
|
264 | else: |
3525
66f4b8646622
Reintegrated the js syntax checker and therefore improved the background service a little.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3515
diff
changeset
|
265 | module = builtins.compile( |
66f4b8646622
Reintegrated the js syntax checker and therefore improved the background service a little.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3515
diff
changeset
|
266 | codestring, file_enc, '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
|
267 | 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
|
268 | 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
|
269 | code = "" |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
270 | error = "" |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
271 | lines = traceback.format_exception_only(SyntaxError, detail) |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3065
diff
changeset
|
272 | if sys.version_info[0] == 2: |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3065
diff
changeset
|
273 | lines = [x.decode(sys.getfilesystemencoding()) for x in lines] |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
274 | match = re.match('\s*File "(.+)", line (\d+)', |
4385
599681bf149a
Source files now executable even with unicodes in path or filename.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4236
diff
changeset
|
275 | lines[0].replace('<string>', 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
|
276 | 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
|
277 | fn, line = match.group(1, 2) |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
278 | if lines[1].startswith('SyntaxError:'): |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
279 | error = re.match('SyntaxError: (.+)', lines[1]).group(1) |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
280 | else: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
281 | code = re.match('(.+)', lines[1]).group(1) |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
282 | for seLine in lines[2:]: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
283 | if seLine.startswith('SyntaxError:'): |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
284 | error = re.match('SyntaxError: (.+)', seLine).group(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 | elif seLine.rstrip().endswith('^'): |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
286 | 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
|
287 | else: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
288 | 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
|
289 | 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
|
290 | error = detail.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
|
291 | 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
|
292 | 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
|
293 | try: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
294 | 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
|
295 | 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
|
296 | 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
|
297 | except AttributeError: |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3065
diff
changeset
|
298 | 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
|
299 | 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
|
300 | error = str(detail) |
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
|
301 | 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
|
302 | except Exception 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
|
303 | try: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
304 | 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
|
305 | 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
|
306 | error = detail.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
|
307 | return [{'error': (fn, line, 0, "", error)}] |
5616
adcffadf4962
Reworked some __IGNORE_WARNING__ comments to be more specific.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5588
diff
changeset
|
308 | except Exception: |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
309 | pass |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
310 | |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
311 | # pyflakes |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
312 | 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
|
313 | return [{}] |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
314 | |
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
|
315 | 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
|
316 | 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
|
317 | 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
|
318 | 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
|
319 | 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
|
320 | for warning in warnings.messages: |
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
|
321 | if ignoreStarImportWarnings and ( |
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
|
322 | isinstance(warning, ImportStarUsed) or |
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
|
323 | isinstance(warning, ImportStarUsage) |
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
|
324 | ): |
3065
070b35dde35e
Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2571
diff
changeset
|
325 | continue |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
326 | |
3177
5af61402d74d
Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3173
diff
changeset
|
327 | _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
|
328 | lineFlags = extractLineFlags(lines[lineno - 1].strip()) |
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
|
329 | try: |
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
|
330 | lineFlags += extractLineFlags(lines[lineno].strip(), |
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
|
331 | flagsLine=True) |
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
|
332 | except IndexError: |
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
|
333 | pass |
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
|
334 | if "__IGNORE_WARNING__" not in lineFlags: |
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
|
335 | 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
|
336 | except SyntaxError as err: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
337 | if err.text.strip(): |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
338 | msg = err.text.strip() |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
339 | else: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
340 | msg = 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
|
341 | results.append((filename, err.lineno, 0, "FLAKES_ERROR", msg, [])) |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
342 | |
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
|
343 | return [{'warnings': results}] |
4555
861e1741985c
Adjustments to future imports for Python 2 compatibility.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4543
diff
changeset
|
344 | |
861e1741985c
Adjustments to future imports for Python 2 compatibility.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4543
diff
changeset
|
345 | # |
861e1741985c
Adjustments to future imports for Python 2 compatibility.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4543
diff
changeset
|
346 | # eflag: noqa = M702 |