Skip to content

Commit b85572c

Browse files
serhiy-storchakamerwokhugovk
authored
gh-90300: Improve the Python CLI help output (GH-115853)
* 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 Co-authored-by: Éric <[email protected]> Co-authored-by: Hugo van Kemenade <[email protected]>
1 parent 61c659e commit b85572c

File tree

1 file changed

+40
-78
lines changed

1 file changed

+40
-78
lines changed

Python/initconfig.c

+40-78
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ Options (and corresponding environment variables):\n\
161161
-P : don't prepend a potentially unsafe path to sys.path; also\n\
162162
PYTHONSAFEPATH\n\
163163
-q : don't print version and copyright messages on interactive startup\n\
164-
-s : don't add user site directory to sys.path; also PYTHONNOUSERSITE\n\
164+
-s : don't add user site directory to sys.path; also PYTHONNOUSERSITE=x\n\
165165
-S : don't imply 'import site' on initialization\n\
166166
-u : force the stdout and stderr streams to be unbuffered;\n\
167167
this option has no effect on stdin; also PYTHONUNBUFFERED=x\n\
@@ -187,67 +187,41 @@ arg ...: arguments passed to program in sys.argv[1:]\n\
187187

188188
static const char usage_xoptions[] = "\
189189
The following implementation-specific options are available:\n\
190-
-X cpu_count=[n|default]: Override the return value of os.cpu_count(),\n\
191-
os.process_cpu_count(), and multiprocessing.cpu_count(). This can\n\
192-
help users who need to limit resources in a container.\n\
193-
-X dev : enable CPython's \"development mode\", introducing additional runtime\n\
194-
checks which are too expensive to be enabled by default. Effect of\n\
195-
the developer mode:\n\
196-
* Add default warning filter, as -W default\n\
197-
* Install debug hooks on memory allocators: see the\n\
198-
PyMem_SetupDebugHooks() C function\n\
199-
* Enable the faulthandler module to dump the Python traceback on\n\
200-
a crash\n\
201-
* Enable asyncio debug mode\n\
202-
* Set the dev_mode attribute of sys.flags to True\n\
203-
* io.IOBase destructor logs close() exceptions\n\
204-
-X faulthandler: enable faulthandler\n\
205-
-X frozen_modules=[on|off]: whether or not frozen modules should be used.\n\
206-
The default is \"on\" (or \"off\" if you are running a local build).\n\
207-
-X importtime: show how long each import takes. It shows module name,\n\
208-
cumulative time (including nested imports) and self time (excluding\n\
209-
nested imports). Note that its output may be broken in\n\
210-
multi-threaded application.\n\
211-
Typical usage is python3 -X importtime -c 'import asyncio'\n\
212-
-X int_max_str_digits=number: limit the size of int<->str conversions.\n\
213-
This helps avoid denial of service attacks when parsing untrusted\n\
214-
data. The default is sys.int_info.default_max_str_digits.\n\
215-
0 disables.\n\
216-
-X no_debug_ranges: disable the inclusion of the tables mapping extra location\n\
217-
information (end line, start column offset and end column offset) to\n\
218-
every instruction in code objects. This is useful when smaller code\n\
219-
objects and pyc files are desired as well as suppressing the extra\n\
220-
visual location indicators when the interpreter displays tracebacks.\n\
221-
-X perf: activate support for the Linux \"perf\" profiler by activating the\n\
222-
\"perf\" trampoline. When this option is activated, the Linux \"perf\"\n\
223-
profiler will be able to report Python calls. This option is only\n\
224-
available on some platforms and will do nothing if is not supported\n\
225-
on the current system. The default value is \"off\".\n\
190+
-X cpu_count=N: override the return value of os.cpu_count();\n\
191+
-X cpu_count=default cancels overriding; also PYTHON_CPU_COUNT\n\
192+
-X dev : enable Python Development Mode; also PYTHONDEVMODE\n\
193+
-X faulthandler: dump the Python traceback on fatal errors;\n\
194+
also PYTHONFAULTHANDLER\n\
195+
-X frozen_modules=[on|off]: whether to use frozen modules; the default is \"on\"\n\
196+
for installed Python and \"off\" for a local build;\n\
197+
also PYTHON_FROZEN_MODULES\n\
198+
-X importtime: show how long each import takes; also PYTHONPROFILEIMPORTTIME\n\
199+
-X int_max_str_digits=N: limit the size of int<->str conversions;\n\
200+
0 disables the limit; also PYTHONINTMAXSTRDIGITS\n\
201+
-X no_debug_ranges: don't include extra location information in code objects;\n\
202+
also PYTHONNODEBUGRANGES\n\
203+
-X perf: support the Linux \"perf\" profiler; also PYTHONPERFSUPPORT=1\n\
226204
"
227205
#ifdef Py_DEBUG
228-
"-X presite=package.module: import this module before site.py is run.\n"
206+
"-X presite=MOD: import this module before site; also PYTHON_PRESITE\n"
229207
#endif
230208
"\
231-
-X pycache_prefix=PATH: enable writing .pyc files to a parallel tree rooted\n\
232-
at the given directory instead of to the code tree\n\
209+
-X pycache_prefix=PATH: write .pyc files to a parallel tree instead of to the\n\
210+
code tree; also PYTHONPYCACHEPREFIX\n\
233211
"
234212
#ifdef Py_STATS
235-
"-X pystats: Enable pystats collection at startup.\n"
213+
"-X pystats: enable pystats collection at startup; also PYTHONSTATS\n"
236214
#endif
237215
"\
238216
-X showrefcount: output the total reference count and number of used\n\
239217
memory blocks when the program finishes or after each statement in\n\
240-
the interactive interpreter. This only works on debug builds\n\
241-
-X tracemalloc: start tracing Python memory allocations using the\n\
242-
tracemalloc module. By default, only the most recent frame is stored\n\
243-
in a traceback of a trace. Use -X tracemalloc=NFRAME to start\n\
244-
tracing with a traceback limit of NFRAME frames\n\
245-
-X utf8: enable UTF-8 mode for operating system interfaces, overriding the\n\
246-
default locale-aware mode. -X utf8=0 explicitly disables UTF-8 mode\n\
247-
(even when it would otherwise activate automatically)\n\
248-
-X warn_default_encoding: enable opt-in EncodingWarning for 'encoding=None'\
249-
"
250-
;
218+
the interactive interpreter; only works on debug builds\n\
219+
-X tracemalloc[=N]: trace Python memory allocations; N sets a traceback limit\n\
220+
of N frames (default: 1); also PYTHONTRACEMALLOC=N\n\
221+
-X utf8[=0|1]: enable (1) or disable (0) UTF-8 mode; also PYTHONUTF8\n\
222+
-X warn_default_encoding: enable opt-in EncodingWarning for 'encoding=None';\n\
223+
also PYTHONWARNDEFAULTENCODING\
224+
";
251225

