[rtems-central commit] content: Add Content.comment_block()

Sebastian Huber sebh at rtems.org
Fri Aug 7 05:09:21 UTC 2020


Module:    rtems-central
Branch:    master
Commit:    c4e460d8ba1fb0539371963fcfa6c2113538c5dd
Changeset: http://git.rtems.org/rtems-central/commit/?id=c4e460d8ba1fb0539371963fcfa6c2113538c5dd

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Aug  7 06:57:26 2020 +0200

content: Add Content.comment_block()

---

 rtemsspec/content.py                   | 24 +++++++++++++++++-------
 rtemsspec/sphinxcontent.py             |  4 ++++
 rtemsspec/tests/test_content.py        | 10 ++++++++++
 rtemsspec/tests/test_content_sphinx.py | 10 ++++++++++
 4 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/rtemsspec/content.py b/rtemsspec/content.py
index 1015424..7b99928 100644
--- a/rtemsspec/content.py
+++ b/rtemsspec/content.py
@@ -163,6 +163,7 @@ class Content:
     """ This class builds content. """
 
     # pylint: disable=too-many-instance-attributes
+    # pylint: disable=too-many-public-methods
     def __init__(self, the_license: str, pop_indent_gap: bool):
         self._lines = []  # type: List[str]
         self._license = the_license
@@ -392,6 +393,22 @@ class Content:
         for statement in item["copyrights"]:
             self.register_copyright(statement)
 
+    def open_comment_block(self) -> None:
+        """ Opens a comment block. """
+        self.push_indent("# ", "#")
+
+    def close_comment_block(self) -> None:
+        """ Closes a comment block. """
+        self.pop_indent()
+        self.gap = True
+
+    @contextmanager
+    def comment_block(self) -> Iterator[None]:
+        """ Opens a comment block context. """
+        self.open_comment_block()
+        yield
+        self.close_comment_block()
+
     def write(self, path: str) -> None:
         """ Writes the content to the file specified by the path. """
         directory = os.path.dirname(path)
@@ -635,13 +652,6 @@ class CContent(Content):
         self.gap = True
 
     @contextmanager
-    def comment_block(self) -> Iterator[None]:
-        """ Opens a comment block context. """
-        self.open_comment_block()
-        yield
-        self.close_comment_block()
-
-    @contextmanager
     def doxygen_block(self) -> Iterator[None]:
         """ Opens a Doxygen comment block context. """
         self.open_doxygen_block()
diff --git a/rtemsspec/sphinxcontent.py b/rtemsspec/sphinxcontent.py
index 6247f98..85c7858 100644
--- a/rtemsspec/sphinxcontent.py
+++ b/rtemsspec/sphinxcontent.py
@@ -208,6 +208,10 @@ class SphinxContent(Content):
             self.prepend([f".. {stm}" for stm in statements])
         self.prepend([f".. SPDX-License-Identifier: {self._license}", ""])
 
+    def open_comment_block(self) -> None:
+        """ Opens a comment block. """
+        self.push_indent(".. ", "..")
+
 
 def _get_ref_term(ctx: ItemGetValueContext) -> Any:
     return f":term:`{ctx.value[ctx.key]}`"
diff --git a/rtemsspec/tests/test_content.py b/rtemsspec/tests/test_content.py
index 27118e1..de30276 100644
--- a/rtemsspec/tests/test_content.py
+++ b/rtemsspec/tests/test_content.py
@@ -188,6 +188,16 @@ def test_indent():
 """
 
 
+def test_comment():
+    content = Content("BSD-2-Clause", True)
+    with content.comment_block():
+        content.add(["abc", "", "def"])
+    assert str(content) == """# abc
+#
+# def
+"""
+
+
 def test_write(tmpdir):
     content = Content("BSD-2-Clause", True)
     content.append("x")
diff --git a/rtemsspec/tests/test_content_sphinx.py b/rtemsspec/tests/test_content_sphinx.py
index 6581b17..70ed622 100644
--- a/rtemsspec/tests/test_content_sphinx.py
+++ b/rtemsspec/tests/test_content_sphinx.py
@@ -260,6 +260,16 @@ def test_license_and_copyrights():
 """
 
 
+def test_comment():
+    content = SphinxContent()
+    with content.comment_block():
+        content.add(["abc", "", "def"])
+    assert str(content) == """.. abc
+..
+.. def
+"""
+
+
 def test_substitute(tmpdir):
     config = create_item_cache_config_and_copy_spec(tmpdir,
                                                     "spec-sphinx",



More information about the vc mailing list