[pypy-svn] pypy commit 45e0881a379b: 'sys.executable' must be set before doing option parsing,
Bitbucket
commits-noreply at bitbucket.org
Tue Dec 14 17:37:16 CET 2010
# HG changeset patch -- Bitbucket.org
# Project pypy
# URL http://bitbucket.org/pypy/pypy/overview
# User Armin Rigo <arigo at tunes.org>
# Date 1292344214 -3600
# Node ID 45e0881a379bfaddb9e5bdd2baf0b6477f3b6e23
# Parent 8d549ed5ab18b56cf2bb0707e71a1c7d3eca0920
'sys.executable' must be set before doing option parsing,
other we get the default 'py.py' in the -h message, for example.
Fixed with a test.
--- a/pypy/translator/goal/app_main.py
+++ b/pypy/translator/goal/app_main.py
@@ -207,7 +207,10 @@ def get_library_path(executable):
break # found!
return newpath
-def setup_initial_paths(executable, ignore_environment=False, **extra):
+def setup_sys_executable(executable, nanos):
+ # a substituted os if we are translated
+ global os
+ os = nanos
# find the full path to the executable, assuming that if there is no '/'
# in the provided one then we must look along the $PATH
if we_are_translated() and IS_WINDOWS and not executable.lower().endswith('.exe'):
@@ -224,7 +227,8 @@ def setup_initial_paths(executable, igno
break
sys.executable = os.path.abspath(executable)
- newpath = get_library_path(executable)
+def setup_initial_paths(ignore_environment=False, **extra):
+ newpath = get_library_path(sys.executable)
readenv = not ignore_environment
path = readenv and os.getenv('PYTHONPATH')
if path:
@@ -575,15 +579,13 @@ def print_banner():
'"license" for more information.')
def entry_point(executable, argv, nanos):
- # a substituted os if we are translated
- global os
- os = nanos
+ setup_sys_executable(executable, nanos)
try:
cmdline = parse_command_line(argv)
except CommandLineError, e:
print_error(str(e))
return 2
- setup_initial_paths(executable, **cmdline)
+ setup_initial_paths(**cmdline)
return run_command_line(**cmdline)
--- a/pypy/translator/goal/test2/test_app_main.py
+++ b/pypy/translator/goal/test2/test_app_main.py
@@ -188,6 +188,12 @@ class TestInteraction:
child.sendline("'' in sys.path")
child.expect("True")
+ def test_help(self):
+ # test that -h prints the usage, including the name of the executable
+ # which should be /full/path/to/app_main.py in this case
+ child = self.spawn(['-h'])
+ child.expect(r'usage: .*app_main.py \[options\]')
+
def test_run_script(self):
child = self.spawn([demo_script])
idx = child.expect(['hello', 'Python ', '>>> '])
More information about the Pypy-commit
mailing list