mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-04 12:16:53 +00:00
Enable users who want to track all files processed
This adds two new methods to the BaseFormatter class: - beginning - finished These will indicate when Flake8 begins and finishes processing a file. Closes #251
This commit is contained in:
parent
cf0115e105
commit
5248cf3c2d
5 changed files with 35 additions and 2 deletions
|
|
@ -260,8 +260,9 @@ class Manager(object):
|
|||
results_reported = results_found = 0
|
||||
for checker in self.checkers:
|
||||
results = sorted(checker.results, key=lambda tup: (tup[1], tup[2]))
|
||||
results_reported += self._handle_results(checker.display_name,
|
||||
results)
|
||||
filename = checker.display_name
|
||||
with self.style_guide.processing_file(filename):
|
||||
results_reported += self._handle_results(filename, results)
|
||||
results_found += len(results)
|
||||
return (results_found, results_reported)
|
||||
|
||||
|
|
|
|||
|
|
@ -44,6 +44,24 @@ class BaseFormatter(object):
|
|||
"""Initialize the formatter further."""
|
||||
pass
|
||||
|
||||
def beginning(self, filename):
|
||||
"""Notify the formatter that we're starting to process a file.
|
||||
|
||||
:param str filename:
|
||||
The name of the file that Flake8 is beginning to report results
|
||||
from.
|
||||
"""
|
||||
pass
|
||||
|
||||
def finished(self, filename):
|
||||
"""Notify the formatter that we've finished processing a file.
|
||||
|
||||
:param str filename:
|
||||
The name of the file that Flake8 has finished reporting results
|
||||
from.
|
||||
"""
|
||||
pass
|
||||
|
||||
def start(self):
|
||||
"""Prepare the formatter to receive input.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
"""Implementation of the StyleGuide used by Flake8."""
|
||||
import collections
|
||||
import contextlib
|
||||
import enum
|
||||
import linecache
|
||||
import logging
|
||||
|
|
@ -120,6 +121,13 @@ class StyleGuide(object):
|
|||
|
||||
return Selected.Implicitly
|
||||
|
||||
@contextlib.contextmanager
|
||||
def processing_file(self, filename):
|
||||
"""Record the fact that we're processing the file's results."""
|
||||
self.formatter.beginning(filename)
|
||||
yield self
|
||||
self.formatter.finished(filename)
|
||||
|
||||
def _decision_for(self, code):
|
||||
# type: (Error) -> Decision
|
||||
select = find_first_match(code, self._all_selected)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue