85 |
95 |
86 |
96 |
87 def codeStyleCheck(filename, source, args): |
97 def codeStyleCheck(filename, source, args): |
88 """ |
98 """ |
89 Do the code style check and/ or fix found errors. |
99 Do the code style check and/ or fix found errors. |
|
100 |
|
101 @param filename source filename (string) |
|
102 @param source string containing the code to check (string) |
|
103 @param args arguments used by the codeStyleCheck function (list of |
|
104 excludeMessages (str), includeMessages (str), repeatMessages |
|
105 (bool), fixCodes (str), noFixCodes (str), fixIssues (bool), |
|
106 maxLineLength (int), hangClosing (bool), docType (str), errors |
|
107 (list of str), eol (str), encoding (str), backup (bool)) |
|
108 @return tuple of stats (dict) and results (tuple for each found violation |
|
109 of style (tuple of lineno (int), position (int), text (str), ignored |
|
110 (bool), fixed (bool), autofixing (bool), fixedMsg (str))) |
|
111 """ |
|
112 return __checkCodeStyle(filename, source, args) |
|
113 |
|
114 |
|
115 def codeStyleBatchCheck(argumentsList, send, fx): |
|
116 """ |
|
117 Module function to check code style for a batch of files. |
|
118 |
|
119 @param argumentsList list of arguments tuples as given for codeStyleCheck |
|
120 @param send reference to send method |
|
121 @param fx registered service name (string) |
|
122 """ |
|
123 try: |
|
124 NumberOfProcesses = multiprocessing.cpu_count() |
|
125 except NotImplementedError: |
|
126 NumberOfProcesses = 4 |
|
127 |
|
128 # Create queues |
|
129 taskQueue = multiprocessing.Queue() |
|
130 doneQueue = multiprocessing.Queue() |
|
131 |
|
132 # Submit tasks |
|
133 for task in argumentsList: |
|
134 taskQueue.put(task) |
|
135 |
|
136 # Start worker processes |
|
137 for i in range(NumberOfProcesses): |
|
138 multiprocessing.Process(target=worker, args=(taskQueue, doneQueue))\ |
|
139 .start() |
|
140 |
|
141 # Get and send results |
|
142 for i in range(len(argumentsList)): |
|
143 filename, result = doneQueue.get() |
|
144 send(fx, filename, result) |
|
145 |
|
146 # Tell child processes to stop |
|
147 for i in range(NumberOfProcesses): |
|
148 taskQueue.put('STOP') |
|
149 |
|
150 |
|
151 def worker(input, output): |
|
152 """ |
|
153 Module function acting as the parallel worker for the style check. |
|
154 |
|
155 @param input input queue (multiprocessing.Queue) |
|
156 @param output output queue (multiprocessing.Queue) |
|
157 """ |
|
158 for filename, source, args in iter(input.get, 'STOP'): |
|
159 result = __checkCodeStyle(filename, source, args) |
|
160 output.put((filename, result)) |
|
161 |
|
162 |
|
163 def __checkCodeStyle(filename, source, args): |
|
164 """ |
|
165 Private module function to perform the code style check and/or fix |
|
166 found errors. |
90 |
167 |
91 @param filename source filename (string) |
168 @param filename source filename (string) |
92 @param source string containing the code to check (string) |
169 @param source string containing the code to check (string) |
93 @param args arguments used by the codeStyleCheck function (list of |
170 @param args arguments used by the codeStyleCheck function (list of |
94 excludeMessages (str), includeMessages (str), repeatMessages |
171 excludeMessages (str), includeMessages (str), repeatMessages |