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

cfbolz at codespeak.net cfbolz at codespeak.net
Fri Jan 12 18:32:40 CET 2007


Author: cfbolz
Date: Fri Jan 12 18:32:30 2007
New Revision: 36601

Modified:
   pypy/dist/pypy/config/config.py
   pypy/dist/pypy/config/test/test_config.py
Log:
add a "suggests" to options: if a ChoiceOption suggests another option, it will
be set, but can be overridden.


Modified: pypy/dist/pypy/config/config.py
==============================================================================
--- pypy/dist/pypy/config/config.py	(original)
+++ pypy/dist/pypy/config/config.py	Fri Jan 12 18:32:30 2007
@@ -79,10 +79,10 @@
         child = getattr(self._cfgimpl_descr, name)
         oldowner = self._cfgimpl_value_owners[child._name]
         oldvalue = getattr(self, name)
-        if oldvalue != value and oldowner != "default":
+        if oldvalue != value and oldowner not in ("default", "suggested"):
             if who == "default":
                 return
-            raise ValueError('can not override value %s for option %s' %
+            raise ValueError('cannot override value %s for option %s' %
                                 (value, name))
         child.setoption(self, value, who)
         self._cfgimpl_value_owners[name] = who
@@ -288,9 +288,11 @@
 
 class BoolOption(Option):
     def __init__(self, name, doc, default=None, requires=None,
+                 suggests=None,
                  cmdline=DEFAULT_OPTION_NAME, negation=True):
         super(BoolOption, self).__init__(name, doc, cmdline=cmdline)
         self._requires = requires
+        self._suggests = suggests
         self.default = default
         self.negation = negation
 
@@ -304,6 +306,11 @@
                 toplevel = config._cfgimpl_get_toplevel()
                 homeconfig, name = toplevel._cfgimpl_get_home_by_path(path)
                 homeconfig.setoption(name, reqvalue, who)
+        if value and self._suggests is not None:
+            for path, reqvalue in self._suggests:
+                toplevel = config._cfgimpl_get_toplevel()
+                homeconfig, name = toplevel._cfgimpl_get_home_by_path(path)
+                homeconfig.setoption(name, reqvalue, "suggested")
         super(BoolOption, self).setoption(config, value, who)
 
     def add_optparse_option(self, argnames, parser, 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	Fri Jan 12 18:32:30 2007
@@ -444,3 +444,18 @@
     assert c2.s1.a
     c2.int = 44 # does not crash
 
+def test_suggests():
+    descr = OptionDescription("test", '', [
+        BoolOption("toplevel", "", default=False),
+        BoolOption("opt", "", default=False,
+                   suggests=[("toplevel", True)])
+    ])
+    c = Config(descr)
+    assert not c.toplevel
+    assert not c.opt
+    c.opt = True
+    assert c.opt
+    assert c.toplevel
+    # does not crash
+    c.toplevel = False
+    assert not c.toplevel



More information about the Pypy-commit mailing list