mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Add -E command line switch (ignore environment variables like PYTHONHOME
and PYTHONPATH).
This commit is contained in:
parent
f973c6d594
commit
7d4bb9f179
12 changed files with 59 additions and 34 deletions
|
@ -365,7 +365,7 @@ calculate_path(void)
|
|||
static char delimiter[2] = {DELIM, '\0'};
|
||||
static char separator[2] = {SEP, '\0'};
|
||||
char *pythonpath = PYTHONPATH;
|
||||
char *rtpypath = getenv("PYTHONPATH");
|
||||
char *rtpypath = Py_GETENV("PYTHONPATH");
|
||||
char *home = Py_GetPythonHome();
|
||||
char *path = getenv("PATH");
|
||||
char *prog = Py_GetProgramName();
|
||||
|
|
|
@ -28,7 +28,7 @@ static char **orig_argv;
|
|||
static int orig_argc;
|
||||
|
||||
/* command line options */
|
||||
#define BASE_OPTS "c:diOStuUvxXhVW:"
|
||||
#define BASE_OPTS "c:diOSEtuUvxXhVW:"
|
||||
|
||||
#ifndef RISCOS
|
||||
#define PROGRAM_OPTS BASE_OPTS
|
||||
|
@ -53,6 +53,7 @@ Options and arguments (and corresponding environment variables):\n\
|
|||
-O : optimize generated bytecode (a tad; also PYTHONOPTIMIZE=x)\n\
|
||||
-OO : remove doc-strings in addition to the -O optimizations\n\
|
||||
-S : don't imply 'import site' on initialization\n\
|
||||
-E : ignore environment variables (such as PYTHONPATH)\n\
|
||||
-t : issue warnings about inconsistent tab usage (-tt: issue errors)\n\
|
||||
";
|
||||
static char *usage_mid = "\
|
||||
|
@ -108,6 +109,8 @@ Py_Main(int argc, char **argv)
|
|||
int stdin_is_interactive = 0;
|
||||
int help = 0;
|
||||
int version = 0;
|
||||
int saw_inspect_flag = 0;
|
||||
int saw_unbuffered_flag = 0;
|
||||
PyCompilerFlags cf;
|
||||
|
||||
orig_argc = argc; /* For Py_GetArgcArgv() */
|
||||
|
@ -117,11 +120,6 @@ Py_Main(int argc, char **argv)
|
|||
Py_RISCOSWimpFlag = 0;
|
||||
#endif
|
||||
|
||||
if ((p = getenv("PYTHONINSPECT")) && *p != '\0')
|
||||
inspect = 1;
|
||||
if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0')
|
||||
unbuffered = 1;
|
||||
|
||||
PySys_ResetWarnOptions();
|
||||
|
||||
while ((c = _PyOS_GetOpt(argc, argv, PROGRAM_OPTS)) != EOF) {
|
||||
|
@ -146,6 +144,7 @@ Py_Main(int argc, char **argv)
|
|||
|
||||
case 'i':
|
||||
inspect++;
|
||||
saw_inspect_flag = 1;
|
||||
Py_InteractiveFlag++;
|
||||
break;
|
||||
|
||||
|
@ -157,12 +156,17 @@ Py_Main(int argc, char **argv)
|
|||
Py_NoSiteFlag++;
|
||||
break;
|
||||
|
||||
case 'E':
|
||||
Py_IgnoreEnvironmentFlag++;
|
||||
break;
|
||||
|
||||
case 't':
|
||||
Py_TabcheckFlag++;
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
unbuffered++;
|
||||
saw_unbuffered_flag = 1;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
|
@ -210,6 +214,13 @@ Py_Main(int argc, char **argv)
|
|||
exit(0);
|
||||
}
|
||||
|
||||
if (!saw_inspect_flag &&
|
||||
(p = Py_GETENV("PYTHONINSPECT")) && *p != '\0')
|
||||
inspect = 1;
|
||||
if (!saw_unbuffered_flag &&
|
||||
(p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0')
|
||||
unbuffered = 1;
|
||||
|
||||
if (command == NULL && _PyOS_optind < argc &&
|
||||
strcmp(argv[_PyOS_optind], "-") != 0)
|
||||
{
|
||||
|
@ -307,7 +318,7 @@ Py_Main(int argc, char **argv)
|
|||
}
|
||||
else {
|
||||
if (filename == NULL && stdin_is_interactive) {
|
||||
char *startup = getenv("PYTHONSTARTUP");
|
||||
char *startup = Py_GETENV("PYTHONSTARTUP");
|
||||
if (startup != NULL && startup[0] != '\0') {
|
||||
FILE *fp = fopen(startup, "r");
|
||||
if (fp != NULL) {
|
||||
|
|
|
@ -594,7 +594,7 @@ inittime(void)
|
|||
m = Py_InitModule3("time", time_methods, module_doc);
|
||||
d = PyModule_GetDict(m);
|
||||
/* Accept 2-digit dates unless PYTHONY2K is set and non-empty */
|
||||
p = getenv("PYTHONY2K");
|
||||
p = Py_GETENV("PYTHONY2K");
|
||||
ins(d, "accept2dyear", PyInt_FromLong((long) (!p || !*p)));
|
||||
/* Squirrel away the module's dictionary for the y2k check */
|
||||
Py_INCREF(d);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue