Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code_annotations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

from __future__ import absolute_import, unicode_literals

__version__ = '0.2.3'
__version__ = '0.2.4'
7 changes: 5 additions & 2 deletions code_annotations/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,20 +570,23 @@ def _format_results_for_report(self, all_results):

return formatted_results

def report(self, all_results):
def report(self, all_results, report_prefix=''):
"""
Genrates the YAML report of all search results.

Args:
all_results: Dict of found annotations, indexed by filename
report_prefix: Prefix to add to report filename

Returns:
Filename of generated report
"""
self.echo.echo_vv(yaml.dump(all_results, default_flow_style=False))

now = datetime.datetime.now()
report_filename = os.path.join(self.config.report_path, '{}.yaml'.format(now.strftime('%Y-%d-%m-%H-%M-%S')))
report_filename = os.path.join(self.config.report_path, '{}{}.yaml'.format(
report_prefix, now.strftime('%Y-%d-%m-%H-%M-%S')
))

formatted_results = self._format_results_for_report(all_results)

Expand Down
8 changes: 6 additions & 2 deletions code_annotations/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def entry_point():
show_default=True,
help='List all locally defined models (in the current repo) that require annotations.',
)
@click.option('--app_name', default='', help='(Optional) App name for which coverage is generated.')
@click.option('--report_path', default=None, help='Location to write the report')
@click.option('-v', '--verbosity', count=True, help='Verbosity level (-v through -vvv)')
@click.option('--lint/--no_lint', help='Enable or disable linting checks', default=False, show_default=True)
Expand All @@ -48,6 +49,7 @@ def django_find_annotations(
config_file,
seed_safelist,
list_local_models,
app_name,
report_path,
verbosity,
lint,
Expand Down Expand Up @@ -96,15 +98,17 @@ def django_find_annotations(
click.echo("Coverage passed without errors.")

if report:
searcher.report(annotated_models)
searcher.report(annotated_models, app_name)

annotation_count = 0

for filename in annotated_models:
annotation_count += len(annotated_models[filename])

elapsed = datetime.datetime.now() - start_time
click.echo("Search found {} annotations in {}.".format(annotation_count, elapsed))
click.echo("Search found {} annotations in {} seconds.".format(
annotation_count, elapsed.total_seconds()
))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, this output looks like this:
Search found 357 annotations in -1 day, 19:00:12.574411.
This change will make it look like this:
Search found 357 annotations in 29.3801 seconds.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. I have a different fix for it in the big refactor PR, but I'm glad to see it sorted.


except Exception as exc: # pylint: disable=broad-except
click.echo(traceback.print_exc())
Expand Down