Skip to content

Commit 36805f6

Browse files
authored
[3.14] gh-145990: Sort python --help-xoptions by option name (GH-145993)
* Sort --help-xoptions alphabetically by name. * add a sorting regression test in test_help_xoptions manual backport of GH-145991
1 parent e0a8a6d commit 36805f6

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
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: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,15 @@ arg ...: arguments passed to program in sys.argv[1:]\n\
301301

302302
static const char usage_xoptions[] = "\
303303
The following implementation-specific options are available:\n\
304+
-X context_aware_warnings=[0|1]: if true (1) then the warnings module will\n\
305+
use a context variables; if false (0) then the warnings module will\n\
306+
use module globals, which is not concurrent-safe; set to true for\n\
307+
free-threaded builds and false otherwise; also\n\
308+
PYTHON_CONTEXT_AWARE_WARNINGS\n\
304309
-X cpu_count=N: override the return value of os.cpu_count();\n\
305310
-X cpu_count=default cancels overriding; also PYTHON_CPU_COUNT\n\
306311
-X dev : enable Python Development Mode; also PYTHONDEVMODE\n\
312+
-X disable-remote-debug: disable remote debugging; also PYTHON_DISABLE_REMOTE_DEBUG\n\
307313
-X faulthandler: dump the Python traceback on fatal errors;\n\
308314
also PYTHONFAULTHANDLER\n\
309315
-X frozen_modules=[on|off]: whether to use frozen modules; the default is \"on\"\n\
@@ -323,7 +329,6 @@ The following implementation-specific options are available:\n\
323329
-X perf: support the Linux \"perf\" profiler; also PYTHONPERFSUPPORT=1\n\
324330
-X perf_jit: support the Linux \"perf\" profiler with DWARF support;\n\
325331
also PYTHON_PERF_JIT_SUPPORT=1\n\
326-
-X disable-remote-debug: disable remote debugging; also PYTHON_DISABLE_REMOTE_DEBUG\n\
327332
"
328333
#ifdef Py_DEBUG
329334
"-X presite=MOD: import this module before site; also PYTHON_PRESITE\n"
@@ -338,21 +343,17 @@ The following implementation-specific options are available:\n\
338343
"\
339344
-X showrefcount: output the total reference count and number of used\n\
340345
memory blocks when the program finishes or after each statement in\n\
341-
the interactive interpreter; only works on debug builds\n"
346+
the interactive interpreter; only works on debug builds\n\
347+
-X thread_inherit_context=[0|1]: enable (1) or disable (0) threads inheriting\n\
348+
context vars by default; enabled by default in the free-threaded\n\
349+
build and disabled otherwise; also PYTHON_THREAD_INHERIT_CONTEXT\n\
350+
"
342351
#ifdef Py_GIL_DISABLED
343352
"-X tlbc=[0|1]: enable (1) or disable (0) thread-local bytecode. Also\n\
344353
PYTHON_TLBC\n"
345354
#endif
346355
"\
347-
-X thread_inherit_context=[0|1]: enable (1) or disable (0) threads inheriting\n\
348-
context vars by default; enabled by default in the free-threaded\n\
349-
build and disabled otherwise; also PYTHON_THREAD_INHERIT_CONTEXT\n\
350-
-X context_aware_warnings=[0|1]: if true (1) then the warnings module will\n\
351-
use a context variables; if false (0) then the warnings module will\n\
352-
use module globals, which is not concurrent-safe; set to true for\n\
353-
free-threaded builds and false otherwise; also\n\
354-
PYTHON_CONTEXT_AWARE_WARNINGS\n\
355-
-X tracemalloc[=N]: trace Python memory allocations; N sets a traceback limit\n \
356+
-X tracemalloc[=N]: trace Python memory allocations; N sets a traceback limit\n\
356357
of N frames (default: 1); also PYTHONTRACEMALLOC=N\n\
357358
-X utf8[=0|1]: enable (1) or disable (0) UTF-8 mode; also PYTHONUTF8\n\
358359
-X warn_default_encoding: enable opt-in EncodingWarning for 'encoding=None';\n\

0 commit comments

Comments
 (0)