252226
/* Envvars that don't have equivalent command-line options are listed first */
253227
static const char usage_envvars[] =
@@ -257,9 +231,9 @@ static const char usage_envvars[] =
257231
" default module search path. The result is sys.path.\n"
258232
"PYTHONHOME : alternate <prefix> directory (or <prefix>%lc<exec_prefix>).\n"
259233
" The default module search path uses %s.\n"
260-
"PYTHONPLATLIBDIR: override sys.platlibdir.\n"
261-
"PYTHONCASEOK : ignore case in 'import' statements (Windows).\n"
262-
"PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.\n"
234+
"PYTHONPLATLIBDIR: override sys.platlibdir\n"
235+
"PYTHONCASEOK : ignore case in 'import' statements (Windows)\n"
236+
"PYTHONIOENCODING: encoding[:errors] used for stdin/stdout/stderr\n"
263237
"PYTHONHASHSEED : if this variable is set to 'random', a random value is used\n"
264238
" to seed the hashes of str and bytes objects. It can also be\n"
265239
" set to an integer in the range [0,4294967295] to get hash\n"
@@ -280,39 +254,27 @@ static const char usage_envvars[] =
280254
"PYTHON_HISTORY : the location of a .python_history file.\n"
281255
"\n"
282256
"These variables have equivalent command-line options (see --help for details):\n"
283-
"PYTHON_CPU_COUNT: Overrides the return value of os.process_cpu_count(),\n"
284-
" os.cpu_count(), and multiprocessing.cpu_count() if set to\n"
285-
" a positive integer. (-X cpu_count)\n"
257+
"PYTHON_CPU_COUNT: override the return value of os.cpu_count() (-X cpu_count)\n"
286258
"PYTHONDEBUG : enable parser debug mode (-d)\n"
287-
"PYTHONDEVMODE : enable the development mode (-X dev)\n"
259+
"PYTHONDEVMODE : enable Python Development Mode (-X dev)\n"
288260
"PYTHONDONTWRITEBYTECODE: don't write .pyc files (-B)\n"
289261
"PYTHONFAULTHANDLER: dump the Python traceback on fatal errors (-X faulthandler)\n"
290-
"PYTHON_FROZEN_MODULES: if this variable is set, it determines whether or not\n"
291-
" frozen modules should be used. The default is \"on\" (or\n"
292-
" \"off\" if you are running a local build).\n"
262+
"PYTHON_FROZEN_MODULES: whether to use frozen modules; the default is \"on\"\n"
263+
" for installed Python and \"off\" for a local build\n"
293264
" (-X frozen_modules)\n"
294265
#ifdef Py_GIL_DISABLED
295266
"PYTHON_GIL : when set to 0, disables the GIL (-X gil)\n"
296267
#endif
297268
"PYTHONINSPECT : inspect interactively after running script (-i)\n"
298-
"PYTHONINTMAXSTRDIGITS: limits the maximum digit characters in an int value\n"
299-
" when converting from a string and when converting an int\n"
300-
" back to a str. A value of 0 disables the limit.\n"
301-
" Conversions to or from bases 2, 4, 8, 16, and 32 are never\n"
302-
" limited.\n"
303-
" (-X int_max_str_digits=number)\n"
304-
"PYTHONNODEBUGRANGES: if this variable is set, it disables the inclusion of\n"
305-
" the tables mapping extra location information (end line,\n"
306-
" start column offset and end column offset) to every\n"
307-
" instruction in code objects. This is useful when smaller\n"
308-
" code objects and pyc files are desired as well as\n"
309-
" suppressing the extra visual location indicators when the\n"
310-
" interpreter displays tracebacks. (-X no_debug_ranges)\n"
269+
"PYTHONINTMAXSTRDIGITS: limit the size of int<->str conversions;\n"
270+
" 0 disables the limit (-X int_max_str_digits=N)\n"
271+
"PYTHONNODEBUGRANGES: don't include extra location information in code objects\n"
272+
" (-X no_debug_ranges)\n"
311273
"PYTHONNOUSERSITE: disable user site directory (-s)\n"
312274
"PYTHONOPTIMIZE : enable level 1 optimizations (-O)\n"
313275
"PYTHONPERFSUPPORT: support the Linux \"perf\" profiler (-X perf)\n"
314276
#ifdef Py_DEBUG
315-
"PYTHON_PRESITE=pkg.mod: import this module before site.py is run (-X presite)\n"
277+
"PYTHON_PRESITE: import this module before site (-X presite)\n"
316278
#endif
317279
"PYTHONPROFILEIMPORTTIME: show how long each import takes (-X importtime)\n"
318280
"PYTHONPYCACHEPREFIX: root directory for bytecode cache (pyc) files\n"
@@ -323,11 +285,11 @@ static const char usage_envvars[] =
323285
#endif
324286
"PYTHONTRACEMALLOC: trace Python memory allocations (-X tracemalloc)\n"
325287
"PYTHONUNBUFFERED: disable stdout/stderr buffering (-u)\n"
326-
"PYTHONUTF8 : if set to 1, enable the UTF-8 mode (-X utf8)\n"
288+
"PYTHONUTF8 : control the UTF-8 mode (-X utf8)\n"
327289
"PYTHONVERBOSE : trace import statements (-v)\n"
328290
"PYTHONWARNDEFAULTENCODING: enable opt-in EncodingWarning for 'encoding=None'\n"
329291
" (-X warn_default_encoding)\n"
330-
"PYTHONWARNINGS=arg: warning control (-W arg)\n"
292+
"PYTHONWARNINGS : warning control (-W)\n"
331293
;
332294

333295
#if defined(MS_WINDOWS)

0 commit comments

Comments
 (0)