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

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Jan 23 17:05:14 CET 2007


Author: cfbolz
Date: Tue Jan 23 17:05:14 2007
New Revision: 37211

Modified:
   pypy/dist/pypy/config/makerestdoc.py
   pypy/dist/pypy/config/test/test_makerestdoc.py
Log:
generate info for the other option types as well


Modified: pypy/dist/pypy/config/makerestdoc.py
==============================================================================
--- pypy/dist/pypy/config/makerestdoc.py	(original)
+++ pypy/dist/pypy/config/makerestdoc.py	Tue Jan 23 17:05:14 2007
@@ -4,7 +4,8 @@
 
 from pypy.config.config import ChoiceOption, BoolOption, StrOption, IntOption
 from pypy.config.config import FloatOption, OptionDescription, Option, Config
-from pypy.config.config import DEFAULT_OPTION_NAME
+from pypy.config.config import ArbitraryOption, DEFAULT_OPTION_NAME
+from pypy.config.config import _getnegation
 
 class __extend__(Option):
     def make_rest_doc(self, path=""):
@@ -15,6 +16,7 @@
         result = Rest(
             Title(fullpath, abovechar="=", belowchar="="),
             Directive("contents"),
+            Paragraph(Link("back to parent", path + ".html")),
             Title("Basic Option Information"),
             ListItem(Strong("name:"), self._name),
             ListItem(Strong("description:"), self.doc))
@@ -49,6 +51,76 @@
             content.add(ListItem(Strong("requirements:"), *requirements))
         return content
 
+class __extend__(BoolOption):
+    def make_rest_doc(self, path=""):
+        content = super(BoolOption, self).make_rest_doc(path)
+        if path:
+            fullpath = "%s.%s" % (path, self._name)
+        else:
+            fullpath = self._name
+        if self.negation and self.cmdline is not None:
+            if self.cmdline is DEFAULT_OPTION_NAME:
+                cmdline = '--%s' % (fullpath.replace('.', '-'),)
+            else:
+                cmdline = self.cmdline
+            neg_cmdline = ["--" + _getnegation(argname.lstrip("-"))
+                               for argname in cmdline.split()
+                                   if argname.startswith("--")][0]
+            content.add(ListItem(Strong("command-line for negation:"),
+                                 neg_cmdline))
+        content.add(ListItem(Strong("option type:"), "boolean option"))
+        if self.default is not None:
+            content.add(ListItem(Strong("default:"), str(self.default)))
+        if self._requires is not None:
+            requirements = [ListItem(Link(opt, opt + ".html"),
+                               "must be set to '%s'" % (rval, ))
+                                for (opt, rval) in self._requires]
+            if requirements:
+                content.add(ListItem(Strong("requirements:"), *requirements))
+        if self._suggests is not None:
+            suggestions = [ListItem(Link(opt, opt + ".html"),
+                              "should be set to '%s'" % (rval, ))
+                               for (opt, rval) in self._suggests]
+            if suggestions:
+                content.add(ListItem(Strong("suggestions:"), *suggestions))
+        return content
+
+class __extend__(IntOption):
+    def make_rest_doc(self, path=""):
+        content = super(IntOption, self).make_rest_doc(path)
+        content.add(ListItem(Strong("option type:"), "integer option"))
+        if self.default is not None:
+            content.add(ListItem(Strong("default:"), str(self.default)))
+        return content
+
+class __extend__(FloatOption):
+    def make_rest_doc(self, path=""):
+        content = super(FloatOption, self).make_rest_doc(path)
+        content.add(ListItem(Strong("option type:"), "float option"))
+        if self.default is not None:
+            content.add(ListItem(Strong("default:"), str(self.default)))
+        return content
+
+class __extend__(StrOption):
+    def make_rest_doc(self, path=""):
+        content = super(StrOption, self).make_rest_doc(path)
+        content.add(ListItem(Strong("option type:"), "string option"))
+        if self.default is not None:
+            content.add(ListItem(Strong("default:"), str(self.default)))
+        return content
+
+class __extend__(ArbitraryOption):
+    def make_rest_doc(self, path=""):
+        content = super(ArbitraryOption, self).make_rest_doc(path)
+        content.add(ListItem(Strong("option type:"),
+                             "arbitrary option (mostly internal)"))
+        if self.default is not None:
+            content.add(ListItem(Strong("default:"), str(self.default)))
+        elif self.defaultfactory is not None:
+            content.add(ListItem(Strong("factory for the default value:"),
+                                 str(self.defaultfactory)))
+        return content
+
 class __extend__(OptionDescription):
     def make_rest_doc(self, path=""):
         if path:

Modified: pypy/dist/pypy/config/test/test_makerestdoc.py
==============================================================================
--- pypy/dist/pypy/config/test/test_makerestdoc.py	(original)
+++ pypy/dist/pypy/config/test/test_makerestdoc.py	Tue Jan 23 17:05:14 2007
@@ -11,11 +11,7 @@
     restcheck(tempfile)
     return tempfile.new(ext='.html').read()
 
-def test_simple():
-    descr = OptionDescription("foo", "doc", [
-            ChoiceOption("bar", "more doc", ["a", "b", "c"]),
-            OptionDescription("sub", "nope", [
-                ChoiceOption("subbar", "", ["d", "f"])])])
+def generate_html(descr):
     config = Config(descr)
     txt = descr.make_rest_doc().text()
     checkrest(txt, descr._name + ".txt")
@@ -26,3 +22,44 @@
         txt = getattr(subconf._cfgimpl_descr, step).make_rest_doc(
                 prefix).text()
         checkrest(txt, fullpath + ".txt")
+
+def test_simple():
+    descr = OptionDescription("foo", "doc", [
+            ChoiceOption("bar", "more doc", ["a", "b", "c"]),
+            OptionDescription("sub", "nope", [
+                ChoiceOption("subbar", "", ["d", "f"]),
+                BoolOption("boolean", "this is a boolean", default=False,
+                           cmdline="-b --with-b")
+                ]),
+            StrOption("str", "string option!", default="strange"),
+            IntOption("int", "integer option", default=42),
+            FloatOption("float", "float option", default=py.std.math.pi),
+            ArbitraryOption("surprise", "special", defaultfactory=int),
+            ])
+    generate_html(descr)
+
+def test_choice_requires():
+    descr = OptionDescription("s0", "doc", [
+            BoolOption("b1", "", default=False),
+            BoolOption("b2", "", default=False),
+            BoolOption("b3", "", default=False),
+            ChoiceOption("bar", "more doc", ["a", "b", "c"],
+                         default="a",
+                         requires={"a": [("s0.b1", True),
+                                         ("s0.b2", False)],
+                                   "b": [("s0.b1", False)]})
+            ])
+    generate_html(descr)
+
+def test_bool_requires_suggests():
+    descr = OptionDescription("a0", "doc", [
+            BoolOption("B1", "", default=False),
+            BoolOption("B2", "", default=False,
+                       suggests=[("a0.B1", True)]),
+            BoolOption("B3", "", default=False,
+                       requires=[("a0.bar", "c"), ("a0.B2", True)]),
+            ChoiceOption("bar", "more doc", ["a", "b", "c"],
+                         default="a")])
+    generate_html(descr)
+
+



More information about the Pypy-commit mailing list