[pypy-svn] r33878 - in pypy/dist/pypy: config config/test translator/goal
cfbolz at codespeak.net
cfbolz at codespeak.net
Mon Oct 30 13:58:20 CET 2006
Author: cfbolz
Date: Mon Oct 30 13:58:19 2006
New Revision: 33878
Modified:
pypy/dist/pypy/config/config.py
pypy/dist/pypy/config/test/test_config.py
pypy/dist/pypy/translator/goal/targetpypystandalone.py
Log:
make_dict helper function
Modified: pypy/dist/pypy/config/config.py
==============================================================================
--- pypy/dist/pypy/config/config.py (original)
+++ pypy/dist/pypy/config/config.py Mon Oct 30 13:58:19 2006
@@ -43,6 +43,10 @@
if '.' in name:
homeconfig, name = self._cfgimpl_get_home_by_path(name)
return getattr(homeconfig, name)
+ if name.startswith('_cfgimpl_'):
+ # if it were in __dict__ it would have been found already
+ raise AttributeError("%s object has no attribute %s" %
+ (self.__class__, name))
if name not in self._cfgimpl_values:
raise AttributeError("%s object has no attribute %s" %
(self.__class__, name))
@@ -488,3 +492,8 @@
option.add_optparse_option(chunks, grp, homeconf)
return parser
+def make_dict(config):
+ paths = config.getpaths()
+ options = dict([(path, getattr(config, path)) for path in paths])
+ return options
+
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 Mon Oct 30 13:58:19 2006
@@ -400,3 +400,16 @@
assert "choose! [CHOICE=a|b|c, default: a]" in help
assert "choose2! [CHOICE2=x|y|z]" in help
assert "specify xyz [default: hello]" in help
+
+def test_make_dict():
+ descr = OptionDescription("opt", "", [
+ OptionDescription("s1", "", [
+ BoolOption("a", "", default=False)]),
+ IntOption("int", "", default=42)])
+ config = Config(descr)
+ d = make_dict(config)
+ assert d == {"s1.a": False, "int": 42}
+ config.int = 43
+ config.s1.a = True
+ d = make_dict(config)
+ assert d == {"s1.a": True, "int": 43}
Modified: pypy/dist/pypy/translator/goal/targetpypystandalone.py
==============================================================================
--- pypy/dist/pypy/translator/goal/targetpypystandalone.py (original)
+++ pypy/dist/pypy/translator/goal/targetpypystandalone.py Mon Oct 30 13:58:19 2006
@@ -14,7 +14,7 @@
from pypy.interpreter.error import OperationError
from pypy.translator.goal.ann_override import PyPyAnnotatorPolicy
from pypy.config.pypyoption import pypy_optiondescription
-from pypy.config.config import Config, to_optparse
+from pypy.config.config import Config, to_optparse, make_dict
from pypy.tool.option import make_objspace
@@ -105,8 +105,7 @@
# obscure hack to stuff the translation options into the translated PyPy
import pypy.module.sys
- paths = config.getpaths()
- options = dict([(path, getattr(config, path)) for path in paths])
+ options = make_dict(config)
wrapstr = 'space.wrap(%r)' % (options)
pypy.module.sys.Module.interpleveldefs['pypy_translation_info'] = wrapstr
More information about the Pypy-commit
mailing list