[pypy-svn] r74966 - in pypy/branch/sys-prefix/pypy: interpreter interpreter/test module/sys tool tool/test translator

antocuni at codespeak.net antocuni at codespeak.net
Mon May 31 12:53:36 CEST 2010


Author: antocuni
Date: Mon May 31 12:53:35 2010
New Revision: 74966

Added:
   pypy/branch/sys-prefix/pypy/tool/lib_pypy.py   (contents, props changed)
   pypy/branch/sys-prefix/pypy/tool/test/test_lib_pypy.py   (contents, props changed)
Modified:
   pypy/branch/sys-prefix/pypy/interpreter/baseobjspace.py
   pypy/branch/sys-prefix/pypy/interpreter/test/test_module.py
   pypy/branch/sys-prefix/pypy/interpreter/test/test_objspace.py
   pypy/branch/sys-prefix/pypy/module/sys/state.py
   pypy/branch/sys-prefix/pypy/module/sys/version.py
   pypy/branch/sys-prefix/pypy/translator/geninterplevel.py
Log:
fix a couple of places that hardcoded the path to pypy/lib, and add a tool
function to get the path to lib_pypy



Modified: pypy/branch/sys-prefix/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/sys-prefix/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/branch/sys-prefix/pypy/interpreter/baseobjspace.py	Mon May 31 12:53:35 2010
@@ -385,6 +385,7 @@
 
     def get_builtinmodule_to_install(self):
         """NOT_RPYTHON"""
+        from pypy.tool.lib_pypy import get_lib_pypy_dir
         try:
             return self._builtinmodule_list
         except AttributeError:
@@ -402,11 +403,10 @@
         if ('time2' in modules or 'rctime' in modules) and 'time' in modules:
             modules.remove('time')
 
+        lib_pypy = get_lib_pypy_dir()
         if not self.config.objspace.nofaking:
             for modname in self.ALL_BUILTIN_MODULES:
-                if not (os.path.exists(
-                        os.path.join(os.path.dirname(pypy.__file__),
-                                     'lib', modname+'.py'))):
+                if not lib_pypy.join(modname+'.py').check(file=True):
                     modules.append('faked+'+modname)
 
         self._builtinmodule_list = modules

Modified: pypy/branch/sys-prefix/pypy/interpreter/test/test_module.py
==============================================================================
--- pypy/branch/sys-prefix/pypy/interpreter/test/test_module.py	(original)
+++ pypy/branch/sys-prefix/pypy/interpreter/test/test_module.py	Mon May 31 12:53:35 2010
@@ -57,8 +57,8 @@
         import _pypy_interact # known to be in pypy/lib
         r = repr(_pypy_interact)
         assert (r.startswith("<module '_pypy_interact' from ") and
-                ('pypy/lib/_pypy_interact.py' in r or
-                 r'pypy\\lib\\_pypy_interact.py' in r.lower()) and
+                ('lib_pypy/_pypy_interact.py' in r or
+                 r'lib_pypy\\_interact.py' in r.lower()) and
                 r.endswith('>'))
         nofile = type(_pypy_interact)('nofile', 'foo')
         assert repr(nofile) == "<module 'nofile' from ?>"

Modified: pypy/branch/sys-prefix/pypy/interpreter/test/test_objspace.py
==============================================================================
--- pypy/branch/sys-prefix/pypy/interpreter/test/test_objspace.py	(original)
+++ pypy/branch/sys-prefix/pypy/interpreter/test/test_objspace.py	Mon May 31 12:53:35 2010
@@ -259,3 +259,23 @@
     def test_sys_import(self):
         from pypy.interpreter.main import run_string
         run_string('import sys', space=self.space)
+
+    def test_get_builtinmodule_to_install(self):
+        space = self.space
+        try:
+            # force rebuilding with this fake builtin
+            space.ALL_BUILTIN_MODULES.append('this_doesnt_exist')
+            del space._builtinmodule_list
+            mods = space.get_builtinmodule_to_install()
+            
+            assert '__pypy__' in mods                # real builtin
+            assert 'array' not in mods               # in lib_pypy
+            assert 'faked+array' not in mods         # in lib_pypy
+            assert 'this_doesnt_exist' not in mods   # not in lib_pypy
+            assert 'faked+this_doesnt_exist' in mods # not in lib_pypy, but in
+                                                     # ALL_BUILTIN_MODULES
+        finally:
+            # rebuild the original list
+            space.ALL_BUILTIN_MODULES.pop()
+            del space._builtinmodule_list
+            mods = space.get_builtinmodule_to_install()

