[pypy-svn] r15148 - in pypy/dist/pypy: interpreter module/sys tool

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Jul 26 20:49:17 CEST 2005


Author: cfbolz
Date: Tue Jul 26 20:49:16 2005
New Revision: 15148

Modified:
   pypy/dist/pypy/interpreter/baseobjspace.py
   pypy/dist/pypy/interpreter/gateway.py
   pypy/dist/pypy/module/sys/state.py
   pypy/dist/pypy/tool/option.py
Log:
(pedronis, cfbolz):

started to clean PyPy faked module handling.
added a --nofakedmodule option.



Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py	Tue Jul 26 20:49:16 2005
@@ -97,7 +97,7 @@
 
 class ObjSpace(object):
     """Base class for the interpreter-level implementations of object spaces.
-    http://codespeak.net/moin/pypy/moin.cgi/ObjectSpace"""
+    http://codespeak.net/pypy/index.cgi?doc/objspace.html"""
     
     full_exceptions = True  # full support for exceptions (normalization & more)
 
@@ -133,6 +133,28 @@
         w_modules = self.sys.get('modules')
         return self.getitem(w_modules, w_name)
 
+    # change this to influence which of our own
+    # mixed modules should be used 
+    def get_builtinmodule_list(self):
+        """NOT_RPYTHON"""
+        try:
+            return self._builtinmodule_list
+        except AttributeError:
+            builtinmodule_list = [('sys', None), ('__builtin__', None),
+                                  ('exceptions', None)]
+            builtinmodule_list.append(('unicodedata', None))
+            #  Uncomment the following line to enable the builtin _codecs module
+            builtinmodule_list.append(('_codecs', None))
+            builtinmodule_list.append(('marshal', None))
+            if self.options.useparsermodule == "recparser":
+                builtinmodule_list.append(('parser', 'recparser'))
+            elif self.options.useparsermodule == "parser":
+                builtinmodule_list.append(('parser', None))
+            #builtinmodule_list.append(('posix', None))
+            #builtinmodule_list.append(('math', None))
+            self._builtinmodule_list = builtinmodule_list
+            return self._builtinmodule_list
+
     def make_builtins(self):
         "NOT_RPYTHON: only for initializing the space."
 
@@ -148,18 +170,11 @@
         w_builtin = self.wrap(self.builtin)
         self.setitem(w_modules, w_name, w_builtin) 
         self.setitem(self.builtin.w_dict, self.wrap('__builtins__'), w_builtin) 
-        self.setbuiltinmodule('unicodedata')
-        #  Uncomment the following line to enable the builtin _codecs module
-        self.setbuiltinmodule('_codecs')
-        # XXX we need to resolve unwrapping issues to 
-        #     make this the default _sre module
-        #self.setbuiltinmodule("_sre", "_sre_pypy")
-        self.setbuiltinmodule('marshal')
-        if self.options.useparsermodule == "recparser":
-             self.setbuiltinmodule('parser', 'recparser')
-        elif self.options.useparsermodule == "parser":
-            self.setbuiltinmodule('parser')
-        #self.setbuiltinmodule('posix')
+
+        for modname, mixedname in self.get_builtinmodule_list():
+            if modname not in ('sys', '__builtin__', 'exceptions'):
+                self.setbuiltinmodule(modname, mixedname)
+        
         # initialize with "bootstrap types" from objspace  (e.g. w_None)
         for name, value in self.__dict__.items():
             if name.startswith('w_') and not name.endswith('Type'): 

