Commits

Jan Borsodi committed e9bae3a Merge

Merged in changes from default.

Comments (0)

Files changed (13)

 js-out/
 mako-py/
 glob:*.bat
+.tox
+tox.ini
 b442c320d4ab69340199b77887d57d73ea8c4fb5 0.2
 cfac3c5a1fbacb5f4fef68fa513a4aae2929e6cc 0.2.1
 ccb42024943b2a679ca969becfda1bd0866c86e3 0.3
+687e298c15eb56f4dccebf6bce893df2d212b9a7 0.3.1
+0c1f48ab832ae93802a6ed66996a55b4e9f0a139 0.3.2
+095039008b45b625d3a02e3e3b365e723ac5af69 0.3.3
+0.3.3 - 2011-01-25
+------------------
+
+hob
+~~~
+
+* Fixed issue 2: Incorrect parsing of documentation blocks
+  Now it only removes the initial whitespace + asterisk from doc blocks and
+  keeps the rest as it is.
+
+0.3.2 - 2011-01-25
+------------------
+
+* Fixed manifest to include templates in the new location, 0.3 and 0.3.1 was
+  released without any template files because of this.
+
+hob
+~~~
+
+* Fixed reading of command options and arguments from config file to only
+  occur on the current command in use. Earlier it would read from all
+  commands which would overwrite values for options/arguments with same
+  name but from a different command.
+
 0.3.1 - 2010-12-01
 ------------------
 
 include LICENSE
 include favicon.ico
 recursive-include hob *.py
-recursive-include templates *.mako *.js *.css *.proto
+recursive-include hob/templates *.mako *.js *.css *.proto
 """A multi-language code generator for the Opera Scope Protocol. Code is generated from Google Protocol Buffer definitions.
 """
 
-__version_num__ = (0, 3)
+__version_num__ = (0, 3, 3)
 __version__ = ".".join(map(str, __version_num__))
 __author__ = "Jan Borsodi, Christian Krebs"
 __author_email__ = "jborsodi@opera.com, chrisk@opera.com"
         """
         if self._command:
             self._command.loadconfig(config, opts, group="global")
-        for command in self:
-            command.loadconfig(config, opts)
+        if getattr(opts, "command", None):
+            for command in self:
+                if command.name == opts.command:
+                    command.loadconfig(config, opts)
+                    break
 
     def options(self, opts=None, **kwargs):
         """Decorator which registers global options.
         generateXML(package, node)
         if out_dir:
             text = getattr(doc, xmlfunc)()
-            fname = os.path.join(out_dir, service.name + ".xml")
+            service_name = package.name
+            if package.services:
+                service_name = package.services[0].name
+            fname = os.path.join(out_dir, service_name + ".xml")
             outfile = open(fname, "w").write(text)
-            print "Wrote service %s to '%s'" % (service.name, fname)
+            print "Wrote service %s to '%s'" % (service_name, fname)
     if not out_dir:
         text = getattr(doc, xmlfunc)()
         f.write(text)

hob/templates/proto/package.mako

 %   if package.name:
 package ${package.name};
 
-%   endif
+%   endif \
 %   if package.options:
 ${g.blockOptions(package, package.options)}
 %   endif
 % endif \
-
 % for item in package.items:
 %   if not export or type(item).__name__.lower() in export:
 ${g.item(item)}
     if re.match("///", cmt):
         cmt = cmt[3:]
     elif cmt.startswith("/**") and cmt.endswith("*/"):
-        m = re.match(r"/\*\*(?:\w*[\n])?(.+)(?:\w+)?\*/", cmt, re.DOTALL | re.MULTILINE)
+        m = re.match(r"/\*\*(?:\w*[\n])?(.+)/$", cmt, re.DOTALL | re.MULTILINE)
         cmt = m.group(1)
-        cmt = "".join([re.sub("[ \t]*[*]", "", line) for line in cmt.splitlines(True)])
+        cmt = "".join([re.sub("^[ \t]*[*]", "", line, flags=re.MULTILINE) for line in cmt.splitlines(True)])
     return textwrap.dedent(cmt)
 
 words_re = re.compile("([A-Z][A-Z0-9]*(?=[A-Z][a-z0-9]))|([A-Z][A-Z0-9]*$)|([A-Z][a-z0-9]*)|([a-z][a-z0-9]*)")

tests/test_command_proto.py

 import difflib
+import re
+from os.path import dirname, join
 from hob.proto import PackageManager
 from hob.template import TextGenerator
 
             print line,
     assert out == expected
 
+def fixpath(fname):
+    return join(dirname(__file__), fname)
+
 def processProto(fname, syntax="scope", export=["package", "service", "message", "enum"]):
     manager = PackageManager()
     package = manager.loadFile(fname)
     gen = TextGenerator(syntax=syntax)
     text = gen.package(package, export=export)
+    text = re.sub(r"\r\n", "\n", text)
     return text
 
 def test_basic_messages():
-    text = processProto("tests/proto/basic.proto")
-    expected = open("tests/syntax_scope/basic.proto").read()
+    text = processProto(fixpath("proto/basic.proto"))
+    expected = open(fixpath("syntax_scope/basic.proto")).read()
     compareOutput(text, expected)
 
 def test_composed_messages():
-    text = processProto("tests/proto/composed.proto")
-    expected = open("tests/syntax_scope/composed.proto").read()
+    text = processProto(fixpath("proto/composed.proto"))
+    expected = open(fixpath("syntax_scope/composed.proto")).read()
     compareOutput(text, expected)
 
 def test_enums():
