[pypy-commit] pypy py3k: make __file/cached__ overwriting optional in _run_compiled_module as app_main
pjenvey
noreply at buildbot.pypy.org
Fri Feb 22 01:41:27 CET 2013
Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r61578:8632713d526b
Date: 2013-02-21 16:03 -0800
http://bitbucket.org/pypy/pypy/changeset/8632713d526b/
Log: make __file/cached__ overwriting optional in _run_compiled_module as
app_main doesn't want it
diff --git a/pypy/interpreter/app_main.py b/pypy/interpreter/app_main.py
--- a/pypy/interpreter/app_main.py
+++ b/pypy/interpreter/app_main.py
@@ -615,7 +615,7 @@
filename = filename.lower()
if filename.endswith('.pyc') or filename.endswith('.pyo'):
args = (imp._run_compiled_module, '__main__',
- sys.argv[0], None, mainmodule)
+ sys.argv[0], None, mainmodule, False)
else:
# maybe it's the name of a directory or a zip file
filename = sys.argv[0]
@@ -762,7 +762,7 @@
# add an emulator for these pypy-only or 2.7-only functions
# (for test_pyc_commandline_argument)
import imp, runpy
- def _run_compiled_module(modulename, filename, file, module):
+ def _run_compiled_module(modulename, filename, file, module, write_paths):
import os
assert modulename == '__main__'
assert os.path.isfile(filename)
diff --git a/pypy/module/imp/importing.py b/pypy/module/imp/importing.py
--- a/pypy/module/imp/importing.py
+++ b/pypy/module/imp/importing.py
@@ -856,17 +856,19 @@
pycode = ec.compiler.compile(source, pathname, 'exec', 0)
return pycode
-def exec_code_module(space, w_mod, code_w, pathname, cpathname):
+def exec_code_module(space, w_mod, code_w, pathname, cpathname,
+ write_paths=True):
w_dict = space.getattr(w_mod, space.wrap('__dict__'))
space.call_method(w_dict, 'setdefault',
space.wrap('__builtins__'),
space.wrap(space.builtin))
- if pathname is not None:
- w_pathname = get_sourcefile(space, pathname)
- else:
- w_pathname = space.wrap(code_w.co_filename)
- space.setitem(w_dict, space.wrap("__file__"), w_pathname)
- space.setitem(w_dict, space.wrap("__cached__"), space.wrap(cpathname))
+ if write_paths:
+ if pathname is not None:
+ w_pathname = get_sourcefile(space, pathname)
+ else:
+ w_pathname = space.wrap(code_w.co_filename)
+ space.setitem(w_dict, space.wrap("__file__"), w_pathname)
+ space.setitem(w_dict, space.wrap("__cached__"), space.wrap(cpathname))
code_w.exec_code(space, w_dict, w_dict)
def rightmost_sep(filename):
@@ -1065,7 +1067,7 @@
@jit.dont_look_inside
def load_compiled_module(space, w_modulename, w_mod, cpathname, magic,
- timestamp, source):
+ timestamp, source, write_paths=True):
"""
Load a module from a compiled file, execute it, and return its
module object.
@@ -1076,7 +1078,7 @@
"Bad magic number in %s", cpathname)
#print "loading pyc file:", cpathname
code_w = read_compiled_module(space, cpathname, source)
- exec_code_module(space, w_mod, code_w, cpathname, cpathname)
+ exec_code_module(space, w_mod, code_w, cpathname, cpathname, write_paths)
return w_mod
diff --git a/pypy/module/imp/interp_imp.py b/pypy/module/imp/interp_imp.py
--- a/pypy/module/imp/interp_imp.py
+++ b/pypy/module/imp/interp_imp.py
@@ -138,8 +138,9 @@
stream.close()
return w_mod
- at unwrap_spec(filename='str0')
-def _run_compiled_module(space, w_modulename, filename, w_file, w_module):
+ at unwrap_spec(filename='str0', write_paths=bool)
+def _run_compiled_module(space, w_modulename, filename, w_file, w_module,
+ write_paths=True):
# the function 'imp._run_compiled_module' is a pypy-only extension
stream = get_file(space, w_file, filename, 'rb')
@@ -148,7 +149,7 @@
importing.load_compiled_module(
space, w_modulename, w_module, filename, magic, timestamp,
- stream.readall())
+ stream.readall(), write_paths)
if space.is_none(w_file):
stream.close()
More information about the pypy-commit
mailing list