[pypy-svn] r79661 - in pypy/trunk/pypy/translator/goal: . test2
arigo at codespeak.net
arigo at codespeak.net
Tue Nov 30 10:57:18 CET 2010
Author: arigo
Date: Tue Nov 30 10:57:15 2010
New Revision: 79661
Modified:
pypy/trunk/pypy/translator/goal/app_main.py
pypy/trunk/pypy/translator/goal/test2/test_app_main.py
Log:
Implement -E, and test it.
(The branch/fast-forward added -E, but as far as I can tell
it completely ignores it)
Modified: pypy/trunk/pypy/translator/goal/app_main.py
==============================================================================
--- pypy/trunk/pypy/translator/goal/app_main.py (original)
+++ pypy/trunk/pypy/translator/goal/app_main.py Tue Nov 30 10:57:15 2010
@@ -11,6 +11,7 @@
-h, --help show this help message and exit
-m library module to be run as a script (terminates option list)
-W arg warning control (arg is action:message:category:module:lineno)
+ -E ignore environment variables (such as PYTHONPATH)
--version print the PyPy version
--info print translation information about this PyPy executable
"""
@@ -199,7 +200,7 @@
break # found!
return newpath
-def setup_initial_paths(executable, nanos):
+def setup_initial_paths(executable, nanos, readenv=True, **extra):
# a substituted os if we are translated
global os
os = nanos
@@ -220,7 +221,7 @@
sys.executable = os.path.abspath(executable)
newpath = get_library_path(executable)
- path = os.getenv('PYTHONPATH')
+ path = readenv and os.getenv('PYTHONPATH')
if path:
newpath = path.split(os.pathsep) + newpath
# remove duplicates
@@ -230,7 +231,6 @@
if dir not in _seen:
sys.path.append(dir)
_seen[dir] = True
- return executable
def parse_command_line(argv):
@@ -242,6 +242,7 @@
run_stdin = False
warnoptions = []
unbuffered = False
+ readenv = True
while i < len(argv):
arg = argv[i]
if not arg.startswith('-'):
@@ -253,6 +254,8 @@
argv[i] = '-c'
run_command = True
break
+ elif arg == '-E':
+ readenv = False
elif arg == '-u':
unbuffered = True
elif arg == '-O' or arg == '-OO':
@@ -305,6 +308,7 @@
run_stdin,
warnoptions,
unbuffered,
+ readenv,
cmd=None,
**ignored):
# with PyPy in top of CPython we can only have around 100
@@ -355,7 +359,7 @@
# * PYTHONINSPECT is set and stdin is a tty.
#
return (go_interactive or
- (os.getenv('PYTHONINSPECT') and sys.stdin.isatty()))
+ (readenv and os.getenv('PYTHONINSPECT') and sys.stdin.isatty()))
success = True
@@ -388,7 +392,7 @@
# If stdin is a tty or if "-i" is specified, we print
# a banner and run $PYTHONSTARTUP.
print_banner()
- python_startup = os.getenv('PYTHONSTARTUP')
+ python_startup = readenv and os.getenv('PYTHONSTARTUP')
if python_startup:
try:
f = open(python_startup)
@@ -451,7 +455,6 @@
'"license" for more information.')
def entry_point(executable, argv, nanos):
- executable = setup_initial_paths(executable, nanos)
try:
cmdline = parse_command_line(argv)
except CommandLineError, e:
@@ -459,8 +462,8 @@
return 2
if cmdline is None:
return 0
- else:
- return run_command_line(**cmdline)
+ setup_initial_paths(executable, nanos, **cmdline)
+ return run_command_line(**cmdline)
if __name__ == '__main__':
Modified: pypy/trunk/pypy/translator/goal/test2/test_app_main.py
==============================================================================
--- pypy/trunk/pypy/translator/goal/test2/test_app_main.py (original)
+++ pypy/trunk/pypy/translator/goal/test2/test_app_main.py Tue Nov 30 10:57:15 2010
@@ -217,6 +217,38 @@
finally:
os.environ['PYTHONSTARTUP'] = old
+ def test_ignore_python_startup(self):
+ old = os.environ.get('PYTHONSTARTUP', '')
+ try:
+ os.environ['PYTHONSTARTUP'] = crashing_demo_script
+ child = self.spawn(['-E'])
+ child.expect(re.escape(banner))
+ index = child.expect(['Traceback', '>>> '])
+ assert index == 1 # no traceback
+ finally:
+ os.environ['PYTHONSTARTUP'] = old
+
+ def test_ignore_python_inspect(self):
+ os.environ['PYTHONINSPECT_'] = '1'
+ try:
+ child = self.spawn(['-E', '-c', 'pass'])
+ from pexpect import EOF
+ index = child.expect(['>>> ', EOF])
+ assert index == 1 # no prompt
+ finally:
+ del os.environ['PYTHONINSPECT_']
+
+ def test_ignore_python_path(self):
+ old = os.environ.get('PYTHONPATH', '')
+ try:
+ os.environ['PYTHONPATH'] = 'foobarbaz'
+ child = self.spawn(['-E', '-c', 'import sys; print sys.path'])
+ from pexpect import EOF
+ index = child.expect(['foobarbaz', EOF])
+ assert index == 1 # no foobarbaz
+ finally:
+ os.environ['PYTHONPATH'] = old
+
def test_unbuffered(self):
line = 'import os,sys;sys.stdout.write(str(789));os.read(0,1)'
child = self.spawn(['-u', '-c', line])
More information about the Pypy-commit
mailing list