[pypy-svn] r7432 - in pypy/trunk/src/pypy: annotation/test appspace appspace/test interpreter interpreter/test module/test objspace/flow/test objspace/std objspace/std/test objspace/test tool tool/test translator translator/test translator/tool translator/tool/pygame

bob at codespeak.net bob at codespeak.net
Fri Nov 19 12:48:21 CET 2004


Author: bob
Date: Fri Nov 19 12:48:20 2004
New Revision: 7432

Modified:
   pypy/trunk/src/pypy/annotation/test/autopath.py
   pypy/trunk/src/pypy/appspace/autopath.py
   pypy/trunk/src/pypy/appspace/test/autopath.py
   pypy/trunk/src/pypy/interpreter/autopath.py
   pypy/trunk/src/pypy/interpreter/test/autopath.py
   pypy/trunk/src/pypy/module/test/autopath.py
   pypy/trunk/src/pypy/objspace/flow/test/autopath.py
   pypy/trunk/src/pypy/objspace/std/autopath.py
   pypy/trunk/src/pypy/objspace/std/test/autopath.py
   pypy/trunk/src/pypy/objspace/test/autopath.py
   pypy/trunk/src/pypy/tool/autopath.py
   pypy/trunk/src/pypy/tool/test/autopath.py
   pypy/trunk/src/pypy/translator/autopath.py
   pypy/trunk/src/pypy/translator/test/autopath.py
   pypy/trunk/src/pypy/translator/tool/autopath.py
   pypy/trunk/src/pypy/translator/tool/pygame/autopath.py
Log:
more stupid autopath tricks, make sure that a module run as a script also
works as if it was imported as a module



Modified: pypy/trunk/src/pypy/annotation/test/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/test/autopath.py	(original)
+++ pypy/trunk/src/pypy/annotation/test/autopath.py	Fri Nov 19 12:48:20 2004
@@ -49,6 +49,33 @@
         if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
             sys.path.remove(orig)
     sys.path.insert(0, head)
+
+    munged = {}
+    for name, mod in sys.modules.items():
+        fn = getattr(mod, '__file__', None)
+        if '.' in name or not isinstance(fn, str):
+            continue
+        newname = os.path.splitext(os.path.basename(fn))[0]
+        path = os.path.join(os.path.dirname(os.path.realpath(fn)), '')
+        if path.startswith(pypy_root) and newname != part:
+            modpaths = os.path.normpath(path[len(pypy_root):]).split(os.sep)
+            if newname != '__init__':
+                modpaths.append(newname)
+            modpath = '.'.join(modpaths)
+            if modpath not in sys.modules:
+                munged[modpath] = mod
+
+    for name, mod in munged.iteritems():
+        if name not in sys.modules:
+            sys.modules[name] = mod
+        if '.' in name:
+            prename = name[:name.rfind('.')]
+            postname = name[len(prename)+1:]
+            if prename not in sys.modules:
+                __import__(prename)
+                if not hasattr(sys.modules[prename], postname):
+                    setattr(sys.modules[prename], postname, mod)
+
     return partdir, this_dir
 
 def __clone():

Modified: pypy/trunk/src/pypy/appspace/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/appspace/autopath.py	(original)
+++ pypy/trunk/src/pypy/appspace/autopath.py	Fri Nov 19 12:48:20 2004
@@ -49,6 +49,33 @@
         if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
             sys.path.remove(orig)
     sys.path.insert(0, head)
+
+    munged = {}
+    for name, mod in sys.modules.items():
+        fn = getattr(mod, '__file__', None)
+        if '.' in name or not isinstance(fn, str):
+            continue
+        newname = os.path.splitext(os.path.basename(fn))[0]
+        path = os.path.join(os.path.dirname(os.path.realpath(fn)), '')
+        if path.startswith(pypy_root) and newname != part:
+            modpaths = os.path.normpath(path[len(pypy_root):]).split(os.sep)
+            if newname != '__init__':
+                modpaths.append(newname)
+            modpath = '.'.join(modpaths)
+            if modpath not in sys.modules:
+                munged[modpath] = mod
+
+    for name, mod in munged.iteritems():
+        if name not in sys.modules:
+            sys.modules[name] = mod
+        if '.' in name:
+            prename = name[:name.rfind('.')]
+            postname = name[len(prename)+1:]
+            if prename not in sys.modules:
+                __import__(prename)
+                if not hasattr(sys.modules[prename], postname):
+                    setattr(sys.modules[prename], postname, mod)
+
     return partdir, this_dir
 
 def __clone():

