Skip to content

Commit 50ffcda

Browse files
committed
style: Fix up formatting
1 parent 97a82b8 commit 50ffcda

File tree

2 files changed

+259
-147
lines changed

2 files changed

+259
-147
lines changed

code_annotations/cli.py

Lines changed: 100 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Command line interface for code annotation tools.
33
"""
4+
45
import datetime
56
import sys
67
import traceback
@@ -21,47 +22,72 @@ def entry_point():
2122
"""
2223

2324

24-
@entry_point.command('django_find_annotations')
25+
@entry_point.command("django_find_annotations")
26+
@click.option(
27+
"--config_file",
28+
default=".annotations",
29+
help="Path to the configuration file",
30+
type=click.Path(exists=True, dir_okay=False, resolve_path=True),
31+
)
32+
@click.option(
33+
"--seed_safelist/--no_safelist",
34+
default=False,
35+
show_default=True,
36+
help="Generate an initial safelist file based on the current Django environment.",
37+
)
2538
@click.option(
26-
'--config_file',
27-
default='.annotations',
28-
help='Path to the configuration file',
29-
type=click.Path(exists=True, dir_okay=False, resolve_path=True)
39+
"--list_local_models/--no_list_models",
40+
default=False,
41+
show_default=True,
42+
help="List all locally defined models (in the current repo) that require annotations.",
43+
)
44+
@click.option(
45+
"--app_name",
46+
default=None,
47+
help="(Optional) App name for which coverage is generated.",
48+
)
49+
@click.option("--report_path", default=None, help="Location to write the report")
50+
@click.option("-v", "--verbosity", count=True, help="Verbosity level (-v through -vvv)")
51+
@click.option(
52+
"--lint/--no_lint",
53+
help="Enable or disable linting checks",
54+
default=False,
55+
show_default=True,
3056
)
3157
@click.option(
32-
'--seed_safelist/--no_safelist',
58+
"--report/--no_report",
59+
help="Enable or disable writing the report",
3360
default=False,
3461
show_default=True,
35-
help='Generate an initial safelist file based on the current Django environment.',
3662
)
3763
@click.option(
38-
'--list_local_models/--no_list_models',
64+
"--coverage/--no_coverage",
65+
help="Enable or disable coverage checks",
3966
default=False,
4067
show_default=True,
41-
help='List all locally defined models (in the current repo) that require annotations.',
4268
)
43-
@click.option('--app_name', default=None, help='(Optional) App name for which coverage is generated.')
44-
@click.option('--report_path', default=None, help='Location to write the report')
45-
@click.option('-v', '--verbosity', count=True, help='Verbosity level (-v through -vvv)')
46-
@click.option('--lint/--no_lint', help='Enable or disable linting checks', default=False, show_default=True)
47-
@click.option('--report/--no_report', help='Enable or disable writing the report', default=False, show_default=True)
48-
@click.option('--coverage/--no_coverage', help='Enable or disable coverage checks', default=False, show_default=True)
4969
def django_find_annotations(
50-
config_file,
51-
seed_safelist,
52-
list_local_models,
53-
app_name,
54-
report_path,
55-
verbosity,
56-
lint,
57-
report,
58-
coverage
70+
config_file,
71+
seed_safelist,
72+
list_local_models,
73+
app_name,
74+
report_path,
75+
verbosity,
76+
lint,
77+
report,
78+
coverage,
5979
):
6080
"""
6181
Subcommand for dealing with annotations in Django models.
6282
"""
6383
try:
64-
if not coverage and not seed_safelist and not list_local_models and not lint and not report and not coverage:
84+
if (
85+
not coverage
86+
and not seed_safelist
87+
and not list_local_models
88+
and not lint
89+
and not report
90+
):
6591
click.echo(
6692
"No actions specified. Please specify one or more of --seed_safelist, --list_local_models, "
6793
"--lint, --report, or --coverage"
@@ -74,7 +100,9 @@ def django_find_annotations(
74100

75101
# Early out if we're trying to do coverage, but a coverage target is not configured
76102
if coverage and not config.coverage_target:
77-
raise ConfigurationException("Please add 'coverage_target' to your configuration before running --coverage")
103+
raise ConfigurationException(
104+
"Please add 'coverage_target' to your configuration before running --coverage"
105+
)
78106

79107
if seed_safelist:
80108
searcher.seed_safelist()
@@ -114,32 +142,46 @@ def django_find_annotations(
114142
annotation_count += len(annotated_models[filename])
115143

116144
elapsed = datetime.datetime.now() - start_time
117-
click.echo("Search found {} annotations in {} seconds.".format(
118-
annotation_count, elapsed.total_seconds()
119-
))
145+
click.echo(
146+
"Search found {} annotations in {} seconds.".format(
147+
annotation_count, elapsed.total_seconds()
148+
)
149+
)
120150

121151
except Exception as exc:
122152
click.echo(traceback.print_exc())
123153
fail(str(exc))
124154

125155

126-
@entry_point.command('static_find_annotations')
156+
@entry_point.command("static_find_annotations")
157+
@click.option(
158+
"--config_file",
159+
default=".annotations",
160+
help="Path to the configuration file",
161+
type=click.Path(exists=True, dir_okay=False, resolve_path=True),
162+
)
127163
@click.option(
128-
'--config_file',
129-
default='.annotations',
130-
help='Path to the configuration file',
131-
type=click.Path(exists=True, dir_okay=False, resolve_path=True)
164+
"--source_path",
165+
help="Location of the source code to search",
166+
type=click.Path(exists=True, dir_okay=True, resolve_path=True),
132167
)
168+
@click.option("--report_path", default=None, help="Location to write the report")
169+
@click.option("-v", "--verbosity", count=True, help="Verbosity level (-v through -vvv)")
133170
@click.option(
134-
'--source_path',
135-
help='Location of the source code to search',
136-
type=click.Path(exists=True, dir_okay=True, resolve_path=True)
171+
"--lint/--no_lint",
172+
help="Enable or disable linting checks",
173+
default=True,
174+
show_default=True,
175+
)
176+
@click.option(
177+
"--report/--no_report",
178+
help="Enable or disable writing the report file",
179+
default=True,
180+
show_default=True,
137181
)
138-
@click.option('--report_path', default=None, help='Location to write the report')
139-
@click.option('-v', '--verbosity', count=True, help='Verbosity level (-v through -vvv)')
140-
@click.option('--lint/--no_lint', help='Enable or disable linting checks', default=True, show_default=True)
141-
@click.option('--report/--no_report', help='Enable or disable writing the report file', default=True, show_default=True)
142-
def static_find_annotations(config_file, source_path, report_path, verbosity, lint, report):
182+
def static_find_annotations(
183+
config_file, source_path, report_path, verbosity, lint, report
184+
):
143185
"""
144186
Subcommand to find annotations via static file analysis.
145187
"""
@@ -183,18 +225,14 @@ def static_find_annotations(config_file, source_path, report_path, verbosity, li
183225

184226
@entry_point.command("generate_docs")
185227
@click.option(
186-
'--config_file',
187-
default='.annotations',
188-
help='Path to the configuration file',
189-
type=click.Path(exists=True, dir_okay=False)
228+
"--config_file",
229+
default=".annotations",
230+
help="Path to the configuration file",
231+
type=click.Path(exists=True, dir_okay=False),
190232
)
191-
@click.option('-v', '--verbosity', count=True, help='Verbosity level (-v through -vvv)')
192-
@click.argument("report_files", type=click.File('r'), nargs=-1)
193-
def generate_docs(
194-
config_file,
195-
verbosity,
196-
report_files
197-
):
233+
@click.option("-v", "--verbosity", count=True, help="Verbosity level (-v through -vvv)")
234+
@click.argument("report_files", type=click.File("r"), nargs=-1)
235+
def generate_docs(config_file, verbosity, report_files):
198236
"""
199237
Generate documentation from a code annotations report.
200238
"""
@@ -204,15 +242,19 @@ def generate_docs(
204242
config = AnnotationConfig(config_file, verbosity)
205243

206244
for key in (
207-
'report_template_dir',
208-
'rendered_report_dir',
209-
'rendered_report_file_extension',
210-
'rendered_report_source_link_prefix'
245+
"report_template_dir",
246+
"rendered_report_dir",
247+
"rendered_report_file_extension",
248+
"rendered_report_source_link_prefix",
211249
):
212250
if not getattr(config, key):
213251
raise ConfigurationException(f"No {key} key in {config_file}")
214252

215-
config.echo("Rendering the following reports: \n{}".format("\n".join([r.name for r in report_files])))
253+
config.echo(
254+
"Rendering the following reports: \n{}".format(
255+
"\n".join([r.name for r in report_files])
256+
)
257+
)
216258

217259
renderer = ReportRenderer(config, report_files)
218260
renderer.render()

0 commit comments

Comments
 (0)