Skip to content

Commit

Permalink
Merge branch 'bug/180' into 'master'
Browse files Browse the repository at this point in the history
Wire-up --statistics again

*Description of changes*

Make `--statistics` work again

*Related to:*  #180

See merge request !87
  • Loading branch information
sigmavirus24 committed Jul 25, 2016
2 parents 427c4b5 + 4dc1d11 commit 667a01f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/flake8/formatting/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ def format(self, error):
raise NotImplementedError('Subclass of BaseFormatter did not implement'
' format.')

def show_statistics(self, statistics):
"""Format and print the statistics."""
for error_code in statistics.error_codes():
stats_for_error_code = statistics.statistics_for(error_code)
statistic = next(stats_for_error_code)
count = statistic.count
count += sum(stat.count for stat in stats_for_error_code)
self._write('{count:<5} {error_code} {message}'.format(
count=count,
error_code=error_code,
message=statistic.message,
))

def show_benchmarks(self, benchmarks):
"""Format and print the benchmarks."""
# NOTE(sigmavirus24): The format strings are a little confusing, even
Expand Down
8 changes: 8 additions & 0 deletions src/flake8/main/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,13 @@ def report_errors(self):
LOG.info('Found a total of %d violations and reported %d',
self.total_result_count, self.result_count)

def report_statistics(self):
"""Aggregate and report statistics from this run."""
if not self.options.statistics:
return

self.formatter.show_statistics(self.guide.stats)

def initialize(self, argv):
# type: () -> NoneType
"""Initialize the application to be run.
Expand All @@ -286,6 +293,7 @@ def _run(self, argv):
self.run_checks()
self.formatter.start()
self.report_errors()
self.report_statistics()
self.report_benchmarks()
self.formatter.stop()

Expand Down
10 changes: 10 additions & 0 deletions src/flake8/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ def __init__(self):
"""Initialize the underlying dictionary for our statistics."""
self._store = {}

def error_codes(self):
"""Return all unique error codes stored.
:returns:
Sorted list of error codes.
:rtype:
list(str)
"""
return list(sorted(set(key.code for key in self._store.keys())))

def record(self, error):
"""Add the fact that the error was seen in the file.
Expand Down

0 comments on commit 667a01f

Please sign in to comment.