[pypy-svn] r30627 - in pypy/dist/pypy/config: . test

guido at codespeak.net guido at codespeak.net
Thu Jul 27 12:55:26 CEST 2006


Author: guido
Date: Thu Jul 27 12:55:25 2006
New Revision: 30627

Modified:
   pypy/dist/pypy/config/config.py
   pypy/dist/pypy/config/pypyoption.py
   pypy/dist/pypy/config/test/test_config.py
Log:
Added function 'get_paths(config)' to config.py that walks through a config
object and returns a list of all possible paths, using it in the __main__ bit
of pypyoption.py to build the optionparser from (meaning all possible options 
are now exposed when you run pypyoption.py on the command line).


Modified: pypy/dist/pypy/config/config.py
==============================================================================
--- pypy/dist/pypy/config/config.py	(original)
+++ pypy/dist/pypy/config/config.py	Thu Jul 27 12:55:25 2006
@@ -263,3 +263,23 @@
                 chunks = option.cmdline.split(' ')
             option.add_optparse_option(chunks, parser, subconf)
     return parser
+
+def get_paths(config, currpath=None):
+    """returns a list of all paths in a config
+    
+        walks through the config recursively
+    """
+    if currpath is None:
+        currpath = []
+    paths = []
+    for attr, value in config.__dict__.iteritems():
+        if attr.startswith('_'):
+            continue
+        if isinstance(value, Config):
+            currpath.append(attr)
+            paths += get_paths(value, currpath)
+            currpath.pop()
+        else:
+            paths.append('.'.join(currpath + [attr]))
+    return paths
+

Modified: pypy/dist/pypy/config/pypyoption.py
==============================================================================
--- pypy/dist/pypy/config/pypyoption.py	(original)
+++ pypy/dist/pypy/config/pypyoption.py	Thu Jul 27 12:55:25 2006
@@ -1,6 +1,6 @@
 import py
 from pypy.config.config import OptionDescription, BoolOption, IntOption
-from pypy.config.config import ChoiceOption, to_optparse, Config
+from pypy.config.config import ChoiceOption, to_optparse, Config, get_paths
 
 modulepath = py.magic.autopath().dirpath().dirpath().join("module")
 all_modules = [p.basename for p in modulepath.listdir()
@@ -79,11 +79,7 @@
 
 if __name__ == '__main__':
     config = Config(pypy_optiondescription)
-    parser = to_optparse(config, ["objspace.name",
-                                  "objspace.std.*",
-                                  "objspace.std.withsmallint",
-                                  "objspace.std.withprebuiltint",
-                                  "objspace.usemodules",
-                                  "objspace.std.prebuiltintfrom",])
+    paths = get_paths(config)
+    parser = to_optparse(config, paths)
     option, args = parser.parse_args()
     print config

Modified: pypy/dist/pypy/config/test/test_config.py
==============================================================================
--- pypy/dist/pypy/config/test/test_config.py	(original)
+++ pypy/dist/pypy/config/test/test_config.py	Thu Jul 27 12:55:25 2006
@@ -203,3 +203,11 @@
     (options, args) = parser.parse_args(args=['--gc-name=framework'])
 
     assert config.gc.name == 'framework'
+
+def test_get_paths():
+    descr = make_description()
+    config = Config(descr)
+    
+    assert get_paths(config), ['gc.name', 'gc.dummy', 'gc.float', 'bool', 
+                                'objspace', 'wantref', 'int']
+    assert get_paths(config.gc), ['name', 'dummy', 'float']



More information about the Pypy-commit mailing list