Modified: pypy/trunk/src/pypy/appspace/test/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/appspace/test/autopath.py	(original)
+++ pypy/trunk/src/pypy/appspace/test/autopath.py	Fri Nov 19 12:48:20 2004
@@ -49,6 +49,33 @@
         if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
             sys.path.remove(orig)
     sys.path.insert(0, head)
+
+    munged = {}
+    for name, mod in sys.modules.items():
+        fn = getattr(mod, '__file__', None)
+        if '.' in name or not isinstance(fn, str):
+            continue
+        newname = os.path.splitext(os.path.basename(fn))[0]
+        path = os.path.join(os.path.dirname(os.path.realpath(fn)), '')
+        if path.startswith(pypy_root) and newname != part:
+            modpaths = os.path.normpath(path[len(pypy_root):]).split(os.sep)
+            if newname != '__init__':
+                modpaths.append(newname)
+            modpath = '.'.join(modpaths)
+            if modpath not in sys.modules:
+                munged[modpath] = mod
+
+    for name, mod in munged.iteritems():
+        if name not in sys.modules:
+            sys.modules[name] = mod
+        if '.' in name:
+            prename = name[:name.rfind('.')]
+            postname = name[len(prename)+1:]
+            if prename not in sys.modules:
+                __import__(prename)
+                if not hasattr(sys.modules[prename], postname):
+                    setattr(sys.modules[prename], postname, mod)
+
     return partdir, this_dir
 
 def __clone():

Modified: pypy/trunk/src/pypy/interpreter/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/autopath.py	(original)
+++ pypy/trunk/src/pypy/interpreter/autopath.py	Fri Nov 19 12:48:20 2004
@@ -49,6 +49,33 @@
         if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
             sys.path.remove(orig)
     sys.path.insert(0, head)
+
+    munged = {}
+    for name, mod in sys.modules.items():
+        fn = getattr(mod, '__file__', None)
+        if '.' in name or not isinstance(fn, str):
+            continue
+        newname = os.path.splitext(os.path.basename(fn))[0]
+        path = os.path.join(os.path.dirname(os.path.realpath(fn)), '')
+        if path.startswith(pypy_root) and newname != part:
+            modpaths = os.path.normpath(path[len(pypy_root):]).split(os.sep)
+            if newname != '__init__':
+                modpaths.append(newname)
+            modpath = '.'.join(modpaths)
+            if modpath not in sys.modules:
+                munged[modpath] = mod
+
+    for name, mod in munged.iteritems():
+        if name not in sys.modules:
+            sys.modules[name] = mod
+        if '.' in name:
+            prename = name[:name.rfind('.')]
+            postname = name[len(prename)+1:]
+            if prename not in sys.modules:
+                __import__(prename)
+                if not hasattr(sys.modules[prename], postname):
+                    setattr(sys.modules[prename], postname, mod)
+
     return partdir, this_dir
 
 def __clone():

Modified: pypy/trunk/src/pypy/interpreter/test/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/test/autopath.py	(original)
+++ pypy/trunk/src/pypy/interpreter/test/autopath.py	Fri Nov 19 12:48:20 2004
@@ -49,6 +49,33 @@
         if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
             sys.path.remove(orig)
     sys.path.insert(0, head)
