Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheck.py

Fri, 31 Mar 2017 17:29:55 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 31 Mar 2017 17:29:55 +0200
changeset 5672
495b53f37f6c
parent 5616
adcffadf4962
child 5683
66b11f5171e8
permissions
-rw-r--r--

Corrected an issue in various checker services that caused them to block, if an exception was thrown in a checker class.

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
5389
9b1c800daff3 Updated copyright for 2017.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5363
diff changeset
3 # Copyright (c) 2011 - 2017 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
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
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
16 import queue
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
17
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
18 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
19 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
20 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
21 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
22 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
23
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
24 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
25 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
26 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
27
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
28
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 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
30 """
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 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
32
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
33 @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
34 """
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
35 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
36
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
37
4231
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
38 def initBatchService():
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
39 """
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
40 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
41
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
42 @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
43 """
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
44 return syntaxAndPyflakesBatchCheck
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
45
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
46
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
47 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
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 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
50
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
51 @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
52 @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
53 """
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
54 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
55
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
56 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
57 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
58
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
59 # 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
60 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
61 try:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
62 codestring = codestring.encode('utf-8')
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3065
diff changeset
63 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
64 pass
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 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
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
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
69 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
70 """
3065
070b35dde35e Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2571
diff changeset
71 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
72 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
73
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
74 @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
75 @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
76 @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
77 @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
78 @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
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 flags = []
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
81
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
82 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
83 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
84 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
85 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
86 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
87 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
88 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
89 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
90 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
91 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
92 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
93 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
94
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
95
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
96 def syntaxAndPyflakesCheck(filename, codestring, checkFlakes=True,
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3065
diff changeset
97 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
98 """
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
99 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
100 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
101
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3065
diff changeset
102 @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
103 @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
104 @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
105 @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
106 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
107 @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
108 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
109 (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
110 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
111 """
4231
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
112 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
113 ignoreStarImportWarnings)
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
114
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
115
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
116 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
117 """
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
118 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
119
4236
8d4e498a7af8 Fixed a few coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4231
diff changeset
120 @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
121 syntaxAndPyflakesCheck
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
122 @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
123 @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
124 @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
125 (function)
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 try:
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
128 NumberOfProcesses = multiprocessing.cpu_count()
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
129 if NumberOfProcesses >= 1:
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
130 NumberOfProcesses -= 1
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
131 except NotImplementedError:
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
132 NumberOfProcesses = 1
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
133
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
134 # Create queues
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
135 taskQueue = multiprocessing.Queue()
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
136 doneQueue = multiprocessing.Queue()
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
137
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
138 # 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
139 initialTasks = 2 * NumberOfProcesses
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
140 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
141 taskQueue.put(task)
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
142
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
143 # Start worker processes
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(NumberOfProcesses):
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
145 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
146 .start()
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
147
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
148 # Get and send results
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
149 endIndex = len(argumentsList) - initialTasks
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
150 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
151 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
152 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
153
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
154 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
155 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
156 # 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
157 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
158 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
159 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
160 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
161 # 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
162 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
163 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
164 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
165
495b53f37f6c Corrected an issue in various checker services that caused them to block, if an exception was thrown in a checker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5616
diff changeset
166 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
167 # 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
168 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
169
4231
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
170 if i < endIndex:
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
171 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
172
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
173 # 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
174 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
175 taskQueue.put('STOP')
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
176
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
177
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5586
diff changeset
178 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
179 """
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
180 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
181
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5586
diff changeset
182 @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
183 @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
184 """
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5586
diff changeset
185 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
186 source, checkFlakes, ignoreStarImportWarnings = args
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
187 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
188 ignoreStarImportWarnings)
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5586
diff changeset
189 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
190
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
191
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
192 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
193 ignoreStarImportWarnings=False):
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 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
196 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
197
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4207
diff changeset
198 @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
199 @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
200 @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
201 @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
202 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
203 @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
204 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
205 (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
206 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
207 """
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
208 try:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
209 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
210 except ImportError:
3515
1b8381afe38f Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
211 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
212
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
213 try:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
214 if sys.version_info[0] == 2:
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3065
diff changeset
215 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
216 else:
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3065
diff changeset
217 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
218
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
219 # 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
220 # 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
221 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
222
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
223 # 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
224 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
225 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
226 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
227 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
228 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
229 (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
230 "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
231 }]
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
232
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3065
diff changeset
233 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
234 try:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
235 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
236 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
237 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
238 '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
239 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
240 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
241 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
242 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
243 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
244 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
245 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
246 code = ""
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 = ""
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
248 lines = traceback.format_exception_only(SyntaxError, detail)
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3065
diff changeset
249 if sys.version_info[0] == 2:
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3065
diff changeset
250 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
251 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
252 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
253 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
254 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
255 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
256 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
257 else:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
258 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
259 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
260 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
261 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
262 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
263 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
264 else:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
265 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
266 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
267 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
268 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
269 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
270 try:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
271 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
272 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
273 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
274 except AttributeError:
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3065
diff changeset
275 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
276 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
277 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
278 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
279 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
280 try:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
281 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
282 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
283 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
284 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
285 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
286 pass
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
287
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
288 # pyflakes
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
289 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
290 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
291
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
292 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
293 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
294 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
295 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
296 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
297 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
298 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
299 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
300 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
301 ):
3065
070b35dde35e Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2571
diff changeset
302 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
303
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3173
diff changeset
304 _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
305 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
306 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
307 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
308 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
309 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
310 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
311 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
312 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
313 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
314 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
315 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
316 else:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
317 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
318 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
319
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
320 return [{'warnings': results}]
4555
861e1741985c Adjustments to future imports for Python 2 compatibility.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4543
diff changeset
321
861e1741985c Adjustments to future imports for Python 2 compatibility.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4543
diff changeset
322 #
861e1741985c Adjustments to future imports for Python 2 compatibility.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4543
diff changeset
323 # eflag: noqa = M702

eric ide

mercurial