summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2016-12-21 01:12:31 +0000
committerIan Cordasco <graffatcolmingov@gmail.com>2016-12-21 01:12:31 +0000
commit85c495b01283ab036ef11e755153e5f0acc4d8c7 (patch)
tree7cc9fd0fcb2995aac485960a79cde6a6a9ee1b33
parentcf0115e105c5963a45446b2cd511c076606119aa (diff)
parent5248cf3c2d4fba47a06121b13b7c0f03c5165420 (diff)
downloadflake8-85c495b01283ab036ef11e755153e5f0acc4d8c7.tar.gz
Merge branch 'feature/251' into 'master'
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 See merge request !152
-rw-r--r--docs/source/release-notes/3.3.0.rst5
-rw-r--r--src/flake8/checker.py5
-rw-r--r--src/flake8/formatting/base.py18
-rw-r--r--src/flake8/style_guide.py8
-rw-r--r--tests/integration/test_checker.py1
5 files changed, 35 insertions, 2 deletions
diff --git a/docs/source/release-notes/3.3.0.rst b/docs/source/release-notes/3.3.0.rst
index 0b0feae..2fb0c92 100644
--- a/docs/source/release-notes/3.3.0.rst
+++ b/docs/source/release-notes/3.3.0.rst
@@ -3,6 +3,9 @@
You can view the `3.3.0 milestone`_ on GitLab for more details.
+- Add methods to Report class that will be called when Flake8 starts and
+ finishes processing a file. (`GitLab#251`_)
+
- Dramatically improve the performance of Flake8 (`GitLab!156`_)
- Fix problem where hooks should only check \*.py files. (See also
@@ -14,6 +17,8 @@ You can view the `3.3.0 milestone`_ on GitLab for more details.
.. links
.. _3.3.0 milestone:
https://gitlab.com/pycqa/flake8/milestones/16
+.. _GitLab#251:
+ https://gitlab.com/pycqa/flake8/issues/251
.. _GitLab#268:
https://gitlab.com/pycqa/flake8/issues/268
.. _GitLab!156:
diff --git a/src/flake8/checker.py b/src/flake8/checker.py
index 4cd049d..32d438c 100644
--- a/src/flake8/checker.py
+++ b/src/flake8/checker.py
@@ -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)
diff --git a/src/flake8/formatting/base.py b/src/flake8/formatting/base.py
index 32b827a..abad254 100644
--- a/src/flake8/formatting/base.py
+++ b/src/flake8/formatting/base.py
@@ -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.
diff --git a/src/flake8/style_guide.py b/src/flake8/style_guide.py
index a531b39..fb0df3a 100644
--- a/src/flake8/style_guide.py
+++ b/src/flake8/style_guide.py
@@ -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)
diff --git a/tests/integration/test_checker.py b/tests/integration/test_checker.py
index 1b8a3c5..02c840b 100644
--- a/tests/integration/test_checker.py
+++ b/tests/integration/test_checker.py
@@ -134,6 +134,7 @@ def test_report_order(results, expected_order):
file_checker.display_name = 'placeholder'
style_guide = mock.Mock(spec=['options'])
+ style_guide.processing_file = mock.MagicMock()
# Create a placeholder manager without arguments or plugins
# Just add one custom file checker which just provides the results