+
+    munged = {}
+    for name, mod in sys.modules.items():
+        fn = getattr(mod, '__file__', None)
+        if '.' in name or not isinstance(fn, str):
+            continue
+        newname = os.path.splitext(os.path.basename(fn))[0]
+        path = os.path.join(os.path.dirname(os.path.realpath(fn)), '')
+        if path.startswith(pypy_root) and newname != part:
+            modpaths = os.path.normpath(path[len(pypy_root):]).split(os.sep)
+            if newname != '__init__':
+                modpaths.append(newname)
+            modpath = '.'.join(modpaths)
+            if modpath not in sys.modules:
+                munged[modpath] = mod
+
+    for name, mod in munged.iteritems():
+        if name not in sys.modules:
+            sys.modules[name] = mod
+        if '.' in name:
+            prename = name[:name.rfind('.')]
+            postname = name[len(prename)+1:]
+            if prename not in sys.modules:
+                __import__(prename)
+                if not hasattr(sys.modules[prename], postname):
+                    setattr(sys.modules[prename], postname, mod)
+
     return partdir, this_dir
 
 def __clone():

Modified: pypy/trunk/src/pypy/module/test/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/module/test/autopath.py	(original)
+++ pypy/trunk/src/pypy/module/test/autopath.py	Fri Nov 19 12:48:20 2004
@@ -49,6 +49,33 @@
         if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
             sys.path.remove(orig)
     sys.path.insert(0, head)
+
+    munged = {}
+    for name, mod in sys.modules.items():
+        fn = getattr(mod, '__file__', None)
+        if '.' in name or not isinstance(fn, str):
+            continue
+        newname = os.path.splitext(os.path.basename(fn))[0]
+        path = os.path.join(os.path.dirname(os.path.realpath(fn)), '')
+        if path.startswith(pypy_root) and newname != part:
+            modpaths = os.path.normpath(path[len(pypy_root):]).split(os.sep)
+            if newname != '__init__':
+                modpaths.append(newname)
+            modpath = '.'.join(modpaths)
+            if modpath not in sys.modules:
+                munged[modpath] = mod
+
+    for name, mod in munged.iteritems():
+        if name not in sys.modules:
+            sys.modules[name] = mod
+        if '.' in name:
+            prename = name[:name.rfind('.')]
+            postname = name[len(prename)+1:]
+            if prename not in sys.modules:
+                __import__(prename)
+                if not hasattr(sys.modules[prename], postname):
+                    setattr(sys.modules[prename], postname, mod)
+
     return partdir, this_dir
 
 def __clone():

Modified: pypy/trunk/src/pypy/objspace/flow/test/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/flow/test/autopath.py	(original)
+++ pypy/trunk/src/pypy/objspace/flow/test/autopath.py	Fri Nov 19 12:48:20 2004
@@ -49,6 +49,33 @@
         if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
             sys.path.remove(orig)
     sys.path.insert(0, head)
+
+    munged = {}
+    for name, mod in sys.modules.items():
+        fn = getattr(mod, '__file__', None)
+        if '.' in name or not isinstance(fn, str):
+            continue
+        newname = os.path.splitext(os.path.basename(fn))[0]
+        path = os.path.join(os.path.dirname(os.path.realpath(fn)), '')
+        if path.startswith(pypy_root) and newname != part:
+            modpaths = os.path.normpath(path[len(pypy_root):]).split(os.sep)
+            if newname != '__init__':
+                modpaths.append(newname)
+            modpath = '.'.join(modpaths)
+            if modpath not in sys.modules:
+                munged[modpath] = mod
+
+    for name, mod in munged.iteritems():
+        if name not in sys.modules:
+            sys.modules[name] = mod
+        if '.' in name:
+            prename = name[:name.rfind('.')]
+            postname = name[len(prename)+1:]
+            if prename not in sys.modules:
+                __import__(prename)
+                if not hasattr(sys.modules[prename], postname):
+                    setattr(sys.modules[prename], postname, mod)
+
     return partdir, this_dir
 
 def __clone():

Modified: pypy/trunk/src/pypy/objspace/std/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/autopath.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/autopath.py	Fri Nov 19 12:48:20 2004
@@ -49,6 +49,33 @@
         if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
             sys.path.remove(orig)
     sys.path.insert(0, head)
