Skip to content

Commit f6546c3

Browse files
vishwajitdandagehoe-jo
authored andcommitted
Added support for png images in requirements
1 parent 679060c commit f6546c3

6 files changed

Lines changed: 33 additions & 23 deletions

File tree

bazel/rules/rules_score/private/requirements.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ _score_requirements_rule = rule(
166166
doc = "TRLC specification target providing the RSL files that define the requirement types. Defaults to the S-CORE requirements model.",
167167
),
168168
"image_srcs": attr.label_list(
169-
allow_files = [".svg"],
169+
allow_files = [".svg", ".png"],
170170
default = [],
171-
doc = "SVG image files to stage next to the rendered RST. The package-relative path of each file (e.g. 'diagrams/arch.svg') must match the path written in a ``.. image::`` directive inside the requirement description field. Only SVG files are permitted.",
171+
doc = "Image files (.svg or .png) to stage next to the rendered RST. The package-relative path of each file (e.g. 'diagrams/arch.png') must match the path written in a ``.. image::`` directive inside the requirement description field.",
172172
),
173173
"_renderer": attr.label(
174174
default = Label("@trlc//tools/trlc_rst:trlc_rst"),

bazel/rules/rules_score/test/BUILD

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,10 @@ requirements_rst_test_suite(name = "requirements_rst_tests")
707707
feature_requirements(
708708
name = "feat_req_with_image",
709709
srcs = ["fixtures/seooc_test/feature_requirements.trlc"],
710-
image_srcs = ["fixtures/image_srcs/diagrams/arch.svg"],
710+
image_srcs = [
711+
"fixtures/image_srcs/diagrams/arch.svg",
712+
"fixtures/image_srcs/diagrams/arch.png",
713+
],
711714
deps = [":asr_trlc"],
712715
)
713716

bazel/rules/rules_score/test/fixtures/image_requirements/image_requirements.trlc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ Requirement REQ_with_image {
2020
'''
2121
}
2222

23+
Requirement REQ_with_png_image {
24+
description = '''
25+
The system shall support PNG image rendering in requirements.
26+
27+
![System overview PNG](diagrams/overview.png)
28+
'''
29+
}
30+
2331
Requirement REQ_no_image {
2432
description = "The system shall operate without images."
2533
}
68 Bytes
Loading

bazel/rules/rules_score/test/requirements_image_test.bzl

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,24 @@ def _image_srcs_sphinx_sources_test_impl(ctx):
4848
str([f.basename for f in rst_files]),
4949
)
5050

51-
image_files = [f for f in sphinx_files if f.extension == "svg"]
51+
image_files = [f for f in sphinx_files if f.extension in ("svg", "png")]
5252
asserts.true(
5353
env,
54-
len(image_files) == 1,
55-
"SphinxSourcesInfo.srcs should contain exactly one staged image file, got: " +
54+
len(image_files) == 2,
55+
"SphinxSourcesInfo.srcs should contain exactly two staged image files, got: " +
5656
str([f.basename for f in image_files]),
5757
)
5858

59-
asserts.equals(
60-
env,
61-
"arch.svg",
62-
image_files[0].basename,
63-
"Staged image should be named arch.svg",
64-
)
59+
basenames = sorted([f.basename for f in image_files])
60+
asserts.equals(env, ["arch.png", "arch.svg"], basenames)
6561

66-
# Verify the image is staged at the package-relative path (diagrams/arch.svg)
67-
# meaning its short_path ends with diagrams/arch.svg relative to the rule output dir.
68-
image_short_path = image_files[0].short_path
62+
# Verify images are staged at package-relative paths under diagrams/.
63+
image_short_paths = sorted([f.short_path for f in image_files])
6964
asserts.true(
7065
env,
71-
image_short_path.endswith("diagrams/arch.svg"),
72-
"Staged image should preserve package-relative path (diagrams/arch.svg), got: " +
73-
image_short_path,
66+
image_short_paths[0].endswith("diagrams/arch.png") and image_short_paths[1].endswith("diagrams/arch.svg"),
67+
"Staged images should preserve package-relative paths under diagrams/, got: " +
68+
str(image_short_paths),
7469
)
7570

7671
return analysistest.end(env)

bazel/rules/rules_score/test/trlc_rst_image_rendering_test.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,26 @@ def _render(self) -> str:
7676
return f.read()
7777

7878
def test_image_directive_emitted(self):
79-
"""``.. image:: diagrams/overview.svg`` appears in the rendered RST."""
80-
self.assertIn(".. image:: diagrams/overview.svg", self._render())
79+
"""Both SVG and PNG image directives appear in the rendered RST."""
80+
rendered = self._render()
81+
self.assertIn(".. image:: diagrams/overview.svg", rendered)
82+
self.assertIn(".. image:: diagrams/overview.png", rendered)
8183

8284
def test_alt_text_emitted(self):
8385
"""The ``:alt:`` option is emitted with the Markdown alt text."""
84-
self.assertIn(":alt: System overview", self._render())
86+
rendered = self._render()
87+
self.assertIn(":alt: System overview", rendered)
88+
self.assertIn(":alt: System overview PNG", rendered)
8589

8690
def test_markdown_syntax_not_in_output(self):
8791
"""The raw ``![...]()`` Markdown syntax must not appear in the output."""
8892
self.assertNotIn("![", self._render())
8993

9094
def test_requirement_without_image_unaffected(self):
91-
"""Requirements without an image render normally; exactly one image total."""
95+
"""Requirements without an image render normally; two images total."""
9296
content = self._render()
9397
self.assertIn("The system shall operate without images.", content)
94-
self.assertEqual(content.count(".. image::"), 1)
98+
self.assertEqual(content.count(".. image::"), 2)
9599

96100

97101
if __name__ == "__main__":

0 commit comments

Comments
 (0)