summaryrefslogtreecommitdiffstats
path: root/rtemsspec
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2020-08-07 06:57:26 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2020-08-07 07:09:08 +0200
commitc4e460d8ba1fb0539371963fcfa6c2113538c5dd (patch)
tree6e305dd5c9f34c47e0fe82fb7ce9863d3220f0e6 /rtemsspec
parentspec: Fix formatting (diff)
downloadrtems-central-c4e460d8ba1fb0539371963fcfa6c2113538c5dd.tar.bz2
content: Add Content.comment_block()
Diffstat (limited to 'rtemsspec')
-rw-r--r--rtemsspec/content.py24
-rw-r--r--rtemsspec/sphinxcontent.py4
-rw-r--r--rtemsspec/tests/test_content.py10
-rw-r--r--rtemsspec/tests/test_content_sphinx.py10
4 files changed, 41 insertions, 7 deletions
diff --git a/rtemsspec/content.py b/rtemsspec/content.py
index 1015424c..7b99928b 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 6247f987..85c7858c 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 27118e1a..de30276f 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 6581b173..70ed6226 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",