diff options
| author | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-03-15 08:42:13 -0500 |
|---|---|---|
| committer | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-03-15 08:42:13 -0500 |
| commit | 189faf68bac204625d6e0b3f3d3ff74ba924dc84 (patch) | |
| tree | f0a64903efffb17a2011a0fe8d1641e4e2903cc7 /flake8 | |
| parent | 3b830366b6c96ec65071eb316d69dee463d91390 (diff) | |
| download | flake8-189faf68bac204625d6e0b3f3d3ff74ba924dc84.tar.gz | |
Reorganize methods alphabetically
Add methods to report errors to the style guide
A single file works fine now but not a directory
Diffstat (limited to 'flake8')
| -rw-r--r-- | flake8/checker.py | 139 |
1 files changed, 91 insertions, 48 deletions
diff --git a/flake8/checker.py b/flake8/checker.py index 274dc23..7cd6d53 100644 --- a/flake8/checker.py +++ b/flake8/checker.py @@ -116,29 +116,64 @@ class Manager(object): # it to an integer return int(jobs) - def start(self): - """Start checking files.""" - LOG.info('Making checkers') - self.make_checkers() - if not self.using_multiprocessing: - return + def _report_after_parallel(self): + style_guide = self.style_guide + for (filename, results) in iter(self.results_queue.get, 'DONE'): + results = sorted(results, key=lambda tup: (tup[2], tup[3])) + for (error_code, line_number, column, text) in results: + style_guide.handle_error( + code=error_code, + filename=filename, + line_number=line_number, + column_number=column, + text=text + ) - LOG.info('Populating process queue') + def _report_after_serial(self): + style_guide = self.style_guide for checker in self.checkers: - self.process_queue.put(checker) + results = sorted(checker.results, key=lambda tup: (tup[2], tup[3])) + filename = checker.filename + for (error_code, line_number, column, text) in results: + style_guide.handle_error( + code=error_code, + filename=filename, + line_number=line_number, + column_number=column, + text=text + ) - def stop(self): - """Stop checking files.""" - if not self.using_multiprocessing: - return + def _run_checks_from_queue(self): + LOG.info('Running checks in parallel') + for checker in iter(self.process_queue.get, 'DONE'): + LOG.debug('Running checker for file "%s"', checker.filename) + checker.run_checks(self.results_queue) - LOG.info('Notifying process workers of completion') - for i in range(self.jobs or 0): - self.process_queue.put('DONE') + def is_path_excluded(self, path): + # type: (str) -> bool + """Check if a path is excluded. - LOG.info('Joining process workers') - for process in self.processes: - process.join() + :param str path: + Path to check against the exclude patterns. + :returns: + True if there are exclude patterns and the path matches, + otherwise False. + :rtype: + bool + """ + exclude = self.options.exclude + if not exclude: + return False + basename = os.path.basename(path) + if utils.fnmatch(basename, exclude): + LOG.info('"%s" has been excluded', basename) + return True + + absolute_path = os.path.abspath(path) + match = utils.fnmatch(absolute_path, exclude) + LOG.info('"%s" has %sbeen excluded', absolute_path, + '' if match else 'not ') + return match def make_checkers(self, paths=None): # type: (List[str]) -> NoneType @@ -154,11 +189,16 @@ class Manager(object): if utils.fnmatch(filename, filename_patterns) ] - def _run_checks_from_queue(self): - LOG.info('Running checks in parallel') - for checker in iter(self.process_queue.get, 'DONE'): - LOG.debug('Running checker for file "%s"', checker.filename) - checker.run_checks() + def report(self): + """Report all of the errors found in the managed file checkers. + + This iterates over each of the checkers and reports the errors sorted + by line number. + """ + if self.using_multiprocessing: + self._report_after_parallel() + else: + self._report_after_serial() def run(self): """Run all the checkers. @@ -179,31 +219,31 @@ class Manager(object): for checker in self.checkers: checker.run_checks() - def is_path_excluded(self, path): - # type: (str) -> bool - """Check if a path is excluded. + def start(self): + """Start checking files.""" + LOG.info('Making checkers') + self.make_checkers() + if not self.using_multiprocessing: + return - :param str path: - Path to check against the exclude patterns. - :returns: - True if there are exclude patterns and the path matches, - otherwise False. - :rtype: - bool - """ - exclude = self.options.exclude - if not exclude: - return False - basename = os.path.basename(path) - if utils.fnmatch(basename, exclude): - LOG.info('"%s" has been excluded', basename) - return True + LOG.info('Populating process queue') + for checker in self.checkers: + self.process_queue.put(checker) - absolute_path = os.path.abspath(path) - match = utils.fnmatch(absolute_path, exclude) - LOG.info('"%s" has %sbeen excluded', absolute_path, - '' if match else 'not ') - return match + def stop(self): + """Stop checking files.""" + if not self.using_multiprocessing: + return + + LOG.info('Notifying process workers of completion') + for i in range(self.jobs or 0): + self.process_queue.put('DONE') + + LOG.info('Joining process workers') + for process in self.processes: + process.join() + LOG.info('Processes joined') + self.results_queue.put('DONE') class FileChecker(object): @@ -246,7 +286,7 @@ class FileChecker(object): """Report an error by storing it in the results list.""" if error_code is None: error_code, text = text.split(' ', 1) - error = (error_code, self.filename, line_number, column, text) + error = (error_code, line_number, column, text) self.results.append(error) return error_code @@ -323,7 +363,7 @@ class FileChecker(object): self.run_physical_checks(file_processor.lines[-1]) self.run_logical_checks() - def run_checks(self): + def run_checks(self, results_queue): """Run checks against the file.""" if self.processor.should_ignore_file(): return @@ -334,6 +374,9 @@ class FileChecker(object): self.report(exc.error_code, exc.line_number, exc.column_number, exc.error_message) + if results_queue is not None: + results_queue.put_nowait((self.filename, self.results)) + def handle_comment(self, token, token_text): """Handle the logic when encountering a comment token.""" # The comment also ends a physical line |
