22 class Pep8Py2Checker(object): |
22 class Pep8Py2Checker(object): |
23 """ |
23 """ |
24 Class implementing the PEP 8 checker interface for Python 2. |
24 Class implementing the PEP 8 checker interface for Python 2. |
25 """ |
25 """ |
26 def __init__(self, filename, lines, repeat=False, |
26 def __init__(self, filename, lines, repeat=False, |
27 select="", ignore=""): |
27 select="", ignore="", max_line_length=79, |
|
28 hang_closing=False): |
28 """ |
29 """ |
29 Constructor |
30 Constructor |
30 |
31 |
31 @param filename name of the file to check (string) |
32 @param filename name of the file to check (string) |
32 @param lines source of the file (list of strings) (ignored) |
33 @param lines source of the file (list of strings) (ignored) |
33 @keyparam repeat flag indicating to repeat message categories (boolean) |
34 @keyparam repeat flag indicating to repeat message categories (boolean) |
34 @keyparam select list of message IDs to check for |
35 @keyparam select list of message IDs to check for |
35 (comma separated string) |
36 (comma separated string) |
36 @keyparam ignore list of message IDs to ignore |
37 @keyparam ignore list of message IDs to ignore |
37 (comma separated string) |
38 (comma separated string) |
|
39 @keyparam max_line_length maximum allowed line length (integer) |
|
40 @keyparam hang_closing flag indicating to allow hanging closing brackets (boolean) |
38 """ |
41 """ |
39 self.messages = [] |
42 self.errors = [] |
40 self.statistics = {} |
43 self.counters = {} |
41 |
44 |
42 interpreter = Preferences.getDebugger("PythonInterpreter") |
45 interpreter = Preferences.getDebugger("PythonInterpreter") |
43 if interpreter == "" or not Utilities.isExecutable(interpreter): |
46 if interpreter == "" or not Utilities.isExecutable(interpreter): |
44 self.messages.append((filename, 1, 1, |
47 self.errors.append((filename, 1, 1, |
45 QCoreApplication.translate("Pep8Py2Checker", |
48 QCoreApplication.translate("Pep8Py2Checker", |
46 "Python2 interpreter not configured."))) |
49 "Python2 interpreter not configured."))) |
47 return |
50 return |
48 |
51 |
49 checker = os.path.join(getConfig('ericDir'), |
52 checker = os.path.join(getConfig('ericDir'), |
69 output = \ |
76 output = \ |
70 str(proc.readAllStandardOutput(), |
77 str(proc.readAllStandardOutput(), |
71 Preferences.getSystem("IOEncoding"), |
78 Preferences.getSystem("IOEncoding"), |
72 'replace').splitlines() |
79 'replace').splitlines() |
73 if output[0] == "ERROR": |
80 if output[0] == "ERROR": |
74 self.messages.append((filename, 1, 1, output[2])) |
81 self.errors.append((filename, 1, 1, output[2])) |
75 return |
82 return |
76 |
83 |
77 if output[0] == "NO_PEP8": |
84 if output[0] == "NO_PEP8": |
78 return |
85 return |
79 |
86 |
94 args.append(output[index + 6 + argindex]) |
101 args.append(output[index + 6 + argindex]) |
95 argindex += 1 |
102 argindex += 1 |
96 index += 6 + arglen |
103 index += 6 + arglen |
97 |
104 |
98 text = pep8.getMessage(code, *args) |
105 text = pep8.getMessage(code, *args) |
99 self.messages.append((fname, lineno, position, text)) |
106 self.errors.append((fname, lineno, position, text)) |
100 while index < len(output): |
107 while index < len(output): |
101 code, countStr = output[index].split(None, 1) |
108 code, countStr = output[index].split(None, 1) |
102 self.statistics[code] = int(countStr) |
109 self.counters[code] = int(countStr) |
103 index += 1 |
110 index += 1 |
104 else: |
111 else: |
105 self.messages.append((filename, 1, 1, |
112 self.errors.append((filename, 1, 1, |
106 QCoreApplication.translate("Pep8Py2Checker", |
113 QCoreApplication.translate("Pep8Py2Checker", |
107 "Python2 interpreter did not finish within 15s."))) |
114 "Python2 interpreter did not finish within 15s."))) |