Commit 7d4bb9f1 authored by Neil Schemenauer's avatar Neil Schemenauer

Add -E command line switch (ignore environment variables like PYTHONHOME

and PYTHONPATH).
parent f973c6d5
...@@ -14,6 +14,12 @@ extern DL_IMPORT(int) Py_UseClassExceptionsFlag; ...@@ -14,6 +14,12 @@ extern DL_IMPORT(int) Py_UseClassExceptionsFlag;
extern DL_IMPORT(int) Py_FrozenFlag; extern DL_IMPORT(int) Py_FrozenFlag;
extern DL_IMPORT(int) Py_TabcheckFlag; extern DL_IMPORT(int) Py_TabcheckFlag;
extern DL_IMPORT(int) Py_UnicodeFlag; extern DL_IMPORT(int) Py_UnicodeFlag;
extern DL_IMPORT(int) Py_IgnoreEnvironmentFlag;
/* this is a wrapper around getenv() the pays attention to
Py_IgnoreEnvironmentFlag. It should be used for getting variables like
PYTHONPATH and PYTHONHOME from the environment */
#define Py_GETENV(s) (Py_IgnoreEnvironmentFlag ? NULL : getenv(s))
DL_IMPORT(void) Py_FatalError(char *message); DL_IMPORT(void) Py_FatalError(char *message);
......
...@@ -281,12 +281,12 @@ $(PYTHON): Modules/$(MAINOBJ) $(LDLIBRARY) ...@@ -281,12 +281,12 @@ $(PYTHON): Modules/$(MAINOBJ) $(LDLIBRARY)
$(LDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST) $(LDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
platform: $(PYTHON) platform: $(PYTHON)
./$(PYTHON) -c 'import sys ; from distutils.util import get_platform ; print get_platform()+"-"+sys.version[0:3]' >platform ./$(PYTHON) -E -c 'import sys ; from distutils.util import get_platform ; print get_platform()+"-"+sys.version[0:3]' >platform
# Build the shared modules # Build the shared modules
sharedmods: $(PYTHON) sharedmods: $(PYTHON)
PYTHONPATH= ./$(PYTHON) $(srcdir)/setup.py build ./$(PYTHON) -E $(srcdir)/setup.py build
# buildno should really depend on something like LIBRARY_SRC # buildno should really depend on something like LIBRARY_SRC
buildno: $(PARSER_OBJS) \ buildno: $(PARSER_OBJS) \
...@@ -466,26 +466,26 @@ $(LIBRARY_OBJS) $(MODOBJS) Modules/$(MAINOBJ): $(PYTHON_HEADERS) ...@@ -466,26 +466,26 @@ $(LIBRARY_OBJS) $(MODOBJS) Modules/$(MAINOBJ): $(PYTHON_HEADERS)
# Test the interpreter (twice, once without .pyc files, once with) # Test the interpreter (twice, once without .pyc files, once with)
TESTOPTS= -l TESTOPTS= -l
TESTPROG= $(srcdir)/Lib/test/regrtest.py TESTPROG= $(srcdir)/Lib/test/regrtest.py
TESTPYTHON= ./$(PYTHON) -tt TESTPYTHON= ./$(PYTHON) -E -tt
test: all platform test: all platform
-find $(srcdir)/Lib -name '*.py[co]' -print | xargs rm -f -find $(srcdir)/Lib -name '*.py[co]' -print | xargs rm -f
-PYTHONPATH= $(TESTPYTHON) $(TESTPROG) $(TESTOPTS) -$(TESTPYTHON) $(TESTPROG) $(TESTOPTS)
PYTHONPATH= $(TESTPYTHON) $(TESTPROG) $(TESTOPTS) $(TESTPYTHON) $(TESTPROG) $(TESTOPTS)
QUICKTESTOPTS= $(TESTOPTS) -x test_thread test_signal test_strftime \ QUICKTESTOPTS= $(TESTOPTS) -x test_thread test_signal test_strftime \
test_unicodedata test_re test_sre test_select test_poll \ test_unicodedata test_re test_sre test_select test_poll \
test_linuxaudiodev test_sunaudiodev test_linuxaudiodev test_sunaudiodev
quicktest: all platform quicktest: all platform
-find $(srcdir)/Lib -name '*.py[co]' -print | xargs rm -f -find $(srcdir)/Lib -name '*.py[co]' -print | xargs rm -f
-PYTHONPATH= $(TESTPYTHON) $(TESTPROG) $(QUICKTESTOPTS) -$(TESTPYTHON) $(TESTPROG) $(QUICKTESTOPTS)
PYTHONPATH= $(TESTPYTHON) $(TESTPROG) $(QUICKTESTOPTS) $(TESTPYTHON) $(TESTPROG) $(QUICKTESTOPTS)
MEMTESTOPTS= $(QUICKTESTOPTS) -x test_dl test___all__ test_fork1 \ MEMTESTOPTS= $(QUICKTESTOPTS) -x test_dl test___all__ test_fork1 \
test_longexp test_longexp
memtest: all platform memtest: all platform
-rm -f $(srcdir)/Lib/test/*.py[co] -rm -f $(srcdir)/Lib/test/*.py[co]
-PYTHONPATH= $(TESTPYTHON) $(TESTPROG) $(MEMTESTOPTS) -$(TESTPYTHON) $(TESTPROG) $(MEMTESTOPTS)
PYTHONPATH= $(TESTPYTHON) $(TESTPROG) $(MEMTESTOPTS) $(TESTPYTHON) $(TESTPROG) $(MEMTESTOPTS)
# Install everything # Install everything
install: altinstall bininstall maninstall install: altinstall bininstall maninstall
...@@ -708,7 +708,7 @@ libainstall: all ...@@ -708,7 +708,7 @@ libainstall: all
# Install the dynamically loadable modules # Install the dynamically loadable modules
# This goes into $(exec_prefix) # This goes into $(exec_prefix)
sharedinstall: sharedinstall:
PYTHONPATH= ./$(PYTHON) $(srcdir)/setup.py install \ ./$(PYTHON) -E $(srcdir)/setup.py install \
--install-platlib=$(DESTSHARED) --install-platlib=$(DESTSHARED)
# Build the toplevel Makefile # Build the toplevel Makefile
......
...@@ -16,6 +16,9 @@ python \- an interpreted, interactive, object-oriented programming language ...@@ -16,6 +16,9 @@ python \- an interpreted, interactive, object-oriented programming language
.B \-S .B \-S
] ]
[ [
.B \-E
]
[
.B \-t .B \-t
] ]
[ [
...@@ -99,6 +102,10 @@ and the site-dependent manipulations of ...@@ -99,6 +102,10 @@ and the site-dependent manipulations of
.I sys.path .I sys.path
that it entails. that it entails.
.TP .TP
.B \-E
Ignore environment variables like PYTHONPATH and PYTHONHOME that modify
the behavior of the interpreter.
.TP
.B \-t .B \-t
Issue a warning when a source file mixes tabs and spaces for Issue a warning when a source file mixes tabs and spaces for
indentation in a way that makes it depend on the worth of a tab indentation in a way that makes it depend on the worth of a tab
......
...@@ -365,7 +365,7 @@ calculate_path(void) ...@@ -365,7 +365,7 @@ calculate_path(void)
static char delimiter[2] = {DELIM, '\0'}; static char delimiter[2] = {DELIM, '\0'};
static char separator[2] = {SEP, '\0'}; static char separator[2] = {SEP, '\0'};
char *pythonpath = PYTHONPATH; char *pythonpath = PYTHONPATH;
char *rtpypath = getenv("PYTHONPATH"); char *rtpypath = Py_GETENV("PYTHONPATH");
char *home = Py_GetPythonHome(); char *home = Py_GetPythonHome();
char *path = getenv("PATH"); char *path = getenv("PATH");
char *prog = Py_GetProgramName(); char *prog = Py_GetProgramName();
......
...@@ -28,7 +28,7 @@ static char **orig_argv; ...@@ -28,7 +28,7 @@ static char **orig_argv;
static int orig_argc; static int orig_argc;
/* command line options */ /* command line options */
#define BASE_OPTS "c:diOStuUvxXhVW:" #define BASE_OPTS "c:diOSEtuUvxXhVW:"
#ifndef RISCOS #ifndef RISCOS
#define PROGRAM_OPTS BASE_OPTS #define PROGRAM_OPTS BASE_OPTS
...@@ -53,6 +53,7 @@ Options and arguments (and corresponding environment variables):\n\ ...@@ -53,6 +53,7 @@ Options and arguments (and corresponding environment variables):\n\
-O : optimize generated bytecode (a tad; also PYTHONOPTIMIZE=x)\n\ -O : optimize generated bytecode (a tad; also PYTHONOPTIMIZE=x)\n\
-OO : remove doc-strings in addition to the -O optimizations\n\ -OO : remove doc-strings in addition to the -O optimizations\n\
-S : don't imply 'import site' on initialization\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\ -t : issue warnings about inconsistent tab usage (-tt: issue errors)\n\
"; ";
static char *usage_mid = "\ static char *usage_mid = "\
...@@ -108,6 +109,8 @@ Py_Main(int argc, char **argv) ...@@ -108,6 +109,8 @@ Py_Main(int argc, char **argv)
int stdin_is_interactive = 0; int stdin_is_interactive = 0;
int help = 0; int help = 0;
int version = 0; int version = 0;
int saw_inspect_flag = 0;
int saw_unbuffered_flag = 0;
PyCompilerFlags cf; PyCompilerFlags cf;
orig_argc = argc; /* For Py_GetArgcArgv() */ orig_argc = argc; /* For Py_GetArgcArgv() */
...@@ -117,11 +120,6 @@ Py_Main(int argc, char **argv) ...@@ -117,11 +120,6 @@ Py_Main(int argc, char **argv)
Py_RISCOSWimpFlag = 0; Py_RISCOSWimpFlag = 0;
#endif #endif
if ((p = getenv("PYTHONINSPECT")) && *p != '\0')
inspect = 1;
if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0')
unbuffered = 1;
PySys_ResetWarnOptions(); PySys_ResetWarnOptions();
while ((c = _PyOS_GetOpt(argc, argv, PROGRAM_OPTS)) != EOF) { while ((c = _PyOS_GetOpt(argc, argv, PROGRAM_OPTS)) != EOF) {
...@@ -146,6 +144,7 @@ Py_Main(int argc, char **argv) ...@@ -146,6 +144,7 @@ Py_Main(int argc, char **argv)
case 'i': case 'i':
inspect++; inspect++;
saw_inspect_flag = 1;
Py_InteractiveFlag++; Py_InteractiveFlag++;
break; break;
...@@ -157,12 +156,17 @@ Py_Main(int argc, char **argv) ...@@ -157,12 +156,17 @@ Py_Main(int argc, char **argv)
Py_NoSiteFlag++; Py_NoSiteFlag++;
break; break;
case 'E':
Py_IgnoreEnvironmentFlag++;
break;
case 't': case 't':
Py_TabcheckFlag++; Py_TabcheckFlag++;
break; break;
case 'u': case 'u':
unbuffered++; unbuffered++;
saw_unbuffered_flag = 1;
break; break;
case 'v': case 'v':
...@@ -210,6 +214,13 @@ Py_Main(int argc, char **argv) ...@@ -210,6 +214,13 @@ Py_Main(int argc, char **argv)
exit(0); 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 && if (command == NULL && _PyOS_optind < argc &&
strcmp(argv[_PyOS_optind], "-") != 0) strcmp(argv[_PyOS_optind], "-") != 0)
{ {
...@@ -307,7 +318,7 @@ Py_Main(int argc, char **argv) ...@@ -307,7 +318,7 @@ Py_Main(int argc, char **argv)
} }
else { else {
if (filename == NULL && stdin_is_interactive) { if (filename == NULL && stdin_is_interactive) {
char *startup = getenv("PYTHONSTARTUP"); char *startup = Py_GETENV("PYTHONSTARTUP");
if (startup != NULL && startup[0] != '\0') { if (startup != NULL && startup[0] != '\0') {
FILE *fp = fopen(startup, "r"); FILE *fp = fopen(startup, "r");
if (fp != NULL) { if (fp != NULL) {
......
...@@ -594,7 +594,7 @@ inittime(void) ...@@ -594,7 +594,7 @@ inittime(void)
m = Py_InitModule3("time", time_methods, module_doc); m = Py_InitModule3("time", time_methods, module_doc);
d = PyModule_GetDict(m); d = PyModule_GetDict(m);
/* Accept 2-digit dates unless PYTHONY2K is set and non-empty */ /* 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))); ins(d, "accept2dyear", PyInt_FromLong((long) (!p || !*p)));
/* Squirrel away the module's dictionary for the y2k check */ /* Squirrel away the module's dictionary for the y2k check */
Py_INCREF(d); Py_INCREF(d);
......
...@@ -425,7 +425,7 @@ calculate_path(void) ...@@ -425,7 +425,7 @@ calculate_path(void)
char *buf; char *buf;
size_t bufsz; size_t bufsz;
char *pythonhome = Py_GetPythonHome(); char *pythonhome = Py_GetPythonHome();
char *envpath = getenv("PYTHONPATH"); char *envpath = Py_GETENV("PYTHONPATH");
#ifdef MS_WIN32 #ifdef MS_WIN32
int skiphome, skipdefault; int skiphome, skipdefault;
......
...@@ -289,7 +289,7 @@ calculate_path(void) ...@@ -289,7 +289,7 @@ calculate_path(void)
char *buf; char *buf;
int bufsz; int bufsz;
char *pythonhome = Py_GetPythonHome(); char *pythonhome = Py_GetPythonHome();
char *envpath = getenv("PYTHONPATH"); char *envpath = Py_GETENV("PYTHONPATH");
#ifdef MS_WIN32 #ifdef MS_WIN32
char *machinepath, *userpath; char *machinepath, *userpath;
......
...@@ -30,9 +30,9 @@ Py_FrozenMain(int argc, char **argv) ...@@ -30,9 +30,9 @@ Py_FrozenMain(int argc, char **argv)
Py_FrozenFlag = 1; /* Suppress errors from getpath.c */ Py_FrozenFlag = 1; /* Suppress errors from getpath.c */
if ((p = getenv("PYTHONINSPECT")) && *p != '\0') if ((p = Py_GETENV("PYTHONINSPECT")) && *p != '\0')
inspect = 1; inspect = 1;
if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0') if ((p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0')
unbuffered = 1; unbuffered = 1;
if (unbuffered) { if (unbuffered) {
......
...@@ -1069,7 +1069,7 @@ case_ok(char *buf, int len, int namelen, char *name) ...@@ -1069,7 +1069,7 @@ case_ok(char *buf, int len, int namelen, char *name)
char tempbuf[MAX_PATH]; char tempbuf[MAX_PATH];
#endif #endif
if (getenv("PYTHONCASEOK") != NULL) if (Py_GETENV("PYTHONCASEOK") != NULL)
return 1; return 1;
#ifdef __CYGWIN__ #ifdef __CYGWIN__
...@@ -1092,7 +1092,7 @@ case_ok(char *buf, int len, int namelen, char *name) ...@@ -1092,7 +1092,7 @@ case_ok(char *buf, int len, int namelen, char *name)
struct ffblk ffblk; struct ffblk ffblk;
int done; int done;
if (getenv("PYTHONCASEOK") != NULL) if (Py_GETENV("PYTHONCASEOK") != NULL)
return 1; return 1;
done = findfirst(buf, &ffblk, FA_ARCH|FA_RDONLY|FA_HIDDEN|FA_DIREC); done = findfirst(buf, &ffblk, FA_ARCH|FA_RDONLY|FA_HIDDEN|FA_DIREC);
...@@ -1109,7 +1109,7 @@ case_ok(char *buf, int len, int namelen, char *name) ...@@ -1109,7 +1109,7 @@ case_ok(char *buf, int len, int namelen, char *name)
FSSpec fss; FSSpec fss;
OSErr err; OSErr err;
if (getenv("PYTHONCASEOK") != NULL) if (Py_GETENV("PYTHONCASEOK") != NULL)
return 1; return 1;
#ifndef USE_GUSI1 #ifndef USE_GUSI1
...@@ -1147,7 +1147,7 @@ case_ok(char *buf, int len, int namelen, char *name) ...@@ -1147,7 +1147,7 @@ case_ok(char *buf, int len, int namelen, char *name)
char dirname[MAXPATHLEN + 1]; char dirname[MAXPATHLEN + 1];
const int dirlen = len - namelen - 1; /* don't want trailing SEP */ const int dirlen = len - namelen - 1; /* don't want trailing SEP */
if (getenv("PYTHONCASEOK") != NULL) if (Py_GETENV("PYTHONCASEOK") != NULL)
return 1; return 1;
/* Copy the dir component into dirname; substitute "." if empty */ /* Copy the dir component into dirname; substitute "." if empty */
......
...@@ -63,6 +63,7 @@ int Py_NoSiteFlag; /* Suppress 'import site' */ ...@@ -63,6 +63,7 @@ int Py_NoSiteFlag; /* Suppress 'import site' */
int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c: deprecated */ int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c: deprecated */
int Py_FrozenFlag; /* Needed by getpath.c */ int Py_FrozenFlag; /* Needed by getpath.c */
int Py_UnicodeFlag = 0; /* Needed by compile.c */ int Py_UnicodeFlag = 0; /* Needed by compile.c */
int Py_IgnoreEnvironmentFlag; /* e.g. PYTHONPATH, PYTHONHOME */
static int initialized = 0; static int initialized = 0;
...@@ -98,11 +99,11 @@ Py_Initialize(void) ...@@ -98,11 +99,11 @@ Py_Initialize(void)
return; return;
initialized = 1; initialized = 1;
if ((p = getenv("PYTHONDEBUG")) && *p != '\0') if ((p = Py_GETENV("PYTHONDEBUG")) && *p != '\0')
Py_DebugFlag = Py_DebugFlag ? Py_DebugFlag : 1; Py_DebugFlag = Py_DebugFlag ? Py_DebugFlag : 1;
if ((p = getenv("PYTHONVERBOSE")) && *p != '\0') if ((p = Py_GETENV("PYTHONVERBOSE")) && *p != '\0')
Py_VerboseFlag = Py_VerboseFlag ? Py_VerboseFlag : 1; Py_VerboseFlag = Py_VerboseFlag ? Py_VerboseFlag : 1;
if ((p = getenv("PYTHONOPTIMIZE")) && *p != '\0') if ((p = Py_GETENV("PYTHONOPTIMIZE")) && *p != '\0')
Py_OptimizeFlag = Py_OptimizeFlag ? Py_OptimizeFlag : 1; Py_OptimizeFlag = Py_OptimizeFlag ? Py_OptimizeFlag : 1;
interp = PyInterpreterState_New(); interp = PyInterpreterState_New();
...@@ -225,7 +226,7 @@ Py_Finalize(void) ...@@ -225,7 +226,7 @@ Py_Finalize(void)
#ifdef Py_TRACE_REFS #ifdef Py_TRACE_REFS
if ( if (
#ifdef MS_WINDOWS /* Only ask on Windows if env var set */ #ifdef MS_WINDOWS /* Only ask on Windows if env var set */
getenv("PYTHONDUMPREFS") && Py_GETENV("PYTHONDUMPREFS") &&
#endif /* MS_WINDOWS */ #endif /* MS_WINDOWS */
_Py_AskYesNo("Print left references?")) { _Py_AskYesNo("Print left references?")) {
_Py_PrintReferences(stderr); _Py_PrintReferences(stderr);
...@@ -394,8 +395,8 @@ char * ...@@ -394,8 +395,8 @@ char *
Py_GetPythonHome(void) Py_GetPythonHome(void)
{ {
char *home = default_home; char *home = default_home;
if (home == NULL) if (home == NULL && !Py_IgnoreEnvironmentFlag)
home = getenv("PYTHONHOME"); home = Py_GETENV("PYTHONHOME");
return home; return home;
} }
......
...@@ -5,7 +5,7 @@ static char *prefix,*exec_prefix,*progpath,*module_search_path=0; ...@@ -5,7 +5,7 @@ static char *prefix,*exec_prefix,*progpath,*module_search_path=0;
static void static void
calculate_path() calculate_path()
{ char *pypath=getenv("Python$Path"); { char *pypath=Py_GETENV("Python$Path");
if(pypath) if(pypath)
{ module_search_path=malloc(strlen(pypath)+1); { module_search_path=malloc(strlen(pypath)+1);
if (module_search_path) sprintf(module_search_path,"%s",pypath); if (module_search_path) sprintf(module_search_path,"%s",pypath);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment