123 @param fn file or list of files or directory to be checked |
123 @param fn file or list of files or directory to be checked |
124 (string or list of strings) |
124 (string or list of strings) |
125 @param codestring string containing the code to be checked (string). |
125 @param codestring string containing the code to be checked (string). |
126 If this is given, file must be a single file name. |
126 If this is given, file must be a single file name. |
127 """ |
127 """ |
|
128 if self.__project is None: |
|
129 self.__project = e5App().getObject("Project") |
|
130 |
128 self.cancelled = False |
131 self.cancelled = False |
129 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) |
132 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) |
130 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True) |
133 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True) |
131 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) |
134 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) |
132 QApplication.processEvents() |
135 QApplication.processEvents() |
177 "Error: {0}".format(str(msg)).rstrip()[1:-1], "") |
180 "Error: {0}".format(str(msg)).rstrip()[1:-1], "") |
178 progress += 1 |
181 progress += 1 |
179 continue |
182 continue |
180 |
183 |
181 flags = Utilities.extractFlags(source) |
184 flags = Utilities.extractFlags(source) |
182 if ("FileType" in flags and flags["FileType"] != "Python3") or \ |
185 ext = os.path.splitext(file)[1] |
183 file in py2files: |
186 if ("FileType" in flags and |
|
187 flags["FileType"] in ["Python", "Python2"]) or \ |
|
188 file in py2files or \ |
|
189 (ext in [".py", ".pyw"] and \ |
|
190 Preferences.getProject("DeterminePyFromProject") and \ |
|
191 self.__project.isOpen() and \ |
|
192 self.__project.isProjectFile(file) and \ |
|
193 self.__project.getProjectLanguage() in ["Python", "Python2"]): |
184 isPy3 = False |
194 isPy3 = False |
185 nok, fname, line, code, error = Utilities.py2compile(file) |
195 nok, fname, line, code, error, warnings = \ |
|
196 Utilities.py2compile(file, |
|
197 checkFlakes = Preferences.getFlakes("IncludeInSyntaxCheck")) |
186 else: |
198 else: |
187 isPy3 = True |
199 isPy3 = True |
188 nok, fname, line, code, error = Utilities.compile(file, source) |
200 nok, fname, line, code, error = Utilities.compile(file, source) |
189 if nok: |
201 if nok: |
190 self.noResults = False |
202 self.noResults = False |
191 self.__createResultItem(fname, line, error, code) |
203 self.__createResultItem(fname, line, error, code) |
192 else: |
204 else: |
193 if Preferences.getFlakes("IncludeInSyntaxCheck") and isPy3: |
205 if Preferences.getFlakes("IncludeInSyntaxCheck"): |
194 try: |
206 if isPy3: |
195 sourceLines = source.splitlines() |
207 try: |
196 warnings = Checker(source, file) |
208 sourceLines = source.splitlines() |
197 warnings.messages.sort(key = lambda a: a.lineno) |
209 warnings = Checker(source, file) |
198 for warning in warnings.messages: |
210 warnings.messages.sort(key = lambda a: a.lineno) |
199 if ignoreStarImportWarnings and \ |
211 for warning in warnings.messages: |
200 isinstance(warning, ImportStarUsed): |
212 if ignoreStarImportWarnings and \ |
201 continue |
213 isinstance(warning, ImportStarUsed): |
202 fname, lineno, message = warning.getMessageData() |
214 continue |
203 if not sourceLines[lineno - 1].strip()\ |
215 fname, lineno, message = warning.getMessageData() |
204 .endswith("__IGNORE_WARNING__"): |
216 if not sourceLines[lineno - 1].strip()\ |
205 self.noResults = False |
217 .endswith("__IGNORE_WARNING__"): |
206 self.__createResultItem(fname, lineno, message, "", |
218 self.noResults = False |
207 isWarning = True) |
219 self.__createResultItem(fname, lineno, message, |
208 except SyntaxError as err: |
220 "", isWarning = True) |
209 if err.text.strip(): |
221 except SyntaxError as err: |
210 msg = err.text.strip() |
222 if err.text.strip(): |
211 else: |
223 msg = err.text.strip() |
212 msg = err.msg |
224 else: |
213 self.__createResultItem(err.filename, err.lineno, msg, "") |
225 msg = err.msg |
|
226 self.__createResultItem(err.filename, err.lineno, msg, "") |
|
227 else: |
|
228 for warning in warnings: |
|
229 self.noResults = False |
|
230 self.__createResultItem(warning[0], int(warning[1]), |
|
231 warning[2], "", isWarning = True) |
214 progress += 1 |
232 progress += 1 |
215 self.checkProgress.setValue(progress) |
233 self.checkProgress.setValue(progress) |
216 QApplication.processEvents() |
234 QApplication.processEvents() |
217 self.__resort() |
235 self.__resort() |
218 else: |
236 else: |