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
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
512 bytes should be enough for everyone
  • Loading branch information
merwok committed May 25, 2022
commit 8fa72f5bc3e4020fa83f36bc09f87760d018ae16
59 changes: 21 additions & 38 deletions Python/initconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
static const char usage_line[] =
"usage: %ls [option] ... [-c cmd | -m mod | file | -] [arg] ...\n";

/* Long help messages, split into parts < 512 bytes */
/* Long help message */
/* Lines sorted by option name; keep in sync with usage_envvars* below */
static const char usage_1[] = "\
static const char usage_help[] = "\
Options (and corresponding environment variables):\n\
-b : issue warnings about str(bytes_instance), str(bytearray_instance)\n\
and comparing bytes/bytearray with str. (-bb: issue errors)\n\
Expand All @@ -45,8 +45,6 @@ Options (and corresponding environment variables):\n\
8000 --help-env : print help about Python environment variables and exit\n\
--help-xoptions : print help about implementation-specific -X options and exit\n\
--help-all : print complete help information and exit\n\
";
static const char usage_2[] = "\
-i : inspect interactively after running script; forces a prompt even\n\
if stdin does not appear to be a terminal; also PYTHONINSPECT=x\n\
-I : isolate Python from the user's environment (implies -E and -s)\n\
Expand All @@ -59,8 +57,6 @@ static const char usage_2[] = "\
-q : don't print version and copyright messages on interactive startup\n\
-s : don't add user site directory to sys.path; also PYTHONNOUSERSITE\n\
-S : don't imply 'import site' on initialization\n\
";
static const char usage_3[] = "\
-u : force the stdout and stderr streams to be unbuffered;\n\
this option has no effect on stdin; also PYTHONUNBUFFERED=x\n\
-v : verbose (trace import statements); also PYTHONVERBOSE=x\n\
Expand All @@ -71,8 +67,6 @@ static const char usage_3[] = "\
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\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 🙂

";
static const char usage_4[] = "\
Arguments:\n\
file : program read from script file\n\
- : program read from stdin (default; interactive mode if a tty)\n\
Expand Down Expand Up @@ -128,21 +122,19 @@ The following implementation-specific options are available:\n\
The default is \"on\" (or \"off\" if you are running a local build).";

/* Envvars that don't have equivalent command-line options are listed first */
static const char usage_envvars1[] = "\
Environment variables that change behavior:\n\
PYTHONSTARTUP: file executed on interactive startup (no default)\n\
PYTHONPATH : '%lc'-separated list of directories prefixed to the\n\
default module search path. The result is sys.path.\n";
static const char usage_envvars2[] =
static const char usage_envvars[] =
"Environment variables that change behavior:\n"
"PYTHONSTARTUP: file executed on interactive startup (no default)\n"
"PYTHONPATH : '%lc'-separated list of directories prefixed to the\n"
" default module search path. The result is sys.path.\n"
"PYTHONSAFEPATH: don't prepend a potentially unsafe path to sys.path.\n"
"PYTHONHOME : alternate <prefix> directory (or <prefix>%lc<exec_prefix>).\n"
" The default module search path uses %s.\n"
"PYTHONPLATLIBDIR : override sys.platlibdir.\n"
"PYTHONCASEOK : ignore case in 'import' statements (Windows).\n"
"PYTHONUTF8: if set to 1, enable the UTF-8 mode.\n"
"PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.\n"
"PYTHONFAULTHANDLER: dump the Python traceback on fatal errors.\n";
static const char usage_envvars3[] =
"PYTHONFAULTHANDLER: dump the Python traceback on fatal errors.\n"
"PYTHONHASHSEED: if this variable is set to 'random', a random value is used\n"
" to seed the hashes of str and bytes objects. It can also be set to an\n"
" integer in the range [0,4294967295] to get hash values with a\n"
Expand All @@ -152,8 +144,7 @@ static const char usage_envvars3[] =
" hooks.\n"
"PYTHONCOERCECLOCALE: if this variable is set to 0, it disables the locale\n"
" coercion behavior. Use PYTHONCOERCECLOCALE=warn to request display of\n"
" locale coercion and locale compatibility warnings on stderr.";
static const char usage_envvars4[] =
" locale coercion and locale compatibility warnings on stderr.\n"
"PYTHONBREAKPOINT: if this variable is set to 0, it disables the default\n"
" debugger. It can be set to the callable of your debugger of choice.\n"
"PYTHONDEVMODE: enable the development mode.\n"
Expand All @@ -163,17 +154,16 @@ static const char usage_envvars4[] =
" tables mapping extra location information (end line, start column offset \n"
" and end column offset) to every instruction in code objects. This is useful \n"
" when smaller code objects and pyc files are desired as well as suppressing the \n"
" extra visual location indicators when the interpreter displays tracebacks.\n";
static const char usage_envvars5[] = "\
These variables have equivalent command-line parameters (see --help for details):\n\
PYTHONDEBUG : enable parser debug mode (-d)\n\
PYTHONDONTWRITEBYTECODE : don't write .pyc files (-B)\n\
PYTHONINSPECT : inspect interactively after running script (-i)\n\
PYTHONNOUSERSITE : disable user site directory (-s)\n\
PYTHONOPTIMIZE : enable level 1 optimizations (-O)\n\
PYTHONUNBUFFERED : disable stdout/stderr buffering (-u)\n\
PYTHONVERBOSE : trace import statements (-v)\n\
PYTHONWARNINGS=arg : warning control (-W arg)";
" extra visual location indicators when the interpreter displays tracebacks.\n"
"These variables have equivalent command-line parameters (see --help for details):\n"
"PYTHONDEBUG : enable parser debug mode (-d)\n"
"PYTHONDONTWRITEBYTECODE : don't write .pyc files (-B)\n"
"PYTHONINSPECT : inspect interactively after running script (-i)\n"
"PYTHONNOUSERSITE : disable user site directory (-s)\n"
"PYTHONOPTIMIZE : enable level 1 optimizations (-O)\n"
"PYTHONUNBUFFERED : disable stdout/stderr buffering (-u)\n"
"PYTHONVERBOSE : trace import statements (-v)\n"
"PYTHONWARNINGS=arg : warning control (-W arg)";

#if defined(MS_WINDOWS)
# define PYTHONHOMEHELP "<prefix>\\python{major}{minor}"
Expand Down Expand Up @@ -2269,21 +2259,14 @@ config_usage(int error, const wchar_t* program)
if (error)
fprintf(f, "Try `python -h' for more information.\n");
else {
fputs(usage_1, f);
fputs(usage_2, f);
fputs(usage_3, f);
fputs(usage_4, f);
fputs(usage_help, f);
}
}

static void
config_envvars_usage()
{
printf(usage_envvars1, (wint_t)DELIM);
printf(usage_envvars2, (wint_t)DELIM, PYTHONHOMEHELP);
puts(usage_envvars3);
puts(usage_envvars4);
puts(usage_envvars5);
printf(usage_envvars, (wint_t)DELIM, (wint_t)DELIM, PYTHONHOMEHELP);
}

static void
Expand Down
0