Modified: pypy/branch/sys-prefix/pypy/module/sys/state.py
==============================================================================
--- pypy/branch/sys-prefix/pypy/module/sys/state.py	(original)
+++ pypy/branch/sys-prefix/pypy/module/sys/state.py	Mon May 31 12:53:35 2010
@@ -35,7 +35,7 @@
 def getinitialpath(srcdir):
     # build the initial path from the srcdir, which is the path of
     # the "dist" directory of a PyPy checkout.
-    from pypy.module.sys.version import CPYTHON_VERSION
+    from pypy.module.sys.version import CPYTHON_VERSION, PYPY_VERSION
 
     dirname = '%d.%d.%d' % (CPYTHON_VERSION[0],
                             CPYTHON_VERSION[1],
@@ -46,12 +46,14 @@
     checkdir(python_std_lib)
     python_std_lib_modified = os.path.join(lib_python, 'modified-' + dirname)
     checkdir(python_std_lib_modified)
-    pypydir = os.path.join(srcdir, 'pypy')
-    pypy_lib = os.path.join(pypydir, 'lib')
-    checkdir(pypy_lib)
+    
+    libdir = os.path.join(srcdir, 'lib')
+    pypyxy_dir = os.path.join(libdir, 'pypy%d.%d' % PYPY_VERSION[:2])
+    lib_pypy = os.path.join(pypyxy_dir, 'lib_pypy')
+    checkdir(lib_pypy)
 
     importlist = []
-    importlist.append(pypy_lib)
+    importlist.append(lib_pypy)
     importlist.append(python_std_lib_modified)
     importlist.append(python_std_lib)
     return importlist

Modified: pypy/branch/sys-prefix/pypy/module/sys/version.py
==============================================================================
--- pypy/branch/sys-prefix/pypy/module/sys/version.py	(original)
+++ pypy/branch/sys-prefix/pypy/module/sys/version.py	Mon May 31 12:53:35 2010
@@ -7,6 +7,7 @@
 CPYTHON_VERSION            = (2, 5, 2, "beta", 42)
 CPYTHON_API_VERSION        = 1012
 
+# when changing the pypy version, remind to also change the name of trunk/lib/pypyX.Y
 PYPY_VERSION               = (1, 2, 0, "beta", '?')
 # the last item is replaced by the svn revision ^^^
 

Added: pypy/branch/sys-prefix/pypy/tool/lib_pypy.py
==============================================================================
--- (empty file)
+++ pypy/branch/sys-prefix/pypy/tool/lib_pypy.py	Mon May 31 12:53:35 2010
@@ -0,0 +1,8 @@
+import py
+import pypy
+from pypy.module.sys.version import PYPY_VERSION
+
+def get_lib_pypy_dir():
+    prefix = py.path.local(pypy.__path__[0]).dirpath()
+    pypy_ver = 'pypy%d.%d' % PYPY_VERSION[:2]
+    return prefix.join('lib', pypy_ver, 'lib_pypy')

Added: pypy/branch/sys-prefix/pypy/tool/test/test_lib_pypy.py
==============================================================================
--- (empty file)
+++ pypy/branch/sys-prefix/pypy/tool/test/test_lib_pypy.py	Mon May 31 12:53:35 2010
@@ -0,0 +1,6 @@
+import py
+from pypy.tool import lib_pypy
+
+def test_lib_pypy_exists():
+    dirname = lib_pypy.get_lib_pypy_dir()
+    assert dirname.check(dir=1)

Modified: pypy/branch/sys-prefix/pypy/translator/geninterplevel.py
==============================================================================
--- pypy/branch/sys-prefix/pypy/translator/geninterplevel.py	(original)
+++ pypy/branch/sys-prefix/pypy/translator/geninterplevel.py	Mon May 31 12:53:35 2010
@@ -1473,6 +1473,7 @@
     dic = initfunc(space)
     # and now use the members of the dict
     """
+    from pypy.tool.lib_pypy import get_lib_pypy_dir
     # create something like a module
     if type(sourcetext) is str:
         code = py.code.Source(sourcetext).compile()
@@ -1484,12 +1485,7 @@
         dic['__file__'] = filename
 
     # XXX allow the app-level code to contain e.g. "import _formatting"
-    for pkgdir in pypy.__path__:
-        libdir = os.path.join(pkgdir, "lib")
-        if os.path.isdir(libdir):
-            break
-    else:
-        raise Exception, "cannot find pypy/lib directory"
+    libdir = str(get_lib_pypy_dir())
     sys.path.insert(0, libdir)
     try:
         if faked_set:



More information about the Pypy-commit mailing list