Commits

Philip Jenvey  committed 8632713

make __file/cached__ overwriting optional in _run_compiled_module as app_main
doesn't want it

  • Participants
  • Parent commits 130ac05
  • Branches py3k

Comments (0)

Files changed (3)

File pypy/interpreter/app_main.py

                 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]
     # 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)

File pypy/module/imp/importing.py

     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):
 
 @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.
                               "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
 

File pypy/module/imp/interp_imp.py

         stream.close()
     return w_mod
 
-@unwrap_spec(filename='str0')
-def _run_compiled_module(space, w_modulename, filename, w_file, w_module):
+@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')
 
 
     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()