+
+    munged = {}
+    for name, mod in sys.modules.items():
+        fn = getattr(mod, '__file__', None)
+        if '.' in name or not isinstance(fn, str):
+            continue
+        newname = os.path.splitext(os.path.basename(fn))[0]
+        path = os.path.join(os.path.dirname(os.path.realpath(fn)), '')
+        if path.startswith(pypy_root) and newname != part:
+            modpaths = os.path.normpath(path[len(pypy_root):]).split(os.sep)
+            if newname != '__init__':
+                modpaths.append(newname)
+            modpath = '.'.join(modpaths)
+            if modpath not in sys.modules:
+                munged[modpath] = mod
+
+    for name, mod in munged.iteritems():
+        if name not in sys.modules:
+            sys.modules[name] = mod
+        if '.' in name:
+            prename = name[:name.rfind('.')]
+            postname = name[len(prename)+1:]
+            if prename not in sys.modules:
+                __import__(prename)
+                if not hasattr(sys.modules[prename], postname):
+                    setattr(sys.modules[prename], postname, mod)
+
     return partdir, this_dir
 
 def __clone():

Modified: pypy/trunk/src/pypy/objspace/std/test/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/autopath.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/test/autopath.py	Fri Nov 19 12:48:20 2004
@@ -49,6 +49,33 @@
         if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
             sys.path.remove(orig)
     sys.path.insert(0, head)
+
+    munged = {}
+    for name, mod in sys.modules.items():
+        fn = getattr(mod, '__file__', None)
+        if '.' in name or not isinstance(fn, str):
+            continue
+        newname = os.path.splitext(os.path.basename(fn))[0]
+        path = os.path.join(os.path.dirname(os.path.realpath(fn)), '')
+        if path.startswith(pypy_root) and newname != part:
+            modpaths = os.path.normpath(path[len(pypy_root):]).split(os.sep)
+            if newname != '__init__':
+                modpaths.append(newname)
+            modpath = '.'.join(modpaths)
+            if modpath not in sys.modules:
+                munged[modpath] = mod
+
+    for name, mod in munged.iteritems():
+        if name not in sys.modules:
+            sys.modules[name] = mod
+        if '.' in name:
+            prename = name[:name.rfind('.')]
+            postname = name[len(prename)+1:]
+            if prename not in sys.modules:
+                __import__(prename)
+                if not hasattr(sys.modules[prename], postname):
+                    setattr(sys.modules[prename], postname, mod)
+
     return partdir, this_dir
 
 def __clone():

Modified: pypy/trunk/src/pypy/objspace/test/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/test/autopath.py	(original)
+++ pypy/trunk/src/pypy/objspace/test/autopath.py	Fri Nov 19 12:48:20 2004
@@ -49,6 +49,33 @@
         if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
             sys.path.remove(orig)
     sys.path.insert(0, head)
+
+    munged = {}
+    for name, mod in sys.modules.items():
+        fn = getattr(mod, '__file__', None)
+        if '.' in name or not isinstance(fn, str):
+            continue
+        newname = os.path.splitext(os.path.basename(fn))[0]
+        path = os.path.join(os.path.dirname(os.path.realpath(fn)), '')
+        if path.startswith(pypy_root) and newname != part:
+            modpaths = os.path.normpath(path[len(pypy_root):]).split(os.sep)
+            if newname != '__init__':
+                modpaths.append(newname)
+            modpath = '.'.join(modpaths)
+            if modpath not in sys.modules:
+                munged[modpath] = mod
+
+    for name, mod in munged.iteritems():
+        if name not in sys.modules:
+            sys.modules[name] = mod
+        if '.' in name:
+            prename = name[:name.rfind('.')]
+            postname = name[len(prename)+1:]
+            if prename not in sys.modules:
+                __import__(prename)
+                if not hasattr(sys.modules[prename], postname):
+                    setattr(sys.modules[prename], postname, mod)
+
     return partdir, this_dir
 
 def __clone():

Modified: pypy/trunk/src/pypy/tool/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/tool/autopath.py	(original)
+++ pypy/trunk/src/pypy/tool/autopath.py	Fri Nov 19 12:48:20 2004
@@ -49,6 +49,33 @@
         if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
             sys.path.remove(orig)
     sys.path.insert(0, head)