-    text = processProto("tests/proto/enums.proto")
-    expected = open("tests/syntax_scope/enums.proto").read()
+    text = processProto(fixpath("proto/enums.proto"))
+    expected = open(fixpath("syntax_scope/enums.proto")).read()
     compareOutput(text, expected)
 
 def test_options():
-    text = processProto("tests/proto/options.proto")
-    expected = open("tests/syntax_scope/options.proto").read()
+    text = processProto(fixpath("proto/options.proto"))
+    expected = open(fixpath("syntax_scope/options.proto")).read()
     compareOutput(text, expected)

tests/test_parser.py

 import os
+from os.path import dirname, join
 from hob.parser import Lexer, create_lexer_rules, PackageBuilder, Loader, ParseError, BuildError
 from hob.proto import Package, Request, Event, Message, Proto
 
+def fixpath(fname):
+    return join(dirname(__file__), fname)
+
 class FakeLoadError(Exception):
     pass
 
 
 def load(filename):
     l = Lexer(create_lexer_rules())
-    loader = PathLoader(l, "tests/proto")
+    loader = PathLoader(l, fixpath("proto"))
     pkg = Package(filename)
     builder = PackageBuilder(pkg, loader)
     loader.load(filename, builder)

tests/test_utils.py

+import difflib
+from hob.utils import parse_docblock
+
+def compareOutput(out, expected):
+    if out != expected:
+        for line in difflib.unified_diff(expected.splitlines(True), out.splitlines(True), "a", "b"):
+            print line,
+    assert out == expected
+
+def test_parse_docblock():
+    doc = """/**
+ * **DocTc** is a fake service designed to test the doucmentation generator.
+ *
+ * Inline markup (this is a subtitle)
+ * ----------------------------------
+ * This sentence uses *italic* text. This sentence uses **bold**.
+ *
+ * We also have ``monospace text``. Does monospace also work next to an edge?
+ * ``Maybe``.
+ *
+ * This interpreted text: `DocTc` should probably link to the service. So should
+ * `DocTc::PerformSomeAction`. That's probably some amount of work, though.
+ *
+ * Lists
+ * -----
+ *
+ * - First way
+ * - Of doing lists
+ *
+ * * Second way
+ * * Meh, don't use this way. But it should work.
+ *
+ * Enumerated list:
+ *
+ * #. One
+ * #. Two
+ *
+ * Escaping
+ * --------
+ *
+ * \*not bold*, \``not monospace``, a backslash should be visible: \\
+ *
+ * Line blocks
+ * -----------
+ *
+ * | These
+ * | words
+ * | should
+ * | be
+ * | on
+ * | different
+ * | lines
+ */"""
+
+    expected = """**DocTc** is a fake service designed to test the doucmentation generator.
+
+Inline markup (this is a subtitle)
+----------------------------------
+This sentence uses *italic* text. This sentence uses **bold**.
+
+We also have ``monospace text``. Does monospace also work next to an edge?
+``Maybe``.
+
+This interpreted text: `DocTc` should probably link to the service. So should
+`DocTc::PerformSomeAction`. That's probably some amount of work, though.
+
+Lists
+-----
+
+- First way
+- Of doing lists
+
+* Second way
+* Meh, don't use this way. But it should work.
+
+Enumerated list:
+
+#. One
+#. Two
+
+Escaping
+--------
+
+\*not bold*, \``not monospace``, a backslash should be visible: \\
+
+Line blocks
+-----------
+
+| These
+| words
+| should
+| be
+| on
+| different
+| lines
+"""
+    result = parse_docblock(doc)
+    compareOutput(result, expected)
+
+def test_parse_docblock2():
+    doc = """/**
+     *   RST
+     *   ---
+     *
+     *   Is whitespace
+     *   preserved (in rst)?
+     *
+     *   Everything except the first space after the asterisk should be preserved. IMO.
+     *
+     *              MIxed
+     *             WhItespace
+     *   This is horrIble
+     *               I am aligned (in rst)
+     */"""
+
+    expected = """RST
+---
+
+Is whitespace
+preserved (in rst)?
+
+Everything except the first space after the asterisk should be preserved. IMO.
+
+           MIxed
+          WhItespace
+This is horrIble
+            I am aligned (in rst)
+"""
+
+    result = parse_docblock(doc)
+    compareOutput(result, expected)
+[tox]
+envlist = py27
+
+[testenv]
+commands = 
+    rm -rf {envdir}/scope-services
+    hg clone https://bitbucket.org/scope/scope-services {envdir}/scope-services
+    rm -rf {envdir}/js-out
+    {envbindir}/hob --project {envdir}/scope-services js --test-framework --out-dir {envdir}/js-out
+    rm -rf {envdir}/rst-doc
+    {envbindir}/hob --project {envdir}/scope-services rst-doc --out-dir {envdir}/rst-doc
+    rm -rf {envdir}/proto
+    {envbindir}/hob --project {envdir}/scope-services rst-doc --out-dir {envdir}/proto
+    {envbindir}/hob --project {envdir}/scope-services proto --out-file {envdir}/proto-files1.txt
+    {envbindir}/hob --project {envdir}/scope-services proto
+    rm -rf {envdir}/xml
+    {envbindir}/hob --project {envdir}/scope-services xml --out-dir {envdir}/xml
+    {envbindir}/hob --project {envdir}/scope-services xml --out-file {envdir}/xml-out1.xml
+    {envbindir}/hob --project {envdir}/scope-services xml