76 return flags |
86 return flags |
77 |
87 |
78 |
88 |
79 def syntaxAndPyflakesCheck(filename, codestring, checkFlakes=True, |
89 def syntaxAndPyflakesCheck(filename, codestring, checkFlakes=True, |
80 ignoreStarImportWarnings=False): |
90 ignoreStarImportWarnings=False): |
|
91 """ |
|
92 Function to compile one Python source file to Python bytecode |
|
93 and to perform a pyflakes check. |
|
94 |
|
95 @param filename source filename (string) |
|
96 @param codestring string containing the code to compile (string) |
|
97 @keyparam checkFlakes flag indicating to do a pyflakes check (boolean) |
|
98 @keyparam ignoreStarImportWarnings flag indicating to |
|
99 ignore 'star import' warnings (boolean) |
|
100 @return dictionary with the keys 'error' and 'warnings' which |
|
101 hold a list containing details about the error/ warnings |
|
102 (file name, line number, column, codestring (only at syntax |
|
103 errors), the message, a list with arguments for the message) |
|
104 """ |
|
105 return __syntaxAndPyflakesCheck(filename, codestring, checkFlakes, |
|
106 ignoreStarImportWarnings) |
|
107 |
|
108 |
|
109 def syntaxAndPyflakesBatchCheck(argumentsList, send, fx, cancelled): |
|
110 """ |
|
111 Module function to check syntax for a batch of files. |
|
112 |
|
113 @param argumentsList list of arguments tuples as given for |
|
114 syntaxAndPyflakesCheck |
|
115 @param send reference to send function (function) |
|
116 @param fx registered service name (string) |
|
117 @param cancelled reference to function checking for a cancellation |
|
118 (function) |
|
119 """ |
|
120 try: |
|
121 NumberOfProcesses = multiprocessing.cpu_count() |
|
122 if NumberOfProcesses >= 1: |
|
123 NumberOfProcesses -= 1 |
|
124 except NotImplementedError: |
|
125 NumberOfProcesses = 1 |
|
126 |
|
127 # Create queues |
|
128 taskQueue = multiprocessing.Queue() |
|
129 doneQueue = multiprocessing.Queue() |
|
130 |
|
131 # Submit tasks (initially two time number of processes |
|
132 initialTasks = 2 * NumberOfProcesses |
|
133 for task in argumentsList[:initialTasks]: |
|
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 endIndex = len(argumentsList) - initialTasks |
|
143 for i in range(len(argumentsList)): |
|
144 filename, result = doneQueue.get() |
|
145 send(fx, filename, result) |
|
146 if cancelled(): |
|
147 # just exit the loop ignoring the results of queued tasks |
|
148 break |
|
149 if i < endIndex: |
|
150 taskQueue.put(argumentsList[i + initialTasks]) |
|
151 |
|
152 # Tell child processes to stop |
|
153 for i in range(NumberOfProcesses): |
|
154 taskQueue.put('STOP') |
|
155 |
|
156 |
|
157 def worker(input, output): |
|
158 """ |
|
159 Module function acting as the parallel worker for the style check. |
|
160 |
|
161 @param input input queue (multiprocessing.Queue) |
|
162 @param output output queue (multiprocessing.Queue) |
|
163 """ |
|
164 for filename, args in iter(input.get, 'STOP'): |
|
165 source, checkFlakes, ignoreStarImportWarnings = args |
|
166 result = __syntaxAndPyflakesCheck(filename, source, checkFlakes, |
|
167 ignoreStarImportWarnings) |
|
168 output.put((filename, result)) |
|
169 |
|
170 |
|
171 def __syntaxAndPyflakesCheck(filename, codestring, checkFlakes=True, |
|
172 ignoreStarImportWarnings=False): |
81 """ |
173 """ |
82 Function to compile one Python source file to Python bytecode |
174 Function to compile one Python source file to Python bytecode |
83 and to perform a pyflakes check. |
175 and to perform a pyflakes check. |
84 |
176 |
85 @param filename source filename (string) |
177 @param filename source filename (string) |