Skip to content

Commit 4be9fa8

Browse files
serhiy-storchakamerwokhugovk
authored
[3.12] gh-90300: Improve the Python CLI help output (GH-115853) (GH-117022)
* document equivalent command-line options for all environment variables * document equivalent environment variables for all command-line options * reduce the size of variable and option descriptions to minimum * remove the ending period in single-sentence descriptions (cherry picked from commit b85572c) Co-authored-by: Éric <merwok@netwok.org> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
1 parent 05b2b30 commit 4be9fa8

File tree

1 file changed

+38
-67
lines changed

1 file changed

+38
-67
lines changed

Python/initconfig.c

+38-67
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Options (and corresponding environment variables):\n\
5252
-P : don't prepend a potentially unsafe path to sys.path; also\n\
5353
PYTHONSAFEPATH\n\
5454
-q : don't print version and copyright messages on interactive startup\n\
55-
-s : don't add user site directory to sys.path; also PYTHONNOUSERSITE\n\
55+
-s : don't add user site directory to sys.path; also PYTHONNOUSERSITE=x\n\
5656
-S : don't imply 'import site' on initialization\n\
5757
-u : force the stdout and stderr streams to be unbuffered;\n\
5858
this option has no effect on stdin; also PYTHONUNBUFFERED=x\n\
@@ -78,59 +78,39 @@ arg ...: arguments passed to program in sys.argv[1:]\n\
7878

7979
static const char usage_xoptions[] = "\
8080
The following implementation-specific options are available:\n\
81-
-X dev : enable CPython's \"development mode\", introducing additional runtime\n\
82-
checks which are too expensive to be enabled by default. Effect of\n\
83-
the developer mode:\n\
84-
* Add default warning filter, as -W default\n\
85-
* Install debug hooks on memory allocators: see the\n\
86-
PyMem_SetupDebugHooks() C function\n\
87-
* Enable the faulthandler module to dump the Python traceback on\n\
88-
a crash\n\
89-
* Enable asyncio debug mode\n\
90-
* Set the dev_mode attribute of sys.flags to True\n\
91-
* io.IOBase destructor logs close() exceptions\n\
92-
-X faulthandler: enable faulthandler\n\
93-
-X frozen_modules=[on|off]: whether or not frozen modules should be used.\n\
94-
The default is \"on\" (or \"off\" if you are running a local build).\n\
95-
-X importtime: show how long each import takes. It shows module name,\n\
96-
cumulative time (including nested imports) and self time (excluding\n\
97-
nested imports). Note that its output may be broken in\n\
98-
multi-threaded application.\n\
99-
Typical usage is python3 -X importtime -c 'import asyncio'\n\
100-
-X int_max_str_digits=number: limit the size of int<->str conversions.\n\
101-
This helps avoid denial of service attacks when parsing untrusted\n\
102-
data. The default is sys.int_info.default_max_str_digits.\n\
103-
0 disables.\n\
104-
-X no_debug_ranges: disable the inclusion of the tables mapping extra location\n\
105-
information (end line, start column offset and end column offset) to\n\
106-
every instruction in code objects. This is useful when smaller code\n\
107-
objects and pyc files are desired as well as suppressing the extra\n\
108-
visual location indicators when the interpreter displays tracebacks.\n\
109-
-X perf: activate support for the Linux \"perf\" profiler by activating the\n\
110-
\"perf\" trampoline. When this option is activated, the Linux \"perf\"\n\
111-
profiler will be able to report Python calls. This option is only\n\
112-
available on some platforms and will do nothing if is not supported\n\
113-
on the current system. The default value is \"off\".\n\
114-
-X pycache_prefix=PATH: enable writing .pyc files to a parallel tree rooted\n\
115-
at the given directory instead of to the code tree\n\
81+
-X dev : enable Python Development Mode; also PYTHONDEVMODE\n\
82+
-X faulthandler: dump the Python traceback on fatal errors;\n\
83+
also PYTHONFAULTHANDLER\n\
84+
-X frozen_modules=[on|off]: whether to use frozen modules; the default is \"on\"\n\
85+
for installed Python and \"off\" for a local build;\n\
86+
also PYTHON_FROZEN_MODULES\n\
87+
-X importtime: show how long each import takes; also PYTHONPROFILEIMPORTTIME\n\
88+
-X int_max_str_digits=N: limit the size of int<->str conversions;\n\
89+
0 disables the limit; also PYTHONINTMAXSTRDIGITS\n\
90+
-X no_debug_ranges: don't include extra location information in code objects;\n\
91+
also PYTHONNODEBUGRANGES\n\
92+
-X perf: support the Linux \"perf\" profiler; also PYTHONPERFSUPPORT=1\n\
93+
"
94+
#ifdef Py_DEBUG
95+
"-X presite=MOD: import this module before site; also PYTHON_PRESITE\n"
96+
#endif
97+
"\
98+
-X pycache_prefix=PATH: write .pyc files to a parallel tree instead of to the\n\
99+
code tree; also PYTHONPYCACHEPREFIX\n\
116100
"
117101
#ifdef Py_STATS
118-
"-X pystats: Enable pystats collection at startup.\n"
102+
"-X pystats: enable pystats collection at startup; also PYTHONSTATS\n"
119103
#endif
120104
"\
121105
-X showrefcount: output the total reference count and number of used\n\
122106
memory blocks when the program finishes or after each statement in\n\
123-
the interactive interpreter. This only works on debug builds\n\
124-
-X tracemalloc: start tracing Python memory allocations using the\n\
125-
tracemalloc module. By default, only the most recent frame is stored\n\
126-
in a traceback of a trace. Use -X tracemalloc=NFRAME to start\n\
127-
tracing with a traceback limit of NFRAME frames\n\
128-
-X utf8: enable UTF-8 mode for operating system interfaces, overriding the\n\
129-
default locale-aware mode. -X utf8=0 explicitly disables UTF-8 mode\n\
130-
(even when it would otherwise activate automatically)\n\
131-
-X warn_default_encoding: enable opt-in EncodingWarning for 'encoding=None'\
132-
"
133-
;
107+
the interactive interpreter; only works on debug builds\n\
108+
-X tracemalloc[=N]: trace Python memory allocations; N sets a traceback limit\n\
109+
of N frames (default: 1); also PYTHONTRACEMALLOC=N\n\
110+
-X utf8[=0|1]: enable (1) or disable (0) UTF-8 mode; also PYTHONUTF8\n\
111+
-X warn_default_encoding: enable opt-in EncodingWarning for 'encoding=None';\n\
112+
also PYTHONWARNDEFAULTENCODING\
113+
";
134114

