Skip to content

Commit 9d87119

Browse files
committed
#1772833: add -q command line option.
1 parent cbd2ab1 commit 9d87119

4 files changed

Lines changed: 27 additions & 3 deletions

File tree

Doc/using/cmdline.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,13 @@ Miscellaneous options
220220
Discard docstrings in addition to the :option:`-O` optimizations.
221221

222222

223+
.. cmdoption:: -q
224+
225+
Don't display the copyright and version messages even in interactive mode.
226+
227+
.. versionadded:: 3.2
228+
229+
223230
.. cmdoption:: -s
224231

225232
Don't add user site directory to sys.path

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.2 Beta 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #1772833: Add the -q command-line option to suppress copyright
14+
and version output in interactive mode.
15+
1316
- Provide an *optimize* parameter in the built-in compile() function.
1417

1518
- Fixed several corner case issues on os.stat/os.lstat related to reparse

Misc/python.man

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ python \- an interpreted, interactive, object-oriented programming language
2626
.B \-m
2727
.I module-name
2828
]
29+
[
30+
.B \-q
31+
]
2932
.br
3033
[
3134
.B \-O
@@ -145,6 +148,10 @@ to \fI.pyo\fP. Given twice, causes docstrings to be discarded.
145148
.B \-O0
146149
Discard docstrings in addition to the \fB-O\fP optimizations.
147150
.TP
151+
.B \-q
152+
Do not print the version and copyright messages. These messages are
153+
also suppressed in non-interactive mode.
154+
.TP
148155
.BI "\-Q " argument
149156
Division control; see PEP 238. The argument must be one of "old" (the
150157
default, int/int and long/long return an int or long), "new" (new

Modules/main.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static wchar_t **orig_argv;
4646
static int orig_argc;
4747

4848
/* command line options */
49-
#define BASE_OPTS L"bBc:dEhiJm:OsStuvVW:xX:?"
49+
#define BASE_OPTS L"bBc:dEhiJm:OqsStuvVW:xX:?"
5050

5151
#define PROGRAM_OPTS BASE_OPTS
5252

@@ -71,6 +71,7 @@ static char *usage_2 = "\
7171
-m mod : run library module as a script (terminates option list)\n\
7272
-O : optimize generated bytecode slightly; also PYTHONOPTIMIZE=x\n\
7373
-OO : remove doc-strings in addition to the -O optimizations\n\
74+
-q : don't print version and copyright messages on interactive startup\n\
7475
-s : don't add user site directory to sys.path; also PYTHONNOUSERSITE\n\
7576
-S : don't imply 'import site' on initialization\n\
7677
";
@@ -318,6 +319,7 @@ Py_Main(int argc, wchar_t **argv)
318319
int stdin_is_interactive = 0;
319320
int help = 0;
320321
int version = 0;
322+
int quiet = 0;
321323
int saw_unbuffered_flag = 0;
322324
PyCompilerFlags cf;
323325

@@ -424,6 +426,10 @@ Py_Main(int argc, wchar_t **argv)
424426
PySys_AddXOption(_PyOS_optarg);
425427
break;
426428

429+
case 'q':
430+
quiet++;
431+
break;
432+
427433
/* This space reserved for other options */
428434

429435
default:
@@ -588,8 +594,9 @@ Py_Main(int argc, wchar_t **argv)
588594
#endif
589595
Py_Initialize();
590596

591-
if (Py_VerboseFlag ||
592-
(command == NULL && filename == NULL && module == NULL && stdin_is_interactive)) {
597+
if (!quiet && (Py_VerboseFlag ||
598+
(command == NULL && filename == NULL &&
599+
module == NULL && stdin_is_interactive))) {
593600
fprintf(stderr, "Python %s on %s\n",
594601
Py_GetVersion(), Py_GetPlatform());
595602
if (!Py_NoSiteFlag)

0 commit comments

Comments
 (0)