+
+    munged = {}
+    for name, mod in sys.modules.items():
+        fn = getattr(mod, '__file__', None)
+        if '.' in name or not isinstance(fn, str):
+            continue
+        newname = os.path.splitext(os.path.basename(fn))[0]
+        path = os.path.join(os.path.dirname(os.path.realpath(fn)), '')
+        if path.startswith(pypy_root) and newname != part:
+            modpaths = os.path.normpath(path[len(pypy_root):]).split(os.sep)
+            if newname != '__init__':
+                modpaths.append(newname)
+            modpath = '.'.join(modpaths)
+            if modpath not in sys.modules:
+                munged[modpath] = mod
+
+    for name, mod in munged.iteritems():
+        if name not in sys.modules:
+            sys.modules[name] = mod
+        if '.' in name:
+            prename = name[:name.rfind('.')]
+            postname = name[len(prename)+1:]
+            if prename not in sys.modules:
+                __import__(prename)
+                if not hasattr(sys.modules[prename], postname):
+                    setattr(sys.modules[prename], postname, mod)
+
     return partdir, this_dir
 
 def __clone():

Modified: pypy/trunk/src/pypy/tool/test/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/tool/test/autopath.py	(original)
+++ pypy/trunk/src/pypy/tool/test/autopath.py	Fri Nov 19 12:48:20 2004
@@ -49,6 +49,33 @@
         if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
             sys.path.remove(orig)
     sys.path.insert(0, head)
+
+    munged = {}
+    for name, mod in sys.modules.items():
+        fn = getattr(mod, '__file__', None)
+        if '.' in name or not isinstance(fn, str):
+            continue
+        newname = os.path.splitext(os.path.basename(fn))[0]
+        path = os.path.join(os.path.dirname(os.path.realpath(fn)), '')
+        if path.startswith(pypy_root) and newname != part:
+            modpaths = os.path.normpath(path[len(pypy_root):]).split(os.sep)
+            if newname != '__init__':
+                modpaths.append(newname)
+            modpath = '.'.join(modpaths)
+            if modpath not in sys.modules:
+                munged[modpath] = mod
+
+    for name, mod in munged.iteritems():
+        if name not in sys.modules:
+            sys.modules[name] = mod
+        if '.' in name:
+            prename = name[:name.rfind('.')]
+            postname = name[len(prename)+1:]
+            if prename not in sys.modules:
+                __import__(prename)
+                if not hasattr(sys.modules[prename], postname):
+                    setattr(sys.modules[prename], postname, mod)
+
     return partdir, this_dir
 
 def __clone():

Modified: pypy/trunk/src/pypy/translator/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/translator/autopath.py	(original)
+++ pypy/trunk/src/pypy/translator/autopath.py	Fri Nov 19 12:48:20 2004
@@ -49,6 +49,33 @@
         if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
             sys.path.remove(orig)
     sys.path.insert(0, head)
+
+    munged = {}
+    for name, mod in sys.modules.items():
+        fn = getattr(mod, '__file__', None)
+        if '.' in name or not isinstance(fn, str):
+            continue
+        newname = os.path.splitext(os.path.basename(fn))[0]
+        path = os.path.join(os.path.dirname(os.path.realpath(fn)), '')
+        if path.startswith(pypy_root) and newname != part:
+            modpaths = os.path.normpath(path[len(pypy_root):]).split(os.sep)
+            if newname != '__init__':
+                modpaths.append(newname)
+            modpath = '.'.join(modpaths)
+            if modpath not in sys.modules:
+                munged[modpath] = mod
+
+    for name, mod in munged.iteritems():
+        if name not in sys.modules:
+            sys.modules[name] = mod
+        if '.' in name:
+            prename = name[:name.rfind('.')]
+            postname = name[len(prename)+1:]
+            if prename not in sys.modules:
+                __import__(prename)
+                if not hasattr(sys.modules[prename], postname):
+                    setattr(sys.modules[prename], postname, mod)
+
     return partdir, this_dir
 
 def __clone():

Modified: pypy/trunk/src/pypy/translator/test/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/translator/test/autopath.py	(original)
+++ pypy/trunk/src/pypy/translator/test/autopath.py	Fri Nov 19 12:48:20 2004
@@ -49,6 +49,33 @@
         if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
             sys.path.remove(orig)
     sys.path.insert(0, head)