135115
/* Envvars that don't have equivalent command-line options are listed first */
136116
static const char usage_envvars[] =
@@ -140,9 +120,9 @@ static const char usage_envvars[] =
140120
" default module search path. The result is sys.path.\n"
141121
"PYTHONHOME : alternate <prefix> directory (or <prefix>%lc<exec_prefix>).\n"
142122
" The default module search path uses %s.\n"
143-
"PYTHONPLATLIBDIR: override sys.platlibdir.\n"
144-
"PYTHONCASEOK : ignore case in 'import' statements (Windows).\n"
145-
"PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.\n"
123+
"PYTHONPLATLIBDIR: override sys.platlibdir\n"
124+
"PYTHONCASEOK : ignore case in 'import' statements (Windows)\n"
125+
"PYTHONIOENCODING: encoding[:errors] used for stdin/stdout/stderr\n"
146126
"PYTHONHASHSEED : if this variable is set to 'random', a random value is used\n"
147127
" to seed the hashes of str and bytes objects. It can also be\n"
148128
" set to an integer in the range [0,4294967295] to get hash\n"
@@ -160,23 +140,14 @@ static const char usage_envvars[] =
160140
"\n"
161141
"These variables have equivalent command-line options (see --help for details):\n"
162142
"PYTHONDEBUG : enable parser debug mode (-d)\n"
163-
"PYTHONDEVMODE : enable the development mode (-X dev)\n"
143+
"PYTHONDEVMODE : enable Python Development Mode (-X dev)\n"
164144
"PYTHONDONTWRITEBYTECODE: don't write .pyc files (-B)\n"
165145
"PYTHONFAULTHANDLER: dump the Python traceback on fatal errors (-X faulthandler)\n"
166146
"PYTHONINSPECT : inspect interactively after running script (-i)\n"
167-
"PYTHONINTMAXSTRDIGITS: limits the maximum digit characters in an int value\n"
168-
" when converting from a string and when converting an int\n"
169-
" back to a str. A value of 0 disables the limit.\n"
170-
" Conversions to or from bases 2, 4, 8, 16, and 32 are never\n"
171-
" limited.\n"
172-
" (-X int_max_str_digits=number)\n"
173-
"PYTHONNODEBUGRANGES: if this variable is set, it disables the inclusion of\n"
174-
" the tables mapping extra location information (end line,\n"
175-
" start column offset and end column offset) to every\n"
176-
" instruction in code objects. This is useful when smaller\n"
177-
" code objects and pyc files are desired as well as\n"
178-
" suppressing the extra visual location indicators when the\n"
179-
" interpreter displays tracebacks. (-X no_debug_ranges)\n"
147+
"PYTHONINTMAXSTRDIGITS: limit the size of int<->str conversions;\n"
148+
" 0 disables the limit (-X int_max_str_digits=N)\n"
149+
"PYTHONNODEBUGRANGES: don't include extra location information in code objects\n"
150+
" (-X no_debug_ranges)\n"
180151
"PYTHONNOUSERSITE: disable user site directory (-s)\n"
181152
"PYTHONOPTIMIZE : enable level 1 optimizations (-O)\n"
182153
"PYTHONPERFSUPPORT: support the Linux \"perf\" profiler (-X perf)\n"
@@ -186,11 +157,11 @@ static const char usage_envvars[] =
186157
"PYTHONSAFEPATH : don't prepend a potentially unsafe path to sys.path.\n"
187158
"PYTHONTRACEMALLOC: trace Python memory allocations (-X tracemalloc)\n"
188159
"PYTHONUNBUFFERED: disable stdout/stderr buffering (-u)\n"
189-
"PYTHONUTF8 : if set to 1, enable the UTF-8 mode (-X utf8)\n"
160+
"PYTHONUTF8 : control the UTF-8 mode (-X utf8)\n"
190161
"PYTHONVERBOSE : trace import statements (-v)\n"
191162
"PYTHONWARNDEFAULTENCODING: enable opt-in EncodingWarning for 'encoding=None'\n"
192163
" (-X warn_default_encoding)\n"
193-
"PYTHONWARNINGS=arg: warning control (-W arg)\n"
164+
"PYTHONWARNINGS : warning control (-W)\n"
194165
;
195166

196167
#if defined(MS_WINDOWS)

0 commit comments

Comments
 (0)