Fri, 01 Jan 2016 12:13:13 +0100
Updated copyright for 2016.
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 | |
4632
ca310db386ed
Updated copyright for 2016.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4557
diff
changeset
|
3 | # Copyright (c) 2011 - 2016 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 | """ |
4541
e8ddd9d76414
Fixed a few code style issues (forgotten future imports, copyrights,...).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4385
diff
changeset
|
10 | |
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
|
11 | 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
|
12 | import re |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3065
diff
changeset
|
13 | 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
|
14 | import traceback |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
15 | import multiprocessing |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
16 | |
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
|
17 | 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
|
18 | from pyflakes.checker import Checker |
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.messages import ImportStarUsed |
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
|
20 | 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
|
21 | 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
|
22 | |
4207
a0c8a7f9839c
Fixed syntax checker to correctly identify VCS conflict markers. The current method was too stupid.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
23 | VcsConflictMarkerRe = re.compile( |
a0c8a7f9839c
Fixed syntax checker to correctly identify VCS conflict markers. The current method was too stupid.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
24 | r"""^<<<<<<< .*?=======.*?>>>>>>> .*?$""", |
a0c8a7f9839c
Fixed syntax checker to correctly identify VCS conflict markers. The current method was too stupid.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
25 | re.MULTILINE | re.DOTALL) |
a0c8a7f9839c
Fixed syntax checker to correctly identify VCS conflict markers. The current method was too stupid.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
26 | |
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
|
27 | |
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 | 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
|
29 | """ |
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
|
30 | 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
|
31 | |
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 | @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
|
33 | """ |
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
|
34 | 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
|
35 | |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
36 | |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
37 | def initBatchService(): |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
38 | """ |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
39 | 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
|
40 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
41 | @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
|
42 | """ |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
43 | return syntaxAndPyflakesBatchCheck |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
44 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
45 | |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
46 | 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
|
47 | """ |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
48 | 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
|
49 | |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
50 | @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
|
51 | @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
|
52 | """ |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
53 | 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
|
54 | |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
55 | 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
|
56 | 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
|
57 | |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
58 | # 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
|
59 | 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
|
60 | try: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
61 | codestring = codestring.encode('utf-8') |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3065
diff
changeset
|
62 | 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
|
63 | pass |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
64 | |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
65 | 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
|
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 | |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
68 | def extractLineFlags(line, startComment="#", endComment=""): |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
69 | """ |
3065
070b35dde35e
Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2571
diff
changeset
|
70 | 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
|
71 | 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
|
72 | |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
73 | @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
|
74 | @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
|
75 | @keyparam endComment string identifying the end of a 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
|
76 | @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
|
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 | flags = [] |
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 | pos = line.rfind(startComment) |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
81 | if pos >= 0: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
82 | comment = line[pos + len(startComment):].strip() |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
83 | if endComment: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
84 | comment = comment.replace("endComment", "") |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
85 | flags = [f.strip() for f in comment.split() |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
86 | if (f.startswith("__") and f.endswith("__"))] |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
87 | 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
|
88 | |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
89 | |
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
|
90 | def syntaxAndPyflakesCheck(filename, codestring, checkFlakes=True, |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3065
diff
changeset
|
91 | 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
|
92 | """ |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
93 | 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
|
94 | 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
|
95 | |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3065
diff
changeset
|
96 | @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
|
97 | @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
|
98 | @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
|
99 | @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
|
100 | 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
|
101 | @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
|
102 | 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
|
103 | (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
|
104 | 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
|
105 | """ |
4231
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
106 | 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
|
107 | ignoreStarImportWarnings) |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
108 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
109 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
110 | def syntaxAndPyflakesBatchCheck(argumentsList, send, fx, cancelled): |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
111 | """ |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
112 | 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
|
113 | |
4236
8d4e498a7af8
Fixed a few coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4231
diff
changeset
|
114 | @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
|
115 | syntaxAndPyflakesCheck |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
116 | @param send reference to send function (function) |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
117 | @param fx registered service name (string) |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
118 | @param cancelled reference to function checking for a cancellation |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
119 | (function) |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
120 | """ |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
121 | try: |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
122 | NumberOfProcesses = multiprocessing.cpu_count() |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
123 | if NumberOfProcesses >= 1: |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
124 | NumberOfProcesses -= 1 |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
125 | except NotImplementedError: |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
126 | NumberOfProcesses = 1 |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
127 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
128 | # Create queues |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
129 | taskQueue = multiprocessing.Queue() |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
130 | doneQueue = multiprocessing.Queue() |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
131 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
132 | # 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
|
133 | initialTasks = 2 * NumberOfProcesses |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
134 | 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
|
135 | taskQueue.put(task) |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
136 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
137 | # Start worker processes |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
138 | for i in range(NumberOfProcesses): |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
139 | 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
|
140 | .start() |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
141 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
142 | # Get and send results |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
143 | endIndex = len(argumentsList) - initialTasks |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
144 | for i in range(len(argumentsList)): |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
145 | filename, result = doneQueue.get() |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
146 | send(fx, filename, result) |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
147 | if cancelled(): |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
148 | # 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
|
149 | break |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
150 | if i < endIndex: |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
151 | 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
|
152 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
153 | # Tell child processes to stop |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
154 | for i in range(NumberOfProcesses): |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
155 | taskQueue.put('STOP') |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
156 | |
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 | def worker(input, output): |
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 | 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
|
161 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
162 | @param input input queue (multiprocessing.Queue) |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
163 | @param output output queue (multiprocessing.Queue) |
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 | for filename, args in iter(input.get, 'STOP'): |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
166 | source, checkFlakes, ignoreStarImportWarnings = args |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
167 | 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
|
168 | ignoreStarImportWarnings) |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
169 | output.put((filename, result)) |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
170 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
171 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
172 | 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
|
173 | ignoreStarImportWarnings=False): |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
174 | """ |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
175 | 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
|
176 | 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
|
177 | |
0b38613388c9
Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4207
diff
changeset
|
178 | @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
|
179 | @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
|
180 | @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
|
181 | @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
|
182 | 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
|
183 | @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
|
184 | 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
|
185 | (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
|
186 | 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
|
187 | """ |
2571
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
188 | try: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
189 | 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
|
190 | except ImportError: |
3515
1b8381afe38f
Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3456
diff
changeset
|
191 | 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
|
192 | |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
193 | try: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
194 | if sys.version_info[0] == 2: |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3065
diff
changeset
|
195 | 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
|
196 | else: |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3065
diff
changeset
|
197 | 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
|
198 | |
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
|
199 | # 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
|
200 | # 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
|
201 | 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
|
202 | |
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
|
203 | # Check for VCS conflict markers |
4207
a0c8a7f9839c
Fixed syntax checker to correctly identify VCS conflict markers. The current method was too stupid.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
204 | conflict = VcsConflictMarkerRe.search(codestring) |
a0c8a7f9839c
Fixed syntax checker to correctly identify VCS conflict markers. The current method was too stupid.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
205 | if conflict is not None: |
a0c8a7f9839c
Fixed syntax checker to correctly identify VCS conflict markers. The current method was too stupid.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
206 | start, i = conflict.span() |
a0c8a7f9839c
Fixed syntax checker to correctly identify VCS conflict markers. The current method was too stupid.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
207 | lineindex = 1 + codestring.count("\n", 0, start) |
a0c8a7f9839c
Fixed syntax checker to correctly identify VCS conflict markers. The current method was too stupid.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
208 | return [{'error': |
a0c8a7f9839c
Fixed syntax checker to correctly identify VCS conflict markers. The current method was too stupid.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
209 | (file_enc, lineindex, 0, "", |
a0c8a7f9839c
Fixed syntax checker to correctly identify VCS conflict markers. The current method was too stupid.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
210 | "VCS conflict marker found") |
a0c8a7f9839c
Fixed syntax checker to correctly identify VCS conflict markers. The current method was too stupid.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
211 | }] |
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
|
212 | |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3065
diff
changeset
|
213 | 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
|
214 | try: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
215 | 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
|
216 | 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
|
217 | 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
|
218 | '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
|
219 | 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
|
220 | 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
|
221 | 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
|
222 | 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
|
223 | 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
|
224 | 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
|
225 | 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
|
226 | code = "" |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
227 | error = "" |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
228 | lines = traceback.format_exception_only(SyntaxError, detail) |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3065
diff
changeset
|
229 | if sys.version_info[0] == 2: |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3065
diff
changeset
|
230 | 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
|
231 | 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
|
232 | 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
|
233 | 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
|
234 | 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
|
235 | 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
|
236 | 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
|
237 | else: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
238 | 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
|
239 | 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
|
240 | 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
|
241 | 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
|
242 | 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
|
243 | 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
|
244 | else: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
245 | 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
|
246 | 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
|
247 | 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
|
248 | 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
|
249 | 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
|
250 | try: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
251 | 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
|
252 | 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
|
253 | 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
|
254 | except AttributeError: |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3065
diff
changeset
|
255 | 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
|
256 | 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
|
257 | 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
|
258 | 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
|
259 | 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
|
260 | try: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
261 | 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
|
262 | 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
|
263 | 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
|
264 | 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
|
265 | except: # this catchall is intentional |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
266 | pass |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
267 | |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
268 | # pyflakes |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
269 | 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
|
270 | 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
|
271 | |
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
|
272 | 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
|
273 | 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
|
274 | 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
|
275 | 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
|
276 | 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
|
277 | for warning in warnings.messages: |
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 ignoreStarImportWarnings and \ |
3065
070b35dde35e
Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2571
diff
changeset
|
279 | isinstance(warning, ImportStarUsed): |
070b35dde35e
Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2571
diff
changeset
|
280 | 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
|
281 | |
3177
5af61402d74d
Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3173
diff
changeset
|
282 | _fn, lineno, col, message, msg_args = warning.getMessageData() |
3065
070b35dde35e
Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2571
diff
changeset
|
283 | if "__IGNORE_WARNING__" not in extractLineFlags( |
070b35dde35e
Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2571
diff
changeset
|
284 | lines[lineno - 1].strip()): |
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
|
285 | 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
|
286 | 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
|
287 | 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
|
288 | 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
|
289 | else: |
e6bb19eb87ea
Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
290 | 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
|
291 | 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
|
292 | |
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
|
293 | return [{'warnings': results}] |
4557
893c9f26a178
Adjustments to future imports for Python 2 compatibility.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4541
diff
changeset
|
294 | |
893c9f26a178
Adjustments to future imports for Python 2 compatibility.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4541
diff
changeset
|
295 | # |
893c9f26a178
Adjustments to future imports for Python 2 compatibility.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4541
diff
changeset
|
296 | # eflag: noqa = M702 |