Modified: pypy/dist/pypy/interpreter/gateway.py
==============================================================================
--- pypy/dist/pypy/interpreter/gateway.py	(original)
+++ pypy/dist/pypy/interpreter/gateway.py	Tue Jul 26 20:49:16 2005
@@ -508,7 +508,7 @@
     name at app-level."""
 
     hidden_applevel = True
-    use_geninterp = True    # change this to disable geninterp globally
+    use_geninterp = False    # change this to disable geninterp globally
 
     def __init__(self, source, filename = None, modname = '__builtin__'):
         self.filename = filename

Modified: pypy/dist/pypy/module/sys/state.py
==============================================================================
--- pypy/dist/pypy/module/sys/state.py	(original)
+++ pypy/dist/pypy/module/sys/state.py	Tue Jul 26 20:49:16 2005
@@ -7,7 +7,7 @@
 
 import sys, os 
 
-def hack_cpython_module(modname):
+def load_cpython_module(modname):
     "NOT_RPYTHON. Steal a module from CPython."
     cpy_module = __import__(modname, globals(), locals(), None)
     return cpy_module
@@ -15,45 +15,53 @@
 # ____________________________________________________________
 #
 
-builtin_module_names = ['__builtin__', 'sys', 'exceptions']
-
-# Create the builtin_modules dictionary, mapping names to Module instances
-builtin_modules = {}
-for fn in builtin_module_names:
-    builtin_modules[fn] = None
-
-# The following built-in modules are not written in PyPy, so we
-# steal them from Python.
-for fn in ['posix', 'nt', 'os2', 'mac', 'ce', 'riscos',
-           'math', 'array', 'select',
-           '_random', '_sre', 'time', '_socket', 'errno',
-           'unicodedata',
-           'parser', 'fcntl', '_codecs', 'binascii'
-           ]: 
-    if fn not in builtin_modules and not os.path.exists(
-            os.path.join(os.path.dirname(pypy.__file__),
-                         'lib', fn+'.py')):
-        try:
-            builtin_modules[fn] = hack_cpython_module(fn)
-        except ImportError:
-            pass
-        else:
-            builtin_module_names.append(fn)
-
-builtin_module_names.sort() 
+ALL_BUILTIN_MODULES = [
+    'posix', 'nt', 'os2', 'mac', 'ce', 'riscos',
+    'math', 'array', 'select',
+    '_random', '_sre', 'time', '_socket', 'errno',
+    'unicodedata',
+     'parser', 'fcntl', '_codecs', 'binascii'
+]
 
 class State: 
     def __init__(self, space): 
         self.space = space 
-        self.w_builtin_module_names = space.newtuple(
-            [space.wrap(fn) for fn in builtin_module_names])
+
         self.w_modules = space.newdict([])
-        for fn, module in builtin_modules.items(): 
-            space.setitem(self.w_modules, space.wrap(fn), space.wrap(module))
+        self.complete_builtinmodules()
+
         self.w_warnoptions = space.newlist([])
         self.w_argv = space.newlist([])
         self.setinitialpath(space) 
 
+    def install_faked_module(self, modname):
+        space = self.space
+        try:
+            module = load_cpython_module(modname)
+        except ImportError:
+            return False
+        else:
+            space.setitem(self.w_modules, space.wrap(modname),
+                          space.wrap(module))
+            return True
+
+    def complete_builtinmodules(self):
+        space = self.space
+        builtinmodule_list = self.space.get_builtinmodule_list()
+        builtinmodule_names = [name for name, mixedname in builtinmodule_list]
+
+        if not space.options.nofakedmodules:
+            for modname in ALL_BUILTIN_MODULES:
+                if modname not in builtinmodule_names:
+                    if not (os.path.exists(
+                            os.path.join(os.path.dirname(pypy.__file__),
+                            'lib', modname+'.py'))):
+                        if self.install_faked_module(modname):
+                             builtinmodule_names.append(modname)
+        builtinmodule_names.sort()
+        self.w_builtin_module_names = space.newtuple(
+            [space.wrap(fn) for fn in builtinmodule_names])
+
     def setinitialpath(self, space): 
         # Initialize the default path
         from pypy.interpreter import autopath

Modified: pypy/dist/pypy/tool/option.py
==============================================================================
--- pypy/dist/pypy/tool/option.py	(original)
+++ pypy/dist/pypy/tool/option.py	Tue Jul 26 20:49:16 2005
@@ -10,6 +10,7 @@
     spaces = []
     oldstyle = 0
     uselibfile = 0
+    nofakedmodules = 0
     useparsermodule = "recparser" # "cpython" / "recparser" / "parser"
     compiler = "pyparse" # "cpython"
                          # "pyparse" pypy parser, cpython's compiler package
@@ -39,6 +40,9 @@
         '--file', action="store_true",dest="uselibfile",
         help="enable our custom file implementation"))
     options.append(make_option(
+        '--nofakedmodules', action="store_true",dest="nofakedmodules",
+        help="don't fake any module"))
+    options.append(make_option(
         '-w', action="store_true", dest="showwarning",
         help="enable warnings (disabled by default)"))
     options.append(make_option(



More information about the Pypy-commit mailing list