gh-142389: Add backticks to stdlib argparse help to display in colour (#149384)

Co-authored-by: Savannah Ostrowski <savannah@python.org>
This commit is contained in:
Hugo van KemenadeandSavannah Ostrowski authored and GitHub committed 2026-05-04 22:23:18 +00:00
1 parent 53a7f76501
commit ef6f0635ce
33 files changed
+115 -123

No files matched your search

+3 -3
View File
@@ -666,7 +666,7 @@ def main(args=None):
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('infile', nargs='?', default='-',
help='the file to parse; defaults to stdin')
help='the file to parse; defaults to `stdin`')
parser.add_argument('-m', '--mode', default='exec',
choices=('exec', 'single', 'eval', 'func_type'),
help='specify what kind of code must be parsed')
@@ -679,8 +679,8 @@ def main(args=None):
help='indentation of nodes (number of spaces)')
parser.add_argument('--feature-version',
type=str, default=None, metavar='VERSION',
help='Python version in the format 3.x '
'(for example, 3.10)')
help='Python version in the format `3.x` '
'(for example, `3.10`)')
parser.add_argument('-O', '--optimize',
type=int, default=-1, metavar='LEVEL',
help='optimization level for parser')
-1
View File
@@ -159,7 +159,6 @@ if __name__ == '__main__':
parser = argparse.ArgumentParser(
prog="python3 -m asyncio",
description="Interactive asyncio shell and CLI tools",
color=True,
)
subparsers = parser.add_subparsers(help="sub-commands", dest="command")
ps = subparsers.add_parser(
+1 -1
View File
@@ -922,7 +922,7 @@ def main(args=None):
"-t", "--type",
default="text",
choices=("text", "html"),
help="output type (text or html)"
help="output type (`text` or `html`)"
)
parser.add_argument(
"-f", "--first-weekday",
+1 -1
View File
@@ -385,7 +385,7 @@ def interact(banner=None, readfunc=None, local=None, exitmsg=None, local_exit=Fa
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(color=True)
parser = argparse.ArgumentParser()
parser.add_argument('-q', action='store_true',
help="don't print version and copyright messages")
args = parser.parse_args()
+11 -12
View File
@@ -326,7 +326,6 @@ def main():
parser = argparse.ArgumentParser(
description='Utilities to support installing Python libraries.',
color=True,
)
parser.add_argument('-l', action='store_const', const=0,
default=None, dest='maxlevels',
@@ -338,10 +337,10 @@ def main():
parser.add_argument('-f', action='store_true', dest='force',
help='force rebuild even if timestamps are up to date')
parser.add_argument('-q', action='count', dest='quiet', default=0,
help='output only error messages; -qq will suppress '
help='output only error messages; `-qq` will suppress '
'the error messages as well.')
parser.add_argument('-b', action='store_true', dest='legacy',
help='use legacy (pre-PEP3147) compiled file locations')
help='use legacy (pre-PEP 3147) compiled file locations')
parser.add_argument('-d', metavar='DESTDIR', dest='ddir', default=None,
help=('directory to prepend to file paths for use in '
'compile-time tracebacks and in runtime '
@@ -367,28 +366,28 @@ def main():
'of each file considered for compilation'))
parser.add_argument('-i', metavar='FILE', dest='flist',
help=('add all the files and directories listed in '
'FILE to the list considered for compilation; '
'if "-", names are read from stdin'))
'`FILE` to the list considered for compilation; '
'if `"-"`, names are read from `stdin`'))
parser.add_argument('compile_dest', metavar='FILE|DIR', nargs='*',
help=('zero or more file and directory names '
'to compile; if no arguments given, defaults '
'to the equivalent of -l sys.path'))
'to the equivalent of `-l` `sys.path`'))
parser.add_argument('-j', '--workers', default=1,
type=int, help='Run compileall concurrently')
invalidation_modes = [mode.name.lower().replace('_', '-')
for mode in py_compile.PycInvalidationMode]
parser.add_argument('--invalidation-mode',
choices=sorted(invalidation_modes),
help=('set .pyc invalidation mode; defaults to '
'"checked-hash" if the SOURCE_DATE_EPOCH '
help=('set `.pyc` invalidation mode; defaults to '
'`"checked-hash"` if the `SOURCE_DATE_EPOCH` '
'environment variable is set, and '
'"timestamp" otherwise.'))
'`"timestamp"` otherwise.'))
parser.add_argument('-o', action='append', type=int, dest='opt_levels',
help=('Optimization levels to run compilation with. '
'Default is -1 which uses the optimization level '
'of the Python interpreter itself (see -O).'))
'Default is `-1` which uses the optimization level '
'of the Python interpreter itself (see `-O`).'))
parser.add_argument('-e', metavar='DIR', dest='limit_sl_dest',
help='Ignore symlinks pointing outsite of the DIR')
help='Ignore symlinks pointing outsite of the `DIR`')
parser.add_argument('--hardlink-dupes', action='store_true',
dest='hardlink_dupes',
help='Hardlink duplicated pyc files')
+1 -1
View File
@@ -1146,7 +1146,7 @@ class Bytecode:
def main(args=None):
import argparse
parser = argparse.ArgumentParser(color=True)
parser = argparse.ArgumentParser()
parser.add_argument('-C', '--show-caches', action='store_true',
help='show inline caches')
parser.add_argument('-O', '--show-offsets', action='store_true',
+3 -3
View File
@@ -2951,7 +2951,7 @@ __test__ = {"_TestClass": _TestClass,
def _test():
import argparse
parser = argparse.ArgumentParser(description="doctest runner", color=True)
parser = argparse.ArgumentParser(description="doctest runner")
parser.add_argument('-v', '--verbose', action='store_true', default=False,
help='print very verbose output for all tests')
parser.add_argument('-o', '--option', action='append',
@@ -2961,8 +2961,8 @@ def _test():
' than once to apply multiple options'))
parser.add_argument('-f', '--fail-fast', action='store_true',
help=('stop running tests after first failure (this'
' is a shorthand for -o FAIL_FAST, and is'
' in addition to any other -o options)'))
' is a shorthand for `-o FAIL_FAST`, and is'
' in addition to any other `-o` options)'))
parser.add_argument('file', nargs='+',
help='file containing the tests to run')
args = parser.parse_args()
+1 -1
View File
@@ -217,7 +217,7 @@ def _uninstall_helper(*, verbosity=0):
def _main(argv=None):
import argparse
parser = argparse.ArgumentParser(color=True)
parser = argparse.ArgumentParser()
parser.add_argument(
"--version",
action="version",
+2 -3
View File
@@ -664,15 +664,14 @@ def decompress(data):
def main():
from argparse import ArgumentParser
parser = ArgumentParser(description=
"A simple command line interface for the gzip module: act like gzip, "
"A simple command line interface for the `gzip` module: act like `gzip`, "
"but do not delete the input file.",
color=True,
)
group = parser.add_mutually_exclusive_group()
group.add_argument('--fast', action='store_true', help='compress faster')
group.add_argument('--best', action='store_true', help='compress better')
group.add_argument("-d", "--decompress", action="store_true",
help="act like gunzip instead of gzip")
help="act like `gunzip` instead of `gzip`")
parser.add_argument("args", nargs="*", default=["-"], metavar='file')
args = parser.parse_args()
+1 -1
View File
@@ -1081,7 +1081,7 @@ def _main(args=None):
import argparse
import contextlib
parser = argparse.ArgumentParser(color=True)
parser = argparse.ArgumentParser()
parser.add_argument('-b', '--bind', metavar='ADDRESS',
help='bind to this address '
'(default: all interfaces)')
+2 -2
View File
@@ -3445,11 +3445,11 @@ def _main():
import argparse
import importlib
parser = argparse.ArgumentParser(color=True)
parser = argparse.ArgumentParser()
parser.add_argument(
'object',
help="The object to be analysed. "
"It supports the 'module:qualname' syntax")
"It supports the `module:qualname` syntax")
parser.add_argument(
'-d', '--details', action='store_true',
help='Display info about the module rather than its source code')
+4 -4
View File
@@ -44,13 +44,13 @@ def _colorize_json(json_str, theme):
def main():
description = ('A simple command line interface for json module '
'to validate and pretty-print JSON objects.')
parser = argparse.ArgumentParser(description=description, color=True)
parser = argparse.ArgumentParser(description=description)
parser.add_argument('infile', nargs='?',
help='a JSON file to be validated or pretty-printed; '
'defaults to stdin',
'defaults to `stdin`',
default='-')
parser.add_argument('outfile', nargs='?',
help='write the output of infile to outfile',
help='write the output of `infile` to `outfile`',
default=None)
parser.add_argument('--sort-keys', action='store_true', default=False,
help='sort the output of dictionaries alphabetically by key')
@@ -58,7 +58,7 @@ def main():
help='disable escaping of non-ASCII characters')
parser.add_argument('--json-lines', action='store_true', default=False,
help='parse input using the JSON Lines format. '
'Use with --no-indent or --compact to produce valid JSON Lines output.')
'Use with `--no-indent` or `--compact` to produce valid JSON Lines output.')
group = parser.add_mutually_exclusive_group()
group.add_argument('--indent', default=4, type=int,
help='separate items with newlines and use this number '
+1 -1
View File
@@ -712,7 +712,7 @@ def _parse_args(args):
from argparse import ArgumentParser
parser = ArgumentParser(
description='map filename extensions to MIME types', color=True
description='map filename extensions to MIME types',
)
parser.add_argument(
'-e', '--extension',
+1 -2
View File
@@ -3757,13 +3757,12 @@ def parse_args():
description=_usage,
formatter_class=argparse.RawDescriptionHelpFormatter,
allow_abbrev=False,
color=True,
)
# Get all the commands out first. For backwards compatibility, we allow
# -c commands to be after the target.
parser.add_argument('-c', '--command', action='append', default=[], metavar='command', dest='commands',
help='pdb commands to execute as if given in a .pdbrc file')
help='pdb commands to execute as if given in a `.pdbrc` file')
opts, args = parser.parse_known_args()
-1
View File
@@ -1937,7 +1937,6 @@ def _main(args=None):
import pprint
parser = argparse.ArgumentParser(
description='display contents of the pickle files',
color=True,
)
parser.add_argument(
'pickle_file',
+1 -1
View File
@@ -2899,7 +2899,7 @@ def _main(args=None):
help='preserve memo between disassemblies')
parser.add_argument(
'-l', '--indentlevel', default=4, type=int,
help='the number of blanks by which to indent a new MARK level')
help='the number of blanks by which to indent a new `MARK` level')
parser.add_argument(
'-a', '--annotate', action='store_true',
help='annotate each line with a short opcode description')
+1 -1
View File
@@ -1400,7 +1400,7 @@ def invalidate_caches():
def _parse_args(args: list[str] | None):
import argparse
parser = argparse.ArgumentParser(color=True)
parser = argparse.ArgumentParser()
parser.add_argument("args", nargs="*", choices=["nonaliased", "terse"])
parser.add_argument(
"--terse",
+13 -13
View File
@@ -389,13 +389,13 @@ def _add_sampling_options(parser):
sampling_group.add_argument(
"--native",
action="store_true",
help='Include artificial "<native>" frames to denote calls to non-Python code',
help='Include artificial `<native>` frames to denote calls to non-Python code',
)
sampling_group.add_argument(
"--no-gc",
action="store_false",
dest="gc",
help='Don\'t include artificial "<GC>" frames to denote active garbage collection',
help='Don\'t include artificial `<GC>` frames to denote active garbage collection',
)
sampling_group.add_argument(
"--opcodes",
@@ -432,14 +432,14 @@ def _add_mode_options(parser):
help="Sampling mode: wall (all samples), cpu (only samples when thread is on CPU), "
"gil (only samples when thread holds the GIL), "
"exception (only samples when thread has an active exception). "
"Incompatible with --async-aware",
"Incompatible with `--async-aware`",
)
mode_group.add_argument(
"--async-mode",
choices=["running", "all"],
default="running",
help='Async profiling mode: "running" (only running task) '
'or "all" (all tasks including waiting). Requires --async-aware',
'or "all" (all tasks including waiting). Requires `--async-aware`',
)
@@ -486,7 +486,7 @@ def _add_format_options(parser, include_compression=True, include_binary=True):
"--diff-flamegraph",
metavar="BASELINE",
action=DiffFlamegraphAction,
help="Generate differential flamegraph comparing current profile to BASELINE binary file",
help="Generate differential flamegraph comparing current profile to `BASELINE` binary file",
)
if include_binary:
format_group.add_argument(
@@ -494,7 +494,7 @@ def _add_format_options(parser, include_compression=True, include_binary=True):
action="store_const",
const="binary",
dest="format",
help="Generate high-performance binary format (use 'replay' command to convert)",
help="Generate high-performance binary format (use `replay` command to convert)",
)
parser.set_defaults(format="pstats", diff_baseline=None)
@@ -510,14 +510,14 @@ def _add_format_options(parser, include_compression=True, include_binary=True):
"-o",
"--output",
dest="outfile",
help="Output path (default: stdout for pstats text; with -o, pstats is binary). "
"Auto-generated for other formats. For heatmap: directory name (default: heatmap_PID)",
help="Output path (default: `stdout` for `pstats` text; with `-o`, `pstats` is binary). "
"Auto-generated for other formats. For heatmap: directory name (default: `heatmap_PID`)",
)
output_group.add_argument(
"--browser",
action="store_true",
help="Automatically open HTML output (flamegraph, heatmap) in browser. "
"When using --subprocesses, only the main process opens the browser",
"When using `--subprocesses`, only the main process opens the browser",
)
@@ -564,13 +564,13 @@ def _add_dump_options(parser):
dump_group.add_argument(
"--native",
action="store_true",
help='Include artificial "<native>" frames to denote calls to non-Python code',
help='Include artificial `<native>` frames to denote calls to non-Python code',
)
dump_group.add_argument(
"--no-gc",
action="store_false",
dest="gc",
help='Don\'t include artificial "<GC>" frames to denote active garbage collection',
help='Don\'t include artificial `<GC>` frames to denote active garbage collection',
)
dump_group.add_argument(
"--opcodes",
@@ -588,7 +588,7 @@ def _add_dump_options(parser):
default=argparse.SUPPRESS,
help='Async stack mode: "running" (only running task) '
'or "all" (all tasks including waiting, default for dump). '
"Requires --async-aware",
"Requires `--async-aware`",
)
dump_group.add_argument(
"--blocking",
@@ -998,7 +998,7 @@ Examples:
"-m",
"--module",
action="store_true",
help="Run target as a module (like python -m)",
help="Run target as a module (like `python -m`)",
)
run_parser.add_argument(
"target",
+1 -1
View File
@@ -177,7 +177,7 @@ def main():
import argparse
description = 'A simple command-line interface for py_compile module.'
parser = argparse.ArgumentParser(description=description, color=True)
parser = argparse.ArgumentParser(description=description)
parser.add_argument(
'-q', '--quiet',
action='store_true',
+6 -6
View File
@@ -1016,26 +1016,26 @@ if hasattr(_os, "fork"):
def _parse_args(arg_list: list[str] | None):
import argparse
parser = argparse.ArgumentParser(
formatter_class=argparse.RawTextHelpFormatter, color=True)
formatter_class=argparse.RawTextHelpFormatter)
group = parser.add_mutually_exclusive_group()
group.add_argument(
"-c", "--choice", nargs="+",
help="print a random choice")
group.add_argument(
"-i", "--integer", type=int, metavar="N",
help="print a random integer between 1 and N inclusive")
help="print a random integer between 1 and `N` inclusive")
group.add_argument(
"-f", "--float", type=float, metavar="N",
help="print a random floating-point number between 0 and N inclusive")
help="print a random floating-point number between 0 and `N` inclusive")
group.add_argument(
"--test", type=int, const=10_000, nargs="?",
help=argparse.SUPPRESS)
parser.add_argument("input", nargs="*",
help="""\
if no options given, output depends on the input
string or multiple: same as --choice
integer: same as --integer
float: same as --float""")
string or multiple: same as `--choice`
integer: same as `--integer`
float: same as `--float`""")
args = parser.parse_args(arg_list)
return args, parser.format_help()
+3 -6
View File
@@ -87,14 +87,11 @@ class SqliteInteractiveConsole(InteractiveConsole):
def main(*args):
parser = ArgumentParser(
description="Python sqlite3 CLI",
color=True,
)
parser = ArgumentParser(description="Python sqlite3 CLI")
parser.add_argument(
"filename", type=str, default=":memory:", nargs="?",
help=(
"SQLite database to open (defaults to ':memory:'). "
"SQLite database to open (defaults to `:memory:`). "
"A new database is created if the file does not previously exist."
),
)
@@ -102,7 +99,7 @@ def main(*args):
"sql", type=str, nargs="?",
help=(
"An SQL query to execute. "
"Any returned rows are printed to stdout."
"Any returned rows are printed to `stdout`."
),
)
parser.add_argument(
+1 -1
View File
@@ -3067,7 +3067,7 @@ def main():
import argparse
description = 'A simple command-line interface for tarfile module.'
parser = argparse.ArgumentParser(description=description, color=True)
parser = argparse.ArgumentParser(description=description)
parser.add_argument('-v', '--verbose', action='store_true', default=False,
help='Verbose output')
parser.add_argument('--filter', metavar='<filtername>',
+20 -20
View File
@@ -245,7 +245,7 @@ def _create_parser():
'buildbot workers')
group.add_argument('--timeout', metavar='TIMEOUT',
help='dump the traceback and exit if a test takes '
'more than TIMEOUT seconds; disabled if TIMEOUT '
'more than `TIMEOUT` seconds; disabled if `TIMEOUT` '
'is negative or equals to zero')
group.add_argument('--wait', action='store_true',
help='wait for user input, e.g., allow a debugger '
@@ -261,11 +261,11 @@ def _create_parser():
group = parser.add_argument_group('Verbosity')
group.add_argument('-v', '--verbose', action='count',
help='run tests in verbose mode with output to stdout')
help='run tests in verbose mode with output to `stdout`')
group.add_argument('-w', '--rerun', action='store_true',
help='re-run failed tests in verbose mode')
group.add_argument('--verbose2', action='store_true', dest='rerun',
help='deprecated alias to --rerun')
help='deprecated alias to `--rerun`')
group.add_argument('-W', '--verbose3', action='store_true',
help='display test output on failure')
group.add_argument('-q', '--quiet', action='store_true',
@@ -295,22 +295,22 @@ def _create_parser():
more_details)
group.add_argument('-m', '--match', metavar='PAT',
dest='match_tests', action=FilterAction, const=True,
help='match test cases and methods with glob pattern PAT')
help='match test cases and methods with glob pattern `PAT`')
group.add_argument('-i', '--ignore', metavar='PAT',
dest='match_tests', action=FilterAction, const=False,
help='ignore test cases and methods with glob pattern PAT')
help='ignore test cases and methods with glob pattern `PAT`')
group.add_argument('--matchfile', metavar='FILENAME',
dest='match_tests',
action=FromFileFilterAction, const=True,
help='similar to --match but get patterns from a '
help='similar to `--match` but get patterns from a '
'text file, one pattern per line')
group.add_argument('--ignorefile', metavar='FILENAME',
dest='match_tests',
action=FromFileFilterAction, const=False,
help='similar to --matchfile but it receives patterns '
help='similar to `--matchfile` but it receives patterns '
'from text file to ignore')
group.add_argument('-G', '--failfast', action='store_true',
help='fail as soon as a test fails (only with -v or -W)')
help='fail as soon as a test fails (only with `-v` or `-W`)')
group.add_argument('-u', '--use', metavar='RES1,RES2,...',
action='extend', type=resources_list,
help='specify which special resource intensive tests '
@@ -325,7 +325,7 @@ def _create_parser():
group = parser.add_argument_group('Special runs')
group.add_argument('-L', '--runleaks', action='store_true',
help='run the leaks(1) command just before exit.' +
help='run the `leaks(1)` command just before exit.' +
more_details)
group.add_argument('-R', '--huntrleaks', metavar='RUNCOUNTS',
type=huntrleaks,
@@ -333,20 +333,20 @@ def _create_parser():
'very slow).' + more_details)
group.add_argument('-j', '--multiprocess', metavar='PROCESSES',
dest='use_mp', type=int,
help='run PROCESSES processes at once')
help='run `PROCESSES` processes at once')
group.add_argument('--single-process', action='store_true',
dest='single_process',
help='always run all tests sequentially in '
'a single process, ignore -jN option, '
'a single process, ignore `-jN` option, '
'and failed tests are also rerun sequentially '
'in the same process')
group.add_argument('--parallel-threads', metavar='PARALLEL_THREADS',
type=int,
help='run copies of each test in PARALLEL_THREADS at '
help='run copies of each test in `PARALLEL_THREADS` at '
'once')
group.add_argument('-T', '--coverage', action='store_true',
dest='trace',
help='turn on code coverage tracing using the trace '
help='turn on code coverage tracing using the `trace` '
'module')
group.add_argument('-D', '--coverdir', metavar='DIR',
type=relative_filename,
@@ -356,18 +356,18 @@ def _create_parser():
help='put coverage files alongside modules')
group.add_argument('-t', '--threshold', metavar='THRESHOLD',
type=int,
help='call gc.set_threshold(THRESHOLD)')
help='call `gc.set_threshold(THRESHOLD)`')
group.add_argument('-n', '--nowindows', action='store_true',
help='suppress error message boxes on Windows')
group.add_argument('-F', '--forever', action='store_true',
help='run the specified tests in a loop, until an '
'error happens; imply --failfast')
'error happens; imply `--failfast`')
group.add_argument('--list-tests', action='store_true',
help="only write the name of tests that will be run, "
"don't execute them")
group.add_argument('--list-cases', action='store_true',
help='only write the name of test cases that will be run'
' , don\'t execute them')
help='only write the name of test cases that will be run, '
'don\'t execute them')
group.add_argument('-P', '--pgo', dest='pgo', action='store_true',
help='enable Profile Guided Optimization (PGO) training')
group.add_argument('--pgo-extended', action='store_true',
@@ -390,11 +390,11 @@ def _create_parser():
group.add_argument('--tempdir', metavar='PATH',
help='override the working directory for the test run')
group.add_argument('--cleanup', action='store_true',
help='remove old test_python_* directories')
help='remove old `test_python_*` directories')
group.add_argument('--bisect', action='store_true',
help='if some tests fail, run test.bisect_cmd on them')
help='if some tests fail, run `test.bisect_cmd` on them')
group.add_argument('--pythoninfo', action='store_true',
help="run python -m test.pythoninfo before tests")
help="run `python -m test.pythoninfo` before tests")
group.add_argument('--dont-add-python-opts', dest='_add_python_opts',
action='store_false',
help="internal option, don't use it")
+2 -2
View File
@@ -299,14 +299,14 @@ Library usage: see the `Timer` class.""",
"-p",
"--process",
action="store_true",
help="use time.process_time() (default is time.perf_counter())",
help="use `time.process_time()` (default is `time.perf_counter()`)",
)
parser.add_argument(
"-t",
"--target-time",
type=float,
default=default_target_time,
help="if --number is 0 the code will run until it takes "
help="if `--number` is 0 the code will run until it takes "
"at least this many seconds (default %(default)s)",
)
parser.add_argument(
+1 -1
View File
@@ -578,7 +578,7 @@ def _main(args=None):
parser = argparse.ArgumentParser()
parser.add_argument(dest='filename', nargs='?',
metavar='filename.py',
help='the file to tokenize; defaults to stdin')
help='the file to tokenize; defaults to `stdin`')
parser.add_argument('-e', '--exact', dest='exact', action='store_true',
help='display token names using the exact type')
args = parser.parse_args(args)
+16 -16
View File
@@ -604,7 +604,7 @@ class Trace:
def main():
import argparse
parser = argparse.ArgumentParser(color=True)
parser = argparse.ArgumentParser()
parser.add_argument('--version', action='version', version='trace 2.0')
grp = parser.add_argument_group('Main options',
@@ -612,27 +612,27 @@ def main():
grp.add_argument('-c', '--count', action='store_true',
help='Count the number of times each line is executed and write '
'the counts to <module>.cover for each module executed, in '
'the module\'s directory. See also --coverdir, --file, '
'--no-report below.')
'the counts to `<module>.cover` for each module executed, in '
'the module\'s directory. See also `--coverdir`, `--file`, '
'`--no-report` below.')
grp.add_argument('-t', '--trace', action='store_true',
help='Print each line to sys.stdout before it is executed')
help='Print each line to `sys.stdout` before it is executed')
grp.add_argument('-l', '--listfuncs', action='store_true',
help='Keep track of which functions are executed at least once '
'and write the results to sys.stdout after the program exits. '
'Cannot be specified alongside --trace or --count.')
'and write the results to `sys.stdout` after the program exits. '
'Cannot be specified alongside `--trace` or `--count`.')
grp.add_argument('-T', '--trackcalls', action='store_true',
help='Keep track of caller/called pairs and write the results to '
'sys.stdout after the program exits.')
'`sys.stdout` after the program exits.')
grp = parser.add_argument_group('Modifiers')
_grp = grp.add_mutually_exclusive_group()
_grp.add_argument('-r', '--report', action='store_true',
help='Generate a report from a counts file; does not execute any '
'code. --file must specify the results file to read, which '
'must have been created in a previous run with --count '
'--file=FILE')
'code. `--file` must specify the results file to read, which '
'must have been created in a previous run with `--count` '
'`--file=FILE`')
_grp.add_argument('-R', '--no-report', action='store_true',
help='Do not generate the coverage report files. '
'Useful if you want to accumulate over several runs.')
@@ -641,14 +641,14 @@ def main():
help='File to accumulate counts over several runs')
grp.add_argument('-C', '--coverdir',
help='Directory where the report files go. The coverage report '
'for <package>.<module> will be written to file '
'<dir>/<package>/<module>.cover')
'for `<package>.<module>` will be written to file '
'`<dir>/<package>/<module>.cover`')
grp.add_argument('-m', '--missing', action='store_true',
help='Annotate executable lines that were not executed with '
'">>>>>> "')
grp.add_argument('-s', '--summary', action='store_true',
help='Write a brief summary for each file to sys.stdout. '
'Can only be used with --count or --report')
help='Write a brief summary for each file to `sys.stdout`. '
'Can only be used with `--count` or `--report`')
grp.add_argument('-g', '--timing', action='store_true',
help='Prefix each line with the time since the program started. '
'Only used while tracing')
@@ -661,7 +661,7 @@ def main():
'module names.')
grp.add_argument('--ignore-dir', action='append', default=[],
help='Ignore files in the given directory '
'(multiple directories can be joined by os.pathsep).')
'(multiple directories can be joined by `os.pathsep`).')
parser.add_argument('--module', action='store_true', default=False,
help='Trace a module. ')
+7 -7
View File
@@ -172,7 +172,7 @@ class TestProgram(object):
help='Show local variables in tracebacks')
parser.add_argument('--durations', dest='durations', type=int,
default=None, metavar="N",
help='Show the N slowest test cases (N=0 for all)')
help='Show the `N` slowest test cases (`N=0` for all)')
if self.failfast is None:
parser.add_argument('-f', '--failfast', dest='failfast',
action='store_true',
@@ -181,12 +181,12 @@ class TestProgram(object):
if self.catchbreak is None:
parser.add_argument('-c', '--catch', dest='catchbreak',
action='store_true',
help='Catch Ctrl-C and display results so far')
help='Catch `Ctrl-C` and display results so far')
self.catchbreak = False
if self.buffer is None:
parser.add_argument('-b', '--buffer', dest='buffer',
action='store_true',
help='Buffer stdout and stderr during tests')
help='Buffer `stdout` and `stderr` during tests')
self.buffer = False
if self.testNamePatterns is None:
parser.add_argument('-k', dest='testNamePatterns',
@@ -197,7 +197,7 @@ class TestProgram(object):
return parser
def _getMainArgParser(self, parent):
parser = argparse.ArgumentParser(parents=[parent], color=True)
parser = argparse.ArgumentParser(parents=[parent])
parser.prog = self.progName
parser.print_help = self._print_help
@@ -208,16 +208,16 @@ class TestProgram(object):
return parser
def _getDiscoveryArgParser(self, parent):
parser = argparse.ArgumentParser(parents=[parent], color=True)
parser = argparse.ArgumentParser(parents=[parent])
parser.prog = '%s discover' % self.progName
parser.epilog = ('For test discovery all test modules must be '
'importable from the top level directory of the '
'project.')
parser.add_argument('-s', '--start-directory', dest='start',
help="Directory to start discovery ('.' default)")
help="Directory to start discovery (`.` default)")
parser.add_argument('-p', '--pattern', dest='pattern',
help="Pattern to match tests ('test*.py' default)")
help="Pattern to match tests (`test*.py` default)")
parser.add_argument('-t', '--top-level-directory', dest='top',
help='Top level directory of project (defaults to '
'start directory)')
+3 -4
View File
@@ -955,7 +955,6 @@ def main():
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description="Generate a UUID using the selected UUID function.",
color=True,
)
parser.add_argument("-u", "--uuid",
choices=uuid_funcs.keys(),
@@ -963,14 +962,14 @@ def main():
help="function to generate the UUID")
parser.add_argument("-n", "--namespace",
metavar=f"{{any UUID,{','.join(namespaces)}}}",
help="uuid3/uuid5 only: "
help="`uuid3`/`uuid5` only: "
"a UUID, or a well-known predefined UUID addressed "
"by namespace name")
parser.add_argument("-N", "--name",
help="uuid3/uuid5 only: "
help="`uuid3`/`uuid5` only: "
"name used as part of generating the UUID")
parser.add_argument("-C", "--count", metavar="NUM", type=int, default=1,
help="generate NUM fresh UUIDs")
help="generate `NUM` fresh UUIDs")
args = parser.parse_args()
uuid_func = uuid_funcs[args.uuid]
-1
View File
@@ -621,7 +621,6 @@ def main(args=None):
'activate it, e.g. by '
'sourcing an activate script '
'in its bin directory.',
color=True,
)
parser.add_argument('dirs', metavar='ENV_DIR', nargs='+',
help='A directory to create the environment in.')
+1 -1
View File
@@ -734,7 +734,7 @@ if sys.platform == "ios":
def parse_args(arg_list: list[str] | None):
import argparse
parser = argparse.ArgumentParser(
description="Open URL in a web browser.", color=True,
description="Open URL in a web browser.",
)
parser.add_argument("url", help="URL to open")
+3 -3
View File
@@ -187,16 +187,16 @@ def main(args=None):
"""
import argparse
parser = argparse.ArgumentParser(color=True)
parser = argparse.ArgumentParser()
parser.add_argument('--output', '-o', default=None,
help="The name of the output archive. "
"Required if SOURCE is an archive.")
"Required if `SOURCE` is an archive.")
parser.add_argument('--python', '-p', default=None,
help="The name of the Python interpreter to use "
"(default: no shebang line).")
parser.add_argument('--main', '-m', default=None,
help="The main function of the application "
"(default: use an existing __main__.py).")
"(default: use an existing `__main__.py`).")
parser.add_argument('--compress', '-c', action='store_true',
help="Compress files with the deflate method. "
"Files are stored uncompressed by default.")
+2 -2
View File
@@ -2328,7 +2328,7 @@ def main(args=None):
import argparse
description = 'A simple command-line interface for zipfile module.'
parser = argparse.ArgumentParser(description=description, color=True)
parser = argparse.ArgumentParser(description=description)
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('-l', '--list', metavar='<zipfile>',
help='Show listing of a zipfile')
@@ -2341,7 +2341,7 @@ def main(args=None):
group.add_argument('-t', '--test', metavar='<zipfile>',
help='Test if a zipfile is valid')
parser.add_argument('--metadata-encoding', metavar='<encoding>',
help='Specify encoding of member names for -l, -e and -t')
help='Specify encoding of member names for `-l`, `-e` and `-t`')
args = parser.parse_args(args)
encoding = args.metadata_encoding
@@ -0,0 +1,2 @@
Add backticks to stdlib argparse help to display in colour. Patch by Hugo
van Kemenade.