[3.12] gh-90300: Reformat the Python CLI help output (GH-93415) (#115847)

(cherry picked from commit 2e92ffd7fa)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Łukasz Langa 2024-02-23 18:23:16 +01:00 committed by GitHub
parent 73921f4c57
commit 2bdd1d6f15
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -49,7 +49,8 @@ Options (and corresponding environment variables):\n\
.pyc extension; also PYTHONOPTIMIZE=x\n\ .pyc extension; also PYTHONOPTIMIZE=x\n\
-OO : do -O changes and also discard docstrings; add .opt-2 before\n\ -OO : do -O changes and also discard docstrings; add .opt-2 before\n\
.pyc extension\n\ .pyc extension\n\
-P : don't prepend a potentially unsafe path to sys.path; also PYTHONSAFEPATH\n\ -P : don't prepend a potentially unsafe path to sys.path; also\n\
PYTHONSAFEPATH\n\
-q : don't print version and copyright messages on interactive startup\n\ -q : don't print version and copyright messages on interactive startup\n\
-s : don't add user site directory to sys.path; also PYTHONNOUSERSITE\n\ -s : don't add user site directory to sys.path; also PYTHONNOUSERSITE\n\
-S : don't imply 'import site' on initialization\n\ -S : don't imply 'import site' on initialization\n\
@ -65,9 +66,10 @@ Options (and corresponding environment variables):\n\
-X opt : set implementation-specific option\n\ -X opt : set implementation-specific option\n\
--check-hash-based-pycs always|default|never:\n\ --check-hash-based-pycs always|default|never:\n\
control how Python invalidates hash-based .pyc files\n\ control how Python invalidates hash-based .pyc files\n\
--help-env : print help about Python environment variables and exit\n\ --help-env: print help about Python environment variables and exit\n\
--help-xoptions : print help about implementation-specific -X options and exit\n\ --help-xoptions: print help about implementation-specific -X options and exit\n\
--help-all : print complete help information and exit\n\ --help-all: print complete help information and exit\n\
\n\
Arguments:\n\ Arguments:\n\
file : program read from script file\n\ file : program read from script file\n\
- : program read from stdin (default; interactive mode if a tty)\n\ - : program read from stdin (default; interactive mode if a tty)\n\
@ -76,64 +78,55 @@ arg ...: arguments passed to program in sys.argv[1:]\n\
static const char usage_xoptions[] = "\ static const char usage_xoptions[] = "\
The following implementation-specific options are available:\n\ The following implementation-specific options are available:\n\
\n\
-X faulthandler: enable faulthandler\n\ -X faulthandler: enable faulthandler\n\
\n\
-X showrefcount: output the total reference count and number of used\n\ -X showrefcount: output the total reference count and number of used\n\
memory blocks when the program finishes or after each statement in the\n\ memory blocks when the program finishes or after each statement in\n\
interactive interpreter. This only works on debug builds\n\ the interactive interpreter. This only works on debug builds\n\
\n\
-X tracemalloc: start tracing Python memory allocations using the\n\ -X tracemalloc: start tracing Python memory allocations using the\n\
tracemalloc module. By default, only the most recent frame is stored in a\n\ tracemalloc module. By default, only the most recent frame is stored\n\
traceback of a trace. Use -X tracemalloc=NFRAME to start tracing with a\n\ in a traceback of a trace. Use -X tracemalloc=NFRAME to start\n\
traceback limit of NFRAME frames\n\ tracing with a traceback limit of NFRAME frames\n\
\n\ -X importtime: show how long each import takes. It shows module name,\n\
-X importtime: show how long each import takes. It shows module name,\n\ cumulative time (including nested imports) and self time (excluding\n\
cumulative time (including nested imports) and self time (excluding\n\ nested imports). Note that its output may be broken in\n\
nested imports). Note that its output may be broken in multi-threaded\n\ multi-threaded application.\n\
application. Typical usage is python3 -X importtime -c 'import asyncio'\n\ Typical usage is python3 -X importtime -c 'import asyncio'\n\
\n\ -X dev : enable CPython's \"development mode\", introducing additional runtime\n\
-X dev: enable CPython's \"development mode\", introducing additional runtime\n\ checks which are too expensive to be enabled by default. Effect of\n\
checks which are too expensive to be enabled by default. Effect of the\n\ the developer mode:\n\
developer mode:\n\ * Add default warning filter, as -W default\n\
* Add default warning filter, as -W default\n\ * Install debug hooks on memory allocators: see the\n\
* Install debug hooks on memory allocators: see the PyMem_SetupDebugHooks()\n\ PyMem_SetupDebugHooks() C function\n\
C function\n\ * Enable the faulthandler module to dump the Python traceback on\n\
* Enable the faulthandler module to dump the Python traceback on a crash\n\ a crash\n\
* Enable asyncio debug mode\n\ * Enable asyncio debug mode\n\
* Set the dev_mode attribute of sys.flags to True\n\ * Set the dev_mode attribute of sys.flags to True\n\
* io.IOBase destructor logs close() exceptions\n\ * io.IOBase destructor logs close() exceptions\n\
\n\ -X utf8: enable UTF-8 mode for operating system interfaces, overriding the\n\
-X utf8: enable UTF-8 mode for operating system interfaces, overriding the default\n\ default locale-aware mode. -X utf8=0 explicitly disables UTF-8 mode\n\
locale-aware mode. -X utf8=0 explicitly disables UTF-8 mode (even when it would\n\ (even when it would otherwise activate automatically)\n\
otherwise activate automatically)\n\ -X pycache_prefix=PATH: enable writing .pyc files to a parallel tree rooted\n\
\n\ at the given directory instead of to the code tree\n\
-X pycache_prefix=PATH: enable writing .pyc files to a parallel tree rooted at the\n\
given directory instead of to the code tree\n\
\n\
-X warn_default_encoding: enable opt-in EncodingWarning for 'encoding=None'\n\ -X warn_default_encoding: enable opt-in EncodingWarning for 'encoding=None'\n\
\n\ -X no_debug_ranges: disable the inclusion of the tables mapping extra location\n\
-X no_debug_ranges: disable the inclusion of the tables mapping extra location \n\ information (end line, start column offset and end column offset) to\n\
information (end line, start column offset and end column offset) to every \n\ every instruction in code objects. This is useful when smaller code\n\
instruction in code objects. This is useful when smaller code objects and pyc \n\ objects and pyc files are desired as well as suppressing the extra\n\
files are desired as well as suppressing the extra visual location indicators \n\ visual location indicators when the interpreter displays tracebacks.\n\
when the interpreter displays tracebacks.\n\ -X perf: activate support for the Linux \"perf\" profiler by activating the\n\
\n\ \"perf\" trampoline. When this option is activated, the Linux \"perf\"\n\
-X perf: activate support for the Linux \"perf\" profiler by activating the \"perf\"\n\ profiler will be able to report Python calls. This option is only\n\
trampoline. When this option is activated, the Linux \"perf\" profiler will be \n\ available on some platforms and will do nothing if is not supported\n\
able to report Python calls. This option is only available on some platforms and will \n\ on the current system. The default value is \"off\".\n\
do nothing if is not supported on the current system. The default value is \"off\".\n\
\n\
-X frozen_modules=[on|off]: whether or not frozen modules should be used.\n\ -X frozen_modules=[on|off]: whether or not frozen modules should be used.\n\
The default is \"on\" (or \"off\" if you are running a local build).\n\ The default is \"on\" (or \"off\" if you are running a local build).\n\
\n\
-X int_max_str_digits=number: limit the size of int<->str conversions.\n\ -X int_max_str_digits=number: limit the size of int<->str conversions.\n\
This helps avoid denial of service attacks when parsing untrusted data.\n\ This helps avoid denial of service attacks when parsing untrusted\n\
The default is sys.int_info.default_max_str_digits. 0 disables." data. The default is sys.int_info.default_max_str_digits.\n\
0 disables.\
"
#ifdef Py_STATS #ifdef Py_STATS
"\n\ "\n\
\n\
-X pystats: Enable pystats collection at startup." -X pystats: Enable pystats collection at startup."
#endif #endif
; ;
@ -141,52 +134,59 @@ The following implementation-specific options are available:\n\
/* Envvars that don't have equivalent command-line options are listed first */ /* Envvars that don't have equivalent command-line options are listed first */
static const char usage_envvars[] = static const char usage_envvars[] =
"Environment variables that change behavior:\n" "Environment variables that change behavior:\n"
"PYTHONSTARTUP: file executed on interactive startup (no default)\n" "PYTHONSTARTUP : file executed on interactive startup (no default)\n"
"PYTHONPATH : '%lc'-separated list of directories prefixed to the\n" "PYTHONPATH : '%lc'-separated list of directories prefixed to the\n"
" default module search path. The result is sys.path.\n" " default module search path. The result is sys.path.\n"
"PYTHONHOME : alternate <prefix> directory (or <prefix>%lc<exec_prefix>).\n" "PYTHONHOME : alternate <prefix> directory (or <prefix>%lc<exec_prefix>).\n"
" The default module search path uses %s.\n" " The default module search path uses %s.\n"
"PYTHONPLATLIBDIR : override sys.platlibdir.\n" "PYTHONPLATLIBDIR: override sys.platlibdir.\n"
"PYTHONCASEOK : ignore case in 'import' statements (Windows).\n" "PYTHONCASEOK : ignore case in 'import' statements (Windows).\n"
"PYTHONUTF8: if set to 1, enable the UTF-8 mode.\n" "PYTHONUTF8 : if set to 1, enable the UTF-8 mode.\n"
"PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.\n" "PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.\n"
"PYTHONFAULTHANDLER: dump the Python traceback on fatal errors.\n" "PYTHONFAULTHANDLER: dump the Python traceback on fatal errors.\n"
"PYTHONHASHSEED: if this variable is set to 'random', a random value is used\n" "PYTHONHASHSEED : if this variable is set to 'random', a random value is used\n"
" to seed the hashes of str and bytes objects. It can also be set to an\n" " to seed the hashes of str and bytes objects. It can also be\n"
" integer in the range [0,4294967295] to get hash values with a\n" " set to an integer in the range [0,4294967295] to get hash\n"
" predictable seed.\n" " values with a predictable seed.\n"
"PYTHONINTMAXSTRDIGITS: limits the maximum digit characters in an int value\n" "PYTHONINTMAXSTRDIGITS: limits the maximum digit characters in an int value\n"
" when converting from a string and when converting an int back to a str.\n" " when converting from a string and when converting an int\n"
" A value of 0 disables the limit. Conversions to or from bases 2, 4, 8,\n" " back to a str. A value of 0 disables the limit.\n"
" 16, and 32 are never limited.\n" " Conversions to or from bases 2, 4, 8, 16, and 32 are never\n"
"PYTHONMALLOC: set the Python memory allocators and/or install debug hooks\n" " limited.\n"
" on Python memory allocators. Use PYTHONMALLOC=debug to install debug\n" "PYTHONMALLOC : set the Python memory allocators and/or install debug hooks\n"
" hooks.\n" " on Python memory allocators. Use PYTHONMALLOC=debug to\n"
" install debug hooks.\n"
"PYTHONCOERCECLOCALE: if this variable is set to 0, it disables the locale\n" "PYTHONCOERCECLOCALE: if this variable is set to 0, it disables the locale\n"
" coercion behavior. Use PYTHONCOERCECLOCALE=warn to request display of\n" " coercion behavior. Use PYTHONCOERCECLOCALE=warn to request\n"
" locale coercion and locale compatibility warnings on stderr.\n" " display of locale coercion and locale compatibility warnings\n"
" on stderr.\n"
"PYTHONBREAKPOINT: if this variable is set to 0, it disables the default\n" "PYTHONBREAKPOINT: if this variable is set to 0, it disables the default\n"
" debugger. It can be set to the callable of your debugger of choice.\n" " debugger. It can be set to the callable of your debugger of\n"
"PYTHONDEVMODE: enable the development mode.\n" " choice.\n"
"PYTHONDEVMODE : enable the development mode.\n"
"PYTHONPYCACHEPREFIX: root directory for bytecode cache (pyc) files.\n" "PYTHONPYCACHEPREFIX: root directory for bytecode cache (pyc) files.\n"
"PYTHONWARNDEFAULTENCODING: enable opt-in EncodingWarning for 'encoding=None'.\n" "PYTHONWARNDEFAULTENCODING: enable opt-in EncodingWarning for 'encoding=None'.\n"
"PYTHONNODEBUGRANGES: If this variable is set, it disables the inclusion of the \n" "PYTHONNODEBUGRANGES: if this variable is set, it disables the inclusion of\n"
" tables mapping extra location information (end line, start column offset \n" " the tables mapping extra location information (end line,\n"
" and end column offset) to every instruction in code objects. This is useful \n" " start column offset and end column offset) to every\n"
" when smaller code objects and pyc files are desired as well as suppressing the \n" " instruction in code objects. This is useful when smaller\n"
" extra visual location indicators when the interpreter displays tracebacks.\n" " code objects and pyc files are desired as well as\n"
"These variables have equivalent command-line parameters (see --help for details):\n" " suppressing the extra visual location indicators when the\n"
"PYTHONDEBUG : enable parser debug mode (-d)\n" " interpreter displays tracebacks.\n"
"PYTHONDONTWRITEBYTECODE : don't write .pyc files (-B)\n" "\n"
"PYTHONINSPECT : inspect interactively after running script (-i)\n" "These variables have equivalent command-line options (see --help for details):\n"
"PYTHONINTMAXSTRDIGITS : limit max digit characters in an int value\n" "PYTHONDEBUG : enable parser debug mode (-d)\n"
" (-X int_max_str_digits=number)\n" "PYTHONDONTWRITEBYTECODE: don't write .pyc files (-B)\n"
"PYTHONNOUSERSITE : disable user site directory (-s)\n" "PYTHONINSPECT : inspect interactively after running script (-i)\n"
"PYTHONOPTIMIZE : enable level 1 optimizations (-O)\n" "PYTHONINTMAXSTRDIGITS: limit max digit characters in an int value\n"
"PYTHONSAFEPATH : don't prepend a potentially unsafe path to sys.path (-P)\n" " (-X int_max_str_digits=number)\n"
"PYTHONUNBUFFERED : disable stdout/stderr buffering (-u)\n" "PYTHONNOUSERSITE: disable user site directory (-s)\n"
"PYTHONVERBOSE : trace import statements (-v)\n" "PYTHONOPTIMIZE : enable level 1 optimizations (-O)\n"
"PYTHONWARNINGS=arg : warning control (-W arg)\n"; "PYTHONSAFEPATH : don't prepend a potentially unsafe path to sys.path.\n"
"PYTHONUNBUFFERED: disable stdout/stderr buffering (-u)\n"
"PYTHONVERBOSE : trace import statements (-v)\n"
"PYTHONWARNINGS=arg: warning control (-W arg)\n"
;
#if defined(MS_WINDOWS) #if defined(MS_WINDOWS)
# define PYTHONHOMEHELP "<prefix>\\python{major}{minor}" # define PYTHONHOMEHELP "<prefix>\\python{major}{minor}"
@ -2370,9 +2370,9 @@ static void
config_complete_usage(const wchar_t* program) config_complete_usage(const wchar_t* program)
{ {
config_usage(0, program); config_usage(0, program);
puts("\n"); putchar('\n');
config_envvars_usage(); config_envvars_usage();
puts("\n"); putchar('\n');
config_xoptions_usage(); config_xoptions_usage();
} }