22Command line interface for code annotation tools.
33"""
44import datetime
5+ import traceback
56
67import click
78
@@ -42,7 +43,17 @@ def entry_point():
4243@click .option ('-v' , '--verbosity' , count = True , help = 'Verbosity level (-v through -vvv)' )
4344@click .option ('--lint/--no_lint' , help = 'Enable or disable linting checks' , default = False , show_default = True )
4445@click .option ('--report/--no_report' , help = 'Enable or disable writing the report' , default = False , show_default = True )
45- def django_find_annotations (config_file , seed_safelist , list_local_models , report_path , verbosity , lint , report ):
46+ @click .option ('--coverage/--no_coverage' , help = 'Enable or disable coverage checks' , default = False , show_default = True )
47+ def django_find_annotations (
48+ config_file ,
49+ seed_safelist ,
50+ list_local_models ,
51+ report_path ,
52+ verbosity ,
53+ lint ,
54+ report ,
55+ coverage
56+ ):
4657 """
4758 Subcommand for dealing with annotations in Django models.
4859 """
@@ -57,24 +68,29 @@ def django_find_annotations(config_file, seed_safelist, list_local_models, repor
5768 if list_local_models :
5869 searcher .list_local_models ()
5970
60- if lint or report :
71+ if lint or report or coverage :
6172 annotated_models = searcher .search ()
6273
6374 if lint :
6475 click .echo ("Performing linting checks..." )
6576
6677 # Check grouping and choices
67- searcher .check_results (annotated_models )
68-
69- # If there are any errors, do not generate the report
70- if searcher .errors :
78+ if not searcher .check_results (annotated_models ):
7179 click .secho ("\n Search failed due to linting errors!" , fg = "red" )
7280 click .secho ("{} errors:" .format (len (searcher .errors )), fg = "red" )
7381 click .secho ("---------------------------------" , fg = "red" )
7482 click .echo ("\n " .join (searcher .errors ))
83+ # If there are any errors, do not continue
7584 exit (- 1 )
7685 click .echo ("Linting passed without errors." )
7786
87+ if coverage :
88+ if not searcher .check_coverage ():
89+ # If there are any errors, do not continue
90+ exit (- 1 )
91+
92+ click .echo ("Coverage passed without errors." )
93+
7894 if report :
7995 searcher .report (annotated_models )
8096
@@ -85,7 +101,9 @@ def django_find_annotations(config_file, seed_safelist, list_local_models, repor
85101
86102 elapsed = datetime .datetime .now () - start_time
87103 click .echo ("Search found {} annotations in {}." .format (annotation_count , elapsed ))
104+
88105 except Exception as exc : # pylint: disable=broad-except
106+ click .echo (traceback .print_exc ())
89107 fail (str (exc ))
90108
91109
@@ -151,4 +169,5 @@ def static_find_annotations(config_file, source_path, report_path, verbosity, li
151169 click .echo ("Search found {} annotations in {}." .format (annotation_count , elapsed ))
152170
153171 except Exception as exc : # pylint: disable=broad-except
172+ click .echo (traceback .print_exc ())
154173 fail (str (exc ))
0 commit comments