[pypy-commit] pypy app_main-refactor: yay! Kill the usage of nanos from app_main: now that we setup a bootstrap sys.path very early, we should be able to import the actual os just aftwerwards
antocuni
noreply at buildbot.pypy.org
Mon Jun 11 13:42:12 CEST 2012
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: app_main-refactor
Changeset: r55570:6020a41d6e87
Date: 2012-06-11 12:04 +0200
http://bitbucket.org/pypy/pypy/changeset/6020a41d6e87/
Log: yay! Kill the usage of nanos from app_main: now that we setup a
bootstrap sys.path very early, we should be able to import the
actual os just aftwerwards
diff --git a/pypy/translator/goal/app_main.py b/pypy/translator/goal/app_main.py
--- a/pypy/translator/goal/app_main.py
+++ b/pypy/translator/goal/app_main.py
@@ -213,12 +213,6 @@
# ____________________________________________________________
# Main entry point
-# see nanos.py for explainment why we do not import os here
-# CAUTION!
-# remember to update nanos.py if you are using more functions
-# from os or os.path!
-# Running test/test_nanos.py might be helpful as well.
-
def we_are_translated():
# app-level, very different from pypy.rlib.objectmodel.we_are_translated
return hasattr(sys, 'pypy_translation_info')
@@ -231,6 +225,7 @@
def setup_and_fix_paths(ignore_environment=False, **extra):
+ import os
newpath = sys.path[:]
readenv = not ignore_environment
path = readenv and os.getenv('PYTHONPATH')
@@ -381,6 +376,7 @@
def parse_command_line(argv):
+ import os
options = default_options.copy()
options['warnoptions'] = []
#
@@ -460,6 +456,7 @@
# but we need more in the translated PyPy for the compiler package
if '__pypy__' not in sys.builtin_module_names:
sys.setrecursionlimit(5000)
+ import os
if unbuffered:
set_unbuffered_io()
@@ -634,6 +631,7 @@
return status
def resolvedirof(filename):
+ import os
try:
filename = os.path.abspath(filename)
except OSError:
@@ -681,9 +679,12 @@
# This is important for py3k
sys.executable = executable
-def entry_point(executable, argv, nanos):
- global os
- os = nanos
+def entry_point(executable, argv):
+ # note that before calling setup_bootstrap_path, we are limited because we
+ # cannot import stdlib modules. In particular, we cannot use unicode
+ # stuffs (because we need to be able to import encodings) and we cannot
+ # import os, which is used a bit everywhere in app_main, but only imported
+ # *after* setup_bootstrap_path
setup_bootstrap_path(executable)
try:
cmdline = parse_command_line(argv)
@@ -698,7 +699,12 @@
if __name__ == '__main__':
import autopath
- import nanos
+ # we need to import pypy.translator.platform early, before we start to
+ # mess up the env variables. In particular, during the import we spawn a
+ # couple of processes which gets confused if PYTHONINSPECT is set (e.g.,
+ # hg to get the version and the hack in tool.runsubprocess to prevent
+ # out-of-memory for late os.fork())
+ import pypy.translator.platform
# obscure! try removing the following line, see how it crashes, and
# guess why...
ImStillAroundDontForgetMe = sys.modules['__main__']
@@ -750,19 +756,18 @@
if 'PYTHONWARNINGS_' in os.environ:
reset.append(('PYTHONWARNINGS', os.environ.get('PYTHONWARNINGS', '')))
os.environ['PYTHONWARNINGS'] = os.environ['PYTHONWARNINGS_']
+ del os # make sure that os is not available globally, because this is what
+ # happens in "real life" outside the tests
# no one should change to which lists sys.argv and sys.path are bound
old_argv = sys.argv
old_path = sys.path
- from pypy.module.sys.version import PYPY_VERSION
- sys.pypy_version_info = PYPY_VERSION
sys.pypy_find_executable = pypy_find_executable
sys.pypy_find_stdlib = pypy_find_stdlib
sys.cpython_path = sys.path[:]
- os = nanos.os_module_for_testing
try:
- sys.exit(int(entry_point(sys.argv[0], sys.argv[1:], os)))
+ sys.exit(int(entry_point(sys.argv[0], sys.argv[1:])))
finally:
# restore the normal prompt (which was changed by _pypy_interact), in
# case we are dropping to CPython's prompt
diff --git a/pypy/translator/goal/targetpypystandalone.py b/pypy/translator/goal/targetpypystandalone.py
--- a/pypy/translator/goal/targetpypystandalone.py
+++ b/pypy/translator/goal/targetpypystandalone.py
@@ -27,7 +27,7 @@
w_run_toplevel = space.getitem(w_dict, space.wrap('run_toplevel'))
w_call_finish_gateway = space.wrap(gateway.interp2app(call_finish))
w_call_startup_gateway = space.wrap(gateway.interp2app(call_startup))
- w_os = setup_nanos(space)
+ #w_os = setup_nanos(space)
withjit = space.config.objspace.usemodules.pypyjit
def entry_point(argv):
@@ -56,7 +56,7 @@
w_executable = space.wrap(argv[0])
w_argv = space.newlist([space.wrap(s) for s in argv[1:]])
space.timer.start("w_entry_point")
- w_exitcode = space.call_function(w_entry_point, w_executable, w_argv, w_os)
+ w_exitcode = space.call_function(w_entry_point, w_executable, w_argv)
space.timer.stop("w_entry_point")
exitcode = space.int_w(w_exitcode)
# try to pull it all in
diff --git a/pypy/translator/goal/test2/test_app_main.py b/pypy/translator/goal/test2/test_app_main.py
--- a/pypy/translator/goal/test2/test_app_main.py
+++ b/pypy/translator/goal/test2/test_app_main.py
@@ -221,7 +221,7 @@
pexpect.__version__,))
kwds.setdefault('timeout', 10)
- print 'SPAWN:', args, kwds
+ print 'SPAWN:', ' '.join([args[0]] + args[1]), kwds
child = pexpect.spawn(*args, **kwds)
child.logfile = sys.stdout
return child
@@ -733,6 +733,7 @@
assert data == p + os.sep + '\n'
def test_getfilesystemencoding(self):
+ py.test.skip("this has been failing since forever, but it's not tested nightly because buildbot uses python2.6 :-(")
if sys.version_info < (2, 7):
skip("test requires Python >= 2.7")
p = getscript_in_dir("""
@@ -841,7 +842,6 @@
sys.path.append(self.goal_dir)
try:
import app_main
- app_main.os = os
app_main.setup_bootstrap_path('/tmp/pypy-c') # stdlib not found
sys.path == old_sys_path
assert sys.executable == ''
@@ -863,7 +863,6 @@
sys.path.append(self.goal_dir)
try:
import app_main
- app_main.os = os
pypy_c = os.path.join(self.trunkdir, 'pypy', 'translator', 'goal', 'pypy-c')
app_main.setup_bootstrap_path(pypy_c)
newpath = sys.path[:]
@@ -883,7 +882,7 @@
try:
import app_main
pypy_c = os.path.join(self.trunkdir, 'pypy', 'translator', 'goal', 'pypy-c')
- app_main.entry_point(pypy_c, ['-c', 'pass'], os)
+ app_main.entry_point(pypy_c, ['-c', 'pass'])
# assert it did not crash
finally:
sys.path[:] = old_sys_path
More information about the pypy-commit
mailing list