[pypy-svn] r12701 - in pypy/branch/0.6.x/pypy: interpreter translator

arigo at codespeak.net arigo at codespeak.net
Sat May 21 13:04:07 CEST 2005


Author: arigo
Date: Sat May 21 13:04:06 2005
New Revision: 12701

Modified:
   pypy/branch/0.6.x/pypy/interpreter/gateway.py
   pypy/branch/0.6.x/pypy/translator/geninterplevel.py
Log:
issue75 testing

Moved a hack elsewhere, basically.  Importing stringobject's apphelpers from
the cache didn't find _formatting at interp-level.  This is all very broken,
but out of reach of a simple clean-up.


Modified: pypy/branch/0.6.x/pypy/interpreter/gateway.py
==============================================================================
--- pypy/branch/0.6.x/pypy/interpreter/gateway.py	(original)
+++ pypy/branch/0.6.x/pypy/interpreter/gateway.py	Sat May 21 13:04:06 2005
@@ -7,7 +7,7 @@
 
 """
 
-import types, sys, md5, os
+import types, sys, md5, os, autopath
 
 NoneNotWrapped = object()
 
@@ -595,32 +595,38 @@
             cls._setup()
 
         from pypy.translator.geninterplevel import translate_as_module
-        scramble = md5.new(cls.seed)
-        scramble.update(self.source)
-        key = scramble.hexdigest()
-        initfunc = cls.known_source.get(key)
-        if not initfunc:
-            # try to get it from file
-            name = key
-            if self.filename:
-                prename = os.path.splitext(os.path.basename(self.filename))[0]
-            else:
-                prename = 'zznoname'
-            name = "%s_%s" % (prename, name)
-            try:
-                __import__("pypy._cache."+name)
-            except ImportError, x:
-                # print x
-                pass
-            else:
-                initfunc = cls.known_source[key]
-        if not initfunc:
-            # build it and put it into a file
-            initfunc, newsrc = translate_as_module(
-                self.source, self.filename, self.modname)
-            fname = cls.cache_path.join(name+".py").strpath
-            f = file(fname, "w")
-            print >> f, """\
+
+        # XXX HACK HACK HACK XXX
+        # XXX allow the app-level code to contain e.g. "import _formatting"
+        libdir = os.path.join(autopath.pypydir, "lib")
+        sys.path.append(libdir)
+        try:
+            scramble = md5.new(cls.seed)
+            scramble.update(self.source)
+            key = scramble.hexdigest()
+            initfunc = cls.known_source.get(key)
+            if not initfunc:
+                # try to get it from file
+                name = key
+                if self.filename:
+                    prename = os.path.splitext(os.path.basename(self.filename))[0]
+                else:
+                    prename = 'zznoname'
+                name = "%s_%s" % (prename, name)
+                try:
+                    __import__("pypy._cache."+name)
+                except ImportError, x:
+                    # print x
+                    pass
+                else:
+                    initfunc = cls.known_source[key]
+            if not initfunc:
+                # build it and put it into a file
+                initfunc, newsrc = translate_as_module(
+                    self.source, self.filename, self.modname)
+                fname = cls.cache_path.join(name+".py").strpath
+                f = file(fname, "w")
+                print >> f, """\
 # self-destruct on double-click:
 if __name__ == "__main__":
     from pypy import _cache
@@ -631,11 +637,14 @@
             os.unlink(namestart+ending)
         except os.error:
             pass""" % name
-            print >> f
-            print >> f, newsrc
-            print >> f, "from pypy._cache import known_source"
-            print >> f, "known_source[%r] = %s" % (key, initfunc.__name__)
-        w_glob = initfunc(space)
+                print >> f
+                print >> f, newsrc
+                print >> f, "from pypy._cache import known_source"
+                print >> f, "known_source[%r] = %s" % (key, initfunc.__name__)
+            w_glob = initfunc(space)
+        finally:
+            if libdir in sys.path:
+                sys.path.remove(libdir)
         return w_glob
     build_applevelinterp_dict = classmethod(build_applevelinterp_dict)
 

Modified: pypy/branch/0.6.x/pypy/translator/geninterplevel.py
==============================================================================
--- pypy/branch/0.6.x/pypy/translator/geninterplevel.py	(original)
+++ pypy/branch/0.6.x/pypy/translator/geninterplevel.py	Sat May 21 13:04:06 2005
@@ -1296,15 +1296,7 @@
     dic = {'__name__': modname}
     if filename:
         dic['__file__'] = filename
-
-    # XXX allow the app-level code to contain e.g. "import _formatting"
-    libdir = os.path.join(pypy.__path__[0], "lib")
-    hold = sys.path[:]
-    sys.path.insert(0, libdir)
-    try:
-        exec code in dic
-    finally:
-        sys.path[:] = hold
+    exec code in dic
 
     entrypoint = dic
     t = Translator(None, verbose=False, simplifying=needed_passes,



More information about the Pypy-commit mailing list