Skip to content

Commit b062f39

Browse files
authored
gh-145990: Sort python --help-xoptions by option name (GH-145991)
* Sort --help-xoptions alphabetically by name. * add a sorting regression test in test_help_xoptions
1 parent f7cb789 commit b062f39

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

Lib/test/test_cmd_line.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# See test_cmd_line_script.py for testing of script execution
44

55
import os
6+
import re
67
import subprocess
78
import sys
89
import sysconfig
@@ -64,6 +65,9 @@ def test_help_env(self):
6465
def test_help_xoptions(self):
6566
out = self.verify_valid_flag('--help-xoptions')
6667
self.assertIn(b'-X dev', out)
68+
options = re.findall(rb'^-X (\w+)', out, re.MULTILINE)
69+
self.assertEqual(options, sorted(options),
70+
"options should be sorted alphabetically")
6771

6872
@support.cpython_only
6973
def test_help_all(self):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``python --help-xoptions`` is now sorted by ``-X`` option name.

Python/initconfig.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,15 @@ arg ...: arguments passed to program in sys.argv[1:]\n\
304304

305305
static const char usage_xoptions[] = "\
306306
The following implementation-specific options are available:\n\
307+
-X context_aware_warnings=[0|1]: if true (1) then the warnings module will\n\
308+
use a context variables; if false (0) then the warnings module will\n\
309+
use module globals, which is not concurrent-safe; set to true for\n\
310+
free-threaded builds and false otherwise; also\n\
311+
PYTHON_CONTEXT_AWARE_WARNINGS\n\
307312
-X cpu_count=N: override the return value of os.cpu_count();\n\
308313
-X cpu_count=default cancels overriding; also PYTHON_CPU_COUNT\n\
309314
-X dev : enable Python Development Mode; also PYTHONDEVMODE\n\
315+
-X disable-remote-debug: disable remote debugging; also PYTHON_DISABLE_REMOTE_DEBUG\n\
310316
-X faulthandler: dump the Python traceback on fatal errors;\n\
311317
also PYTHONFAULTHANDLER\n\
312318
-X frozen_modules=[on|off]: whether to use frozen modules; the default is \"on\"\n\
@@ -319,16 +325,18 @@ The following implementation-specific options are available:\n\
319325
"\
320326
-X importtime[=2]: show how long each import takes; use -X importtime=2 to\n\
321327
log imports of already-loaded modules; also PYTHONPROFILEIMPORTTIME\n\
322-
-X lazy_imports=[all|none|normal]: control global lazy imports;\n\
323-
default is normal; also PYTHON_LAZY_IMPORTS\n\
324328
-X int_max_str_digits=N: limit the size of int<->str conversions;\n\
325329
0 disables the limit; also PYTHONINTMAXSTRDIGITS\n\
330+
-X lazy_imports=[all|none|normal]: control global lazy imports;\n\
331+
default is normal; also PYTHON_LAZY_IMPORTS\n\
326332
-X no_debug_ranges: don't include extra location information in code objects;\n\
327333
also PYTHONNODEBUGRANGES\n\
334+
-X pathconfig_warnings=[0|1]: if true (1) then path configuration is allowed\n\
335+
to log warnings into stderr; if false (0) suppress these warnings;\n\
336+
set to true by default; also PYTHON_PATHCONFIG_WARNINGS\n\
328337
-X perf: support the Linux \"perf\" profiler; also PYTHONPERFSUPPORT=1\n\
329338
-X perf_jit: support the Linux \"perf\" profiler with DWARF support;\n\
330339
also PYTHON_PERF_JIT_SUPPORT=1\n\
331-
-X disable-remote-debug: disable remote debugging; also PYTHON_DISABLE_REMOTE_DEBUG\n\
332340
"
333341
#ifdef Py_DEBUG
334342
"-X presite=MOD: import this module before site; also PYTHON_PRESITE\n"
@@ -343,24 +351,17 @@ The following implementation-specific options are available:\n\
343351
"\
344352
-X showrefcount: output the total reference count and number of used\n\
345353
memory blocks when the program finishes or after each statement in\n\
346-
the interactive interpreter; only works on debug builds\n"
354+
the interactive interpreter; only works on debug builds\n\
355+
-X thread_inherit_context=[0|1]: enable (1) or disable (0) threads inheriting\n\
356+
context vars by default; enabled by default in the free-threaded\n\
357+
build and disabled otherwise; also PYTHON_THREAD_INHERIT_CONTEXT\n\
358+
"
347359
#ifdef Py_GIL_DISABLED
348360
"-X tlbc=[0|1]: enable (1) or disable (0) thread-local bytecode. Also\n\
349361
PYTHON_TLBC\n"
350362
#endif
351363
"\
352-
-X thread_inherit_context=[0|1]: enable (1) or disable (0) threads inheriting\n\
353-
context vars by default; enabled by default in the free-threaded\n\
354-
build and disabled otherwise; also PYTHON_THREAD_INHERIT_CONTEXT\n\
355-
-X context_aware_warnings=[0|1]: if true (1) then the warnings module will\n\
356-
use a context variables; if false (0) then the warnings module will\n\
357-
use module globals, which is not concurrent-safe; set to true for\n\
358-
free-threaded builds and false otherwise; also\n\
359-
PYTHON_CONTEXT_AWARE_WARNINGS\n\
360-
-X pathconfig_warnings=[0|1]: if true (1) then path configuration is allowed\n\
361-
to log warnings into stderr; if false (0) suppress these warnings;\n\
362-
set to true by default; also PYTHON_PATHCONFIG_WARNINGS\n\
363-
-X tracemalloc[=N]: trace Python memory allocations; N sets a traceback limit\n \
364+
-X tracemalloc[=N]: trace Python memory allocations; N sets a traceback limit\n\
364365
of N frames (default: 1); also PYTHONTRACEMALLOC=N\n\
365366
-X utf8[=0|1]: enable (1) or disable (0) UTF-8 mode; also PYTHONUTF8\n\
366367
-X warn_default_encoding: enable opt-in EncodingWarning for 'encoding=None';\n\

0 commit comments

Comments
 (0)