36 |
36 |
37 def initService(): |
37 def initService(): |
38 """ |
38 """ |
39 Initialize the service and return the entry point. |
39 Initialize the service and return the entry point. |
40 |
40 |
41 @return the entry point for the background client (function) |
41 @return the entry point for the background client |
|
42 @rtype function |
42 """ |
43 """ |
43 return codeStyleCheck |
44 return codeStyleCheck |
44 |
45 |
45 |
46 |
46 def initBatchService(): |
47 def initBatchService(): |
47 """ |
48 """ |
48 Initialize the batch service and return the entry point. |
49 Initialize the batch service and return the entry point. |
49 |
50 |
50 @return the entry point for the background client (function) |
51 @return the entry point for the background client |
|
52 @rtype function |
51 """ |
53 """ |
52 return codeStyleBatchCheck |
54 return codeStyleBatchCheck |
53 |
55 |
54 |
56 |
55 class CodeStyleCheckerReport(pycodestyle.BaseReport): |
57 class CodeStyleCheckerReport(pycodestyle.BaseReport): |
59 |
61 |
60 def __init__(self, options): |
62 def __init__(self, options): |
61 """ |
63 """ |
62 Constructor |
64 Constructor |
63 |
65 |
64 @param options options for the report (optparse.Values) |
66 @param options options for the report |
|
67 @type optparse.Values |
65 """ |
68 """ |
66 super().__init__(options) |
69 super().__init__(options) |
67 |
70 |
68 self.__repeat = options.repeat |
71 self.__repeat = options.repeat |
69 self.errors = [] |
72 self.errors = [] |
70 |
73 |
71 def error_args(self, line_number, offset, errorCode, check, *args): |
74 def error_args(self, line_number, offset, errorCode, check, *args): |
72 """ |
75 """ |
73 Public method to collect the error messages. |
76 Public method to collect the error messages. |
74 |
77 |
75 @param line_number line number of the issue (integer) |
78 @param line_number line number of the issue |
76 @param offset position within line of the issue (integer) |
79 @type int |
77 @param errorCode error message code (string) |
80 @param offset position within line of the issue |
78 @param check reference to the checker function (function) |
81 @type int |
79 @param args arguments for the message (list) |
82 @param errorCode error message code |
80 @return error code (string) |
83 @type str |
|
84 @param check reference to the checker function |
|
85 @type function |
|
86 @param args arguments for the message |
|
87 @type list |
|
88 @return error code |
|
89 @rtype str |
81 """ |
90 """ |
82 errorCode = super().error_args(line_number, offset, errorCode, check, *args) |
91 errorCode = super().error_args(line_number, offset, errorCode, check, *args) |
83 if errorCode and (self.counters[errorCode] == 1 or self.__repeat): |
92 if errorCode and (self.counters[errorCode] == 1 or self.__repeat): |
84 self.errors.append( |
93 self.errors.append( |
85 { |
94 { |
96 def extractLineFlags(line, startComment="#", endComment="", flagsLine=False): |
105 def extractLineFlags(line, startComment="#", endComment="", flagsLine=False): |
97 """ |
106 """ |
98 Function to extract flags starting and ending with '__' from a line |
107 Function to extract flags starting and ending with '__' from a line |
99 comment. |
108 comment. |
100 |
109 |
101 @param line line to extract flags from (string) |
110 @param line line to extract flags from |
102 @param startComment string identifying the start of the comment (string) |
111 @type str |
103 @param endComment string identifying the end of a comment (string) |
112 @param startComment string identifying the start of the comment |
104 @param flagsLine flag indicating to check for a flags only line (bool) |
113 @type str |
105 @return list containing the extracted flags (list of strings) |
114 @param endComment string identifying the end of a comment |
|
115 @type str |
|
116 @param flagsLine flag indicating to check for a flags only line |
|
117 @type bool |
|
118 @return list containing the extracted flags |
|
119 @rtype list of str |
106 """ |
120 """ |
107 flags = [] |
121 flags = [] |
108 |
122 |
109 if not flagsLine or (flagsLine and line.strip().startswith(startComment)): |
123 if not flagsLine or (flagsLine and line.strip().startswith(startComment)): |
110 pos = line.rfind(startComment) |
124 pos = line.rfind(startComment) |
291 |
305 |
292 def workerTask(inputQueue, outputQueue): |
306 def workerTask(inputQueue, outputQueue): |
293 """ |
307 """ |
294 Module function acting as the parallel worker for the style check. |
308 Module function acting as the parallel worker for the style check. |
295 |
309 |
296 @param inputQueue input queue (multiprocessing.Queue) |
310 @param inputQueue input queue |
297 @param outputQueue output queue (multiprocessing.Queue) |
311 @type multiprocessing.Queue |
|
312 @param outputQueue output queue |
|
313 @type multiprocessing.Queue |
298 """ |
314 """ |
299 for filename, source, args in iter(inputQueue.get, "STOP"): |
315 for filename, source, args in iter(inputQueue.get, "STOP"): |
300 result = __checkCodeStyle(filename, source, args) |
316 result = __checkCodeStyle(filename, source, args) |
301 outputQueue.put((filename, result)) |
317 outputQueue.put((filename, result)) |
302 |
318 |