+
+    munged = {}
+    for name, mod in sys.modules.items():
+        fn = getattr(mod, '__file__', None)
+        if '.' in name or not isinstance(fn, str):
+            continue
+        newname = os.path.splitext(os.path.basename(fn))[0]
+        path = os.path.join(os.path.dirname(os.path.realpath(fn)), '')
+        if path.startswith(pypy_root) and newname != part:
+            modpaths = os.path.normpath(path[len(pypy_root):]).split(os.sep)
+            if newname != '__init__':
+                modpaths.append(newname)
+            modpath = '.'.join(modpaths)
+            if modpath not in sys.modules:
+                munged[modpath] = mod
+
+    for name, mod in munged.iteritems():
+        if name not in sys.modules:
+            sys.modules[name] = mod
+        if '.' in name:
+            prename = name[:name.rfind('.')]
+            postname = name[len(prename)+1:]
+            if prename not in sys.modules:
+                __import__(prename)
+                if not hasattr(sys.modules[prename], postname):
+                    setattr(sys.modules[prename], postname, mod)
+
     return partdir, this_dir
 
 def __clone():

Modified: pypy/trunk/src/pypy/translator/tool/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/translator/tool/autopath.py	(original)
+++ pypy/trunk/src/pypy/translator/tool/autopath.py	Fri Nov 19 12:48:20 2004
@@ -49,6 +49,33 @@
         if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
             sys.path.remove(orig)
     sys.path.insert(0, head)
+
+    munged = {}
+    for name, mod in sys.modules.items():
+        fn = getattr(mod, '__file__', None)
+        if '.' in name or not isinstance(fn, str):
+            continue
+        newname = os.path.splitext(os.path.basename(fn))[0]
+        path = os.path.join(os.path.dirname(os.path.realpath(fn)), '')
+        if path.startswith(pypy_root) and newname != part:
+            modpaths = os.path.normpath(path[len(pypy_root):]).split(os.sep)
+            if newname != '__init__':
+                modpaths.append(newname)
+            modpath = '.'.join(modpaths)
+            if modpath not in sys.modules:
+                munged[modpath] = mod
+
+    for name, mod in munged.iteritems():
+        if name not in sys.modules:
+            sys.modules[name] = mod
+        if '.' in name:
+            prename = name[:name.rfind('.')]
+            postname = name[len(prename)+1:]
+            if prename not in sys.modules:
+                __import__(prename)
+                if not hasattr(sys.modules[prename], postname):
+                    setattr(sys.modules[prename], postname, mod)
+
     return partdir, this_dir
 
 def __clone():

Modified: pypy/trunk/src/pypy/translator/tool/pygame/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/translator/tool/pygame/autopath.py	(original)
+++ pypy/trunk/src/pypy/translator/tool/pygame/autopath.py	Fri Nov 19 12:48:20 2004
@@ -49,6 +49,33 @@
         if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
             sys.path.remove(orig)
     sys.path.insert(0, head)
+
+    munged = {}
+    for name, mod in sys.modules.items():
+        fn = getattr(mod, '__file__', None)
+        if '.' in name or not isinstance(fn, str):
+            continue
+        newname = os.path.splitext(os.path.basename(fn))[0]
+        path = os.path.join(os.path.dirname(os.path.realpath(fn)), '')
+        if path.startswith(pypy_root) and newname != part:
+            modpaths = os.path.normpath(path[len(pypy_root):]).split(os.sep)
+            if newname != '__init__':
+                modpaths.append(newname)
+            modpath = '.'.join(modpaths)
+            if modpath not in sys.modules:
+                munged[modpath] = mod
+
+    for name, mod in munged.iteritems():
+        if name not in sys.modules:
+            sys.modules[name] = mod
+        if '.' in name:
+            prename = name[:name.rfind('.')]
+            postname = name[len(prename)+1:]
+            if prename not in sys.modules:
+                __import__(prename)
+                if not hasattr(sys.modules[prename], postname):
+                    setattr(sys.modules[prename], postname, mod)
+
     return partdir, this_dir
 
 def __clone():



More information about the Pypy-commit mailing list