Skip to content

Commit 8f06c42

Browse files
committed
style: use a helper for long help strings
1 parent f4541cf commit 8f06c42

File tree

2 files changed

+115
-73
lines changed

2 files changed

+115
-73
lines changed

coverage/cmdline.py

Lines changed: 113 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
# When adding to this file, alphabetization is important. Look for
3333
# "alphabetize" comments throughout.
3434

35+
36+
def oneline(text: str) -> str:
37+
"""Turn a multi-line string into one line for help to reformat nicely."""
38+
return " ".join(text.split())
39+
40+
3541
class Opts:
3642
"""A namespace class for individual options we'll build parsers from."""
3743

@@ -48,9 +54,11 @@ class Opts:
4854
)
4955
concurrency = optparse.make_option(
5056
"", "--concurrency", action="store", metavar="LIBS",
51-
help=(
52-
"Properly measure code using a concurrency library. " +
53-
"Valid values are: {}, or a comma-list of them."
57+
help=oneline(
58+
"""
59+
Properly measure code using a concurrency library.
60+
Valid values are: {}, or a comma-list of them.
61+
"""
5462
).format(", ".join(sorted(CoverageConfig.CONCURRENCY_CHOICES))),
5563
)
5664
context = optparse.make_option(
@@ -59,30 +67,38 @@ class Opts:
5967
)
6068
contexts = optparse.make_option(
6169
"", "--contexts", action="store", metavar="REGEX1,REGEX2,...",
62-
help=(
63-
"Only display data from lines covered in the given contexts. " +
64-
"Accepts Python regexes, which must be quoted."
70+
help=oneline(
71+
"""
72+
Only display data from lines covered in the given contexts.
73+
Accepts Python regexes, which must be quoted.
74+
"""
6575
),
6676
)
6777
datafile = optparse.make_option(
6878
"", "--data-file", action="store", metavar="DATAFILE",
69-
help=(
70-
"Base name of the data files to operate on. " +
71-
"Defaults to '.coverage'. [env: COVERAGE_FILE]"
79+
help=oneline(
80+
"""
81+
Base name of the data files to operate on.
82+
Defaults to '.coverage'. [env: COVERAGE_FILE]
83+
"""
7284
),
7385
)
7486
datafle_input = optparse.make_option(
7587
"", "--data-file", action="store", metavar="INFILE",
76-
help=(
77-
"Read coverage data for report generation from this file. " +
78-
"Defaults to '.coverage'. [env: COVERAGE_FILE]"
88+
help=oneline(
89+
"""
90+
Read coverage data for report generation from this file.
91+
Defaults to '.coverage'. [env: COVERAGE_FILE]
92+
"""
7993
),
8094
)
8195
datafile_output = optparse.make_option(
8296
"", "--data-file", action="store", metavar="OUTFILE",
83-
help=(
84-
"Write the recorded coverage data to this file. " +
85-
"Defaults to '.coverage'. [env: COVERAGE_FILE]"
97+
help=oneline(
98+
"""
99+
Write the recorded coverage data to this file.
100+
Defaults to '.coverage'. [env: COVERAGE_FILE]
101+
"""
86102
),
87103
)
88104
debug = optparse.make_option(
@@ -111,9 +127,11 @@ class Opts:
111127
)
112128
include = optparse.make_option(
113129
"", "--include", action="store", metavar="PAT1,PAT2,...",
114-
help=(
115-
"Include only files whose paths match one of these patterns. " +
116-
"Accepts shell-style wildcards, which must be quoted."
130+
help=oneline(
131+
"""
132+
Include only files whose paths match one of these patterns.
133+
Accepts shell-style wildcards, which must be quoted.
134+
"""
117135
),
118136
)
119137
keep = optparse.make_option(
@@ -122,9 +140,11 @@ class Opts:
122140
)
123141
pylib = optparse.make_option(
124142
"-L", "--pylib", action="store_true",
125-
help=(
126-
"Measure coverage even inside the Python installed library, " +
127-
"which isn't done by default."
143+
help=oneline(
144+
"""
145+
Measure coverage even inside the Python installed library,
146+
which isn't done by default.
147+
"""
128148
),
129149
)
130150
show_missing = optparse.make_option(
@@ -133,16 +153,20 @@ class Opts:
133153
)
134154
module = optparse.make_option(
135155
"-m", "--module", action="store_true",
136-
help=(
137-
"<pyfile> is an importable Python module, not a script path, " +
138-
"to be run as 'python -m' would run it."
156+
help=oneline(
157+
"""
158+
<pyfile> is an importable Python module, not a script path,
159+
to be run as 'python -m' would run it.
160+
"""
139161
),
140162
)
141163
omit = optparse.make_option(
142164
"", "--omit", action="store", metavar="PAT1,PAT2,...",
143-
help=(
144-
"Omit files whose paths match one of these patterns. " +
145-
"Accepts shell-style wildcards, which must be quoted."
165+
help=oneline(
166+
"""
167+
Omit files whose paths match one of these patterns.
168+
Accepts shell-style wildcards, which must be quoted.
169+
"""
146170
),
147171
)
148172
output_xml = optparse.make_option(
@@ -163,16 +187,20 @@ class Opts:
163187
)
164188
parallel_mode = optparse.make_option(
165189
"-p", "--parallel-mode", action="store_true",
166-
help=(
167-
"Append a unique suffix to the data file name to collect separate " +
168-
"data from multiple processes."
190+
help=oneline(
191+
"""
192+
Append a unique suffix to the data file name to collect separate
193+
data from multiple processes.
194+
"""
169195
),
170196
)
171197
precision = optparse.make_option(
172198
"", "--precision", action="store", metavar="N", type=int,
173-
help=(
174-
"Number of digits after the decimal point to display for " +
175-
"reported coverage percentages."
199+
help=oneline(
200+
"""
201+
Number of digits after the decimal point to display for
202+
reported coverage percentages.
203+
"""
176204
),
177205
)
178206
quiet = optparse.make_option(
@@ -181,18 +209,22 @@ class Opts:
181209
)
182210
rcfile = optparse.make_option(
183211
"", "--rcfile", action="store",
184-
help=(
185-
"Specify configuration file. " +
186-
"By default '.coveragerc', 'setup.cfg', 'tox.ini', and " +
187-
"'pyproject.toml' are tried. [env: COVERAGE_RCFILE]"
212+
help=oneline(
213+
"""
214+
Specify configuration file.
215+
By default '.coveragerc', 'setup.cfg', 'tox.ini', and
216+
'pyproject.toml' are tried. [env: COVERAGE_RCFILE]
217+
"""
188218
),
189219
)
190220
save_signal = optparse.make_option(
191221
"", "--save-signal", action="store", metavar="SIGNAL",
192222
choices = ["USR1", "USR2"],
193-
help=(
194-
"Specify a signal that will trigger coverage to write its collected data. " +
195-
"Supported values are: USR1, USR2. Not available on Windows."
223+
help=oneline(
224+
"""
225+
Specify a signal that will trigger coverage to write its collected data.
226+
Supported values are: USR1, USR2. Not available on Windows.
227+
"""
196228
),
197229
)
198230
show_contexts = optparse.make_option(
@@ -213,9 +245,11 @@ class Opts:
213245
)
214246
sort = optparse.make_option(
215247
"--sort", action="store", metavar="COLUMN",
216-
help=(
217-
"Sort the report by the named column: name, stmts, miss, branch, brpart, or cover. " +
218-
"Default is name."
248+
help=oneline(
249+
"""
250+
Sort the report by the named column: name, stmts, miss, branch, brpart, or cover.
251+
Default is name.
252+
"""
219253
),
220254
)
221255
source = optparse.make_option(
@@ -383,9 +417,11 @@ def get_prog_name(self) -> str:
383417
Opts.omit,
384418
] + GLOBAL_ARGS,
385419
usage="[options] [modules]",
386-
description=(
387-
"Make annotated copies of the given files, marking statements that are executed " +
388-
"with > and statements that are missed with !."
420+
description=oneline(
421+
"""
422+
Make annotated copies of the given files, marking statements that are executed
423+
with > and statements that are missed with !.
424+
"""
389425
),
390426
),
391427

@@ -398,28 +434,31 @@ def get_prog_name(self) -> str:
398434
Opts.quiet,
399435
] + GLOBAL_ARGS,
400436
usage="[options] <path1> <path2> ... <pathN>",
401-
description=(
402-
"Combine data from multiple coverage files. " +
403-
"The combined results are written to a single " +
404-
"file representing the union of the data. The positional " +
405-
"arguments are data files or directories containing data files. " +
406-
"If no paths are provided, data files in the default data file's " +
407-
"directory are combined."
437+
description=oneline(
438+
"""
439+
Combine data from multiple coverage files.
440+
The combined results are written to a single
441+
file representing the union of the data. The positional
442+
arguments are data files or directories containing data files.
443+
If no paths are provided, data files in the default data file's
444+
directory are combined.
445+
"""
408446
),
409447
),
410-
411448
"debug": CmdOptionParser(
412449
"debug", GLOBAL_ARGS,
413450
usage="<topic>",
414-
description=(
415-
"Display information about the internals of coverage.py, " +
416-
"for diagnosing problems. " +
417-
"Topics are: " +
418-
"'data' to show a summary of the collected data; " +
419-
"'sys' to show installation information; " +
420-
"'config' to show the configuration; " +
421-
"'premain' to show what is calling coverage; " +
422-
"'pybehave' to show internal flags describing Python behavior."
451+
description=oneline(
452+
"""
453+
Display information about the internals of coverage.py,
454+
for diagnosing problems.
455+
Topics are:
456+
'data' to show a summary of the collected data;
457+
'sys' to show installation information;
458+
'config' to show the configuration;
459+
'premain' to show what is calling coverage;
460+
'pybehave' to show internal flags describing Python behavior.
461+
"""
423462
),
424463
),
425464

@@ -456,10 +495,12 @@ def get_prog_name(self) -> str:
456495
Opts.title,
457496
] + GLOBAL_ARGS,
458497
usage="[options] [modules]",
459-
description=(
460-
"Create an HTML report of the coverage of the files. " +
461-
"Each file gets its own page, with the source decorated to show " +
462-
"executed, excluded, and missed lines."
498+
description=oneline(
499+
"""
500+
Create an HTML report of the coverage of the files.
501+
Each file gets its own page, with the source decorated to show
502+
executed, excluded, and missed lines.
503+
"""
463504
),
464505
),
465506

@@ -968,10 +1009,11 @@ def unglob_args(args: list[str]) -> list[str]:
9681009
9691010
Use "{program_name} help <command>" for detailed help on any command.
9701011
""",
971-
972-
"minimum_help": (
973-
"Code coverage for Python, version {__version__} {extension_modifier}. " +
974-
"Use '{program_name} help' for help."
1012+
"minimum_help": oneline(
1013+
"""
1014+
Code coverage for Python, version {__version__} {extension_modifier}.
1015+
Use '{program_name} help' for help.
1016+
"""
9751017
),
9761018

9771019
"version": "Coverage.py, version {__version__} {extension_modifier}",

doc/cmd.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ Click the keyboard icon in the upper right to see the complete list.
677677
$ coverage html --help
678678
Usage: coverage html [options] [modules]
679679
680-
Create an HTML report of the coverage of the files. Each file gets its own
680+
Create an HTML report of the coverage of the files. Each file gets its own
681681
page, with the source decorated to show executed, excluded, and missed lines.
682682
683683
Options:
@@ -712,7 +712,7 @@ Click the keyboard icon in the upper right to see the complete list.
712712
--rcfile=RCFILE Specify configuration file. By default '.coveragerc',
713713
'setup.cfg', 'tox.ini', and 'pyproject.toml' are
714714
tried. [env: COVERAGE_RCFILE]
715-
.. [[[end]]] (sum: 46Gm4krZsw)
715+
.. [[[end]]] (sum: DwG6DxRZIf)
716716
717717
The title of the report can be set with the ``title`` setting in the
718718
``[html]`` section of the configuration file, or the ``--title`` switch on

0 commit comments

Comments
 (0)