8000 gh-90300: split --help output into separate options by merwok · Pull Request #30331 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-90300: split --help output into separate options #30331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
225c869
move list of X options out of help output
merwok Jan 2, 2022
eaefd1a
mention help option in fatal error message
merwok Jan 2, 2022
57fd33b
move variable declaration out of case block
merwok Jan 2, 2022
55dbf69
move extra envvars help to separate option
merwok Jan 2, 2022
0aaf9af
doc
merwok Jan 2, 2022
a592003
add minimal tests
merwok Jan 2, 2022
1c4cf63
flatten the sub-switch
merwok Jan 2, 2022
d8bfcff
suggestion from Barry
merwok Jan 3, 2022
38f2dd8
more suggestions from flufl
merwok Jan 3, 2022
a828fe8
remove unnecessary
merwok Jan 7, 2022
8bde4ec
mention all envvars in --help-env
merwok Jan 7, 2022
0dbaf03
mistake
merwok Jan 7, 2022
0c9a995
introduce --help-xoptions
merwok Jan 12, 2022
aab464f
add --help-all
merwok Jan 12, 2022
064d4ad
merge upstream
merwok Jan 12, 2022
b9a0b19
replace fprintf by printf; remove extra blanklines
merwok Jan 15, 2022
0ee24d4
merge upstream
merwok Feb 9, 2022
dd2beaa
Merge branch 'main' into shorten-help-output
merwok Apr 11, 2022
c74fc69
merge upstream
merwok May 5, 2022
2f108fe
merge upstream
merwok May 23, 2022
4f345e8
check return code in verify_valid_flag
merwok May 23, 2022
a6573d6
remove duplicate check
merwok May 24, 2022
da97a38
fix some help texts in 80 columns
merwok May 24, 2022
98525b4
remove needless checks
merwok May 25, 2022
5585095
reformat and rearrange some help entries
merwok May 25, 2022
24526bd
fix formatting issues and missing info in man page and --help
merwok May 25, 2022
0bb5dfa
make new tests a bit more useful
merwok May 25, 2022
8fa72f5
512 bytes should be enough for everyone
merwok May 25, 2022
29d04a0
keep long option at the end of help text
merwok May 26, 2022
356d1bf
merge branch 'fix-help-man'
merwok May 26, 2022
ac1b5fb
fix tests and output
merwok May 26, 2022
9bcea95
final fixes
merwok May 26, 2022
5485255
merge upstream
merwok May 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
introduce --help-xoptions
  • Loading branch information
merwok committed Jan 12, 2022
commit 0c9a995fe668900f09fe890de38eacf91bf510f2
20 changes: 12 additions & 8 deletions Doc/using/cmdline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,21 @@ Generic options
--help

Print a short description of all command line options and corresponding
environment variables.
environment variables and exit.

.. cmdoption:: --help-env

Print a short description of Python-specific environment variables.
Print a short description of Python-specific environment variables
and exit.

.. versionadded:: 3.11

.. cmdoption:: --help-xoptions

Print a description of implementation-specific :option:`-X` options
and exit.

.. versionadded:: 3.11

.. cmdoption:: -V
--version
Expand All @@ -218,9 +228,6 @@ Generic options
.. versionadded:: 3.6
The ``-VV`` option.

.. versionadded:: 3.11
The ``--help-env`` option.


.. _using-on-misc-options:

Expand Down Expand Up @@ -458,7 +465,6 @@ Miscellaneous options
Reserved for various implementation-specific options. CPython currently
defines the following possible values:

* ``-X help`` to print a short description of all ``-X`` options;
* ``-X faulthandler`` to enable :mod:`faulthandler`;
* ``-X showrefcount`` to output the total reference count and number of used
memory blocks when the program finishes or after each statement in the
Expand Down Expand Up @@ -540,8 +546,6 @@ Miscellaneous options
.. versionadded:: 3.11
The ``-X frozen_modules`` option.

.. versionadded:: 3.11
The ``-X help`` option.


Options you shouldn't use
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_cmd_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def get_xoptions(*args):
def test_unknown_xoptions(self):
_, out, err = assert_python_failure('-X', 'blech')
self.assertIn(b'Unknown value for option -X', err)
msg = b'Fatal Python error: Unknown value for option -X (see -X help)'
msg = b'Fatal Python error: Unknown value for option -X (see --help-xoptions)'
self.assertEqual(err.splitlines().count(msg), 1)
self.assertEqual(b'', out)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Make ``--help`` output shorter by moving some info to the new
``--help-env`` and ``-X help`` options.
``--help-env`` and ``--help-xoptions`` command-line options.
9 changes: 5 additions & 4 deletions Misc/python.man
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ python \- an interpreted, interactive, object-oriented programming language
.B \--help-env
]
[
.B \-X help
.B \--help-xoptions
]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought showing all help options on their own line could be nice.

