[pypy-svn] r37166 - in pypy/dist/pypy/config: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Tue Jan 23 10:18:07 CET 2007
Author: cfbolz
Date: Tue Jan 23 10:18:07 2007
New Revision: 37166
Added:
pypy/dist/pypy/config/makerestdoc.py
pypy/dist/pypy/config/test/test_makerestdoc.py
Modified:
pypy/dist/pypy/config/config.py
Log:
train experiments: try to produce some human-readable information out of the
option descriptions
Modified: pypy/dist/pypy/config/config.py
==============================================================================
--- pypy/dist/pypy/config/config.py (original)
+++ pypy/dist/pypy/config/config.py Tue Jan 23 10:18:07 2007
@@ -1,5 +1,6 @@
-
+import py
from py.compat import optparse
+from pypy.tool.pairtype import extendabletype
SUPPRESS_USAGE = optparse.SUPPRESS_USAGE
@@ -179,6 +180,8 @@
class Option(object):
+ __metaclass__ = extendabletype
+
def __init__(self, name, doc, cmdline=DEFAULT_OPTION_NAME):
self._name = name
self.doc = doc
@@ -211,6 +214,9 @@
callback=callback, metavar=self._name.upper(),
*argnames)
+ def make_rest_docs(self):
+ pass
+
class ConfigUpdate(object):
def __init__(self, config, option):
@@ -279,6 +285,7 @@
def convert_from_cmdline(self, value):
return value.strip()
+
def _getnegation(optname):
if optname.startswith("without"):
return "with" + optname[len("without"):]
@@ -408,7 +415,10 @@
return self.default
class OptionDescription(object):
+ __metaclass__ = extendabletype
+
cmdline = None
+
def __init__(self, name, doc, children):
self._name = name
self.doc = doc
Added: pypy/dist/pypy/config/makerestdoc.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/config/makerestdoc.py Tue Jan 23 10:18:07 2007
@@ -0,0 +1,84 @@
+import py
+from py.__.rest.rst import Rest, Paragraph, Strong, ListItem, Title, Link
+from py.__.rest.rst import Directive
+
+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
+
+class __extend__(Option):
+ def make_rest_doc(self, path=""):
+ if path:
+ fullpath = "%s.%s" % (path, self._name)
+ else:
+ fullpath = self._name
+ result = Rest(
+ Title(fullpath, abovechar="=", belowchar="="),
+ Directive("contents"),
+ Title("Basic Option Information"),
+ ListItem(Strong("name:"), self._name),
+ ListItem(Strong("description:"), self.doc))
+ if self.cmdline is not None:
+ if self.cmdline is DEFAULT_OPTION_NAME:
+ cmdline = '--%s' % (fullpath.replace('.', '-'),)
+ else:
+ cmdline = self.cmdline
+ result.add(ListItem(Strong("command-line:"), cmdline))
+ return result
+
+class __extend__(ChoiceOption):
+ def make_rest_doc(self, path=""):
+ content = super(ChoiceOption, self).make_rest_doc(path)
+ content.add(ListItem(Strong("option type:"), "choice option"))
+ content.add(ListItem(Strong("possible values:"),
+ *[ListItem(str(val)) for val in self.values]))
+ if self.default is not None:
+ content.add(ListItem(Strong("default:"), str(self.default)))
+
+ requirements = []
+
+ for val in self.values:
+ if val not in self._requires:
+ continue
+ req = self._requires[val]
+ requirements.append(ListItem("value '%s' requires:" % (val, ),
+ *[ListItem(Link(opt, opt + ".html"),
+ "to be set to '%s'" % (rval, ))
+ for (opt, rval) in req]))
+ if requirements:
+ content.add(ListItem(Strong("requirements:"), *requirements))
+ return content
+
+class __extend__(OptionDescription):
+ def make_rest_doc(self, path=""):
+ if path:
+ fullpath = "%s.%s" % (path, self._name)
+ else:
+ fullpath = self._name
+ content = Rest(
+ Title(fullpath, abovechar="=", belowchar="="),
+ Directive("contents"))
+ if path:
+ content.add(
+ Paragraph(Link("back to parent", path + ".html")))
+ for elt in [
+ Title("Basic Option Information"),
+ ListItem(Strong("name:"), self._name),
+ ListItem(Strong("description:"), self.doc),
+ Title("Children")
+ ]:
+ content.add(elt)
+ conf = Config(self)
+ stack = []
+ prefix = fullpath
+ curr = content
+ for subpath in conf.getpaths(include_groups=True):
+ subpath = fullpath + "." + subpath
+ while not subpath.startswith(prefix):
+ curr, prefix = stack.pop()
+ new = curr.add(ListItem(Link(subpath, subpath + ".html")))
+ stack.append((curr, prefix))
+ prefix = subpath
+ curr = new
+ return content
+
Added: pypy/dist/pypy/config/test/test_makerestdoc.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/config/test/test_makerestdoc.py Tue Jan 23 10:18:07 2007
@@ -0,0 +1,28 @@
+from pypy.config.config import *
+import pypy.config.makerestdoc
+
+from py.__.doc.conftest import restcheck
+
+tempdir = py.test.ensuretemp('config')
+
+def checkrest(rest, filename):
+ tempfile = tempdir.join(filename)
+ tempfile.write(rest)
+ 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"])])])
+ config = Config(descr)
+ txt = descr.make_rest_doc().text()
+ checkrest(txt, descr._name + ".txt")
+ for path in config.getpaths(include_groups=True):
+ subconf, step = config._cfgimpl_get_home_by_path(path)
+ fullpath = (descr._name + "." + path)
+ prefix = fullpath.rsplit(".", 1)[0]
+ txt = getattr(subconf._cfgimpl_descr, step).make_rest_doc(
+ prefix).text()
+ checkrest(txt, fullpath + ".txt")
More information about the Pypy-commit
mailing list