.br
[
Expand Down Expand Up @@ -156,9 +156,12 @@ the behavior of the interpreter.
.B \-h ", " \-? ", "\-\-help
Prints the usage for the interpreter executable and exits.
.TP
.B \-\-help\-env
.B "\-\-help\-env"
Prints help about Python-specific environment variables and exits.
.TP
.B "\-\-help\-xoptions"
Prints help about implementation-specific \fB\-X\fP options and exits.
.TP
.B \-i
When a script is passed as first argument or the \fB\-c\fP option is
used, enter interactive mode after executing the script or the
Expand Down Expand Up @@ -294,8 +297,6 @@ a regular expression on the warning message.
.BI "\-X " option
Set implementation-specific option. The following options are available:

-X help: show help about available options

-X faulthandler: enable faulthandler

-X showrefcount: output the total reference count and number of used
Expand Down
1 change: 1 addition & 0 deletions Python/getopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ static const wchar_t *opt_ptr = L"";
static const _PyOS_LongOption longopts[] = {
{L"check-hash-based-pycs", 1, 0},
{L"help-env", 0, 1},
{L"help-xoptions", 0, 2},
{NULL, 0, -1},
};

Expand Down
25 changes: 10 additions & 15 deletions Python/initconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Options (and corresponding environment variables):\n\
debug builds); also PYTHONDEBUG=x\n\
-E : ignore PYTHON* environment variables (such as PYTHONPATH)\n\
-h : print this help message and exit (also --help)\n\
--help-env : print help about Python-specific environment variables and exit\n\
--help-xoptions : print help about implementation-specific -X options and exit\n\
";
static const char usage_2[] = "\
-i : inspect interactively after running script; forces a prompt even\n\
Expand All @@ -64,8 +66,7 @@ static const char usage_3[] = "\
-W arg : warning control; arg is action:message:category:module:lineno\n\
also PYTHONWARNINGS=arg\n\
-x : skip first line of source, allowing use of non-Unix forms of #!cmd\n\
-X opt : set implementation-specific option (see details with -X help)\n\
--help-env : print help about Python-specific environment variables\n\
-X opt : set implementation-specific option\n\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--help-xoptions is listed a few items below, but if scanning the list it might be helpful to explicitly mention it here. (Sorry if it's been suggested before & declined!).

Suggested change
-X opt : set implementation-specific option\n\
-X opt : set implementation-specific option (see --help-xoptions)\n\

Copy link
Member Author
@merwok merwok May 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve added it and removed it. In the current version, I think it is not needed, as it is a few lines later and in the man page and shown in error message for unknown X option, but have no problem adding it if someone adds 👍🏽 to your comment 🙂

--check-hash-based-pycs always|default|never :\n\
control how Python invalidates hash-based .pyc files\n\
";
Expand All @@ -78,7 +79,6 @@ arg ...: arguments passed to program in sys.argv[1:]\n\

static const char usage_xoptions[] = "\
The following implementation-specific options are available:\n\
-X help: show this help and exit\n\
-X faulthandler: enable faulthandler\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\
Expand Down Expand Up @@ -2028,7 +2028,6 @@ _PyConfig_InitImportConfig(PyConfig *config)
// set, like -X showrefcount which requires a debug build. In this case unknown
// options are silently ignored.
const wchar_t* known_xoptions[] = {
L"help",
L"faulthandler",
L"showrefcount",
L"tracemalloc",
Expand Down Expand Up @@ -2084,7 +2083,7 @@ config_read(PyConfig *config, int compute_path_config)
/* -X options */
const wchar_t* option = _Py_check_xoptions(&config->xoptions, known_xoptions);
if (option != NULL) {
return PyStatus_Error("Unknown value for option -X (see -X help)");
return PyStatus_Error("Unknown value for option -X (see --help-xoptions)");
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out that showing the invalid value in this error message is not trivial: real C programmers had issue with it too before #28823


if (config_get_xoption(config, L"showrefcount")) {
Expand Down Expand Up @@ -2271,7 +2270,6 @@ config_parse_cmdline(PyConfig *config, PyWideStringList *warnoptions,
const PyWideStringList *argv = &config->argv;
int print_version = 0;
const wchar_t* program = config->program_name;
const wchar_t* xoption_help;

_PyOS_ResetGetOpt();
do {
Expand Down Expand Up @@ -2338,6 +2336,11 @@ config_parse_cmdline(PyConfig *config, PyWideStringList *warnoptions,
config_envvars_usage();
return _PyStatus_EXIT(0);

case 2:
// help-xoptions
config_xoptions_usage();
return _PyStatus_EXIT(0);

case 'b':
config->bytes_warning++;
break;
Expand All @@ -2353,6 +2356,7 @@ config_parse_cmdline(PyConfig *config, PyWideStringList *warnoptions,

case 'E':
case 'I':
case 'X':
/* option handled by _PyPreCmdline_Read() */
break;

Expand Down Expand Up @@ -2414,15 +2418,6 @@ config_parse_cmdline(PyConfig *config, PyWideStringList *warnoptions,
config->use_hash_seed = 0;
break;

case 'X':
xoption_help = config_get_xoption(config, L"help");
if (xoption_help) {
52FE config_xoptions_usage();
return _PyStatus_EXIT(0);
}
/* option handled by _PyPreCmdline_Read() */
break;

/* This space reserved for other options */

default:
Expand Down
0