Skip to content

Commit 0475c9e

Browse files
authored
fix(sphinxdocs): do not crash when tag_class does not have doc (#2585)
It seems that there was a typo in the code and instead of calling `self._write` we were calling `self.write`. It went unnoticed because of lack of coverage. This adds test code exercising the edge case and fixes the typo. Fixes #2579
1 parent 80aab4a commit 0475c9e

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ Unreleased changes template.
6767
as UTF-8 on all platforms.
6868
* (coverage) Coverage with `--bootstrap_impl=script` is fixed
6969
([#2572](https://github.com/bazelbuild/rules_python/issues/2572)).
70+
* (sphinxdocs) Do not crash when `tag_class` does not have a populated `doc` value.
71+
Fixes ([#2579](https://github.com/bazelbuild/rules_python/issues/2579)).
7072

7173
{#v0-0-0-added}
7274
### Added

Diff for: sphinxdocs/private/proto_to_markdown.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def _render_module_extension(self, mod_ext: stardoc_output_pb2.ModuleExtensionIn
197197
# Ensure a newline between the directive and the doc fields,
198198
# otherwise they get parsed as directive options instead.
199199
if not doc_string and tag.attribute:
200-
self.write("\n")
200+
self._write("\n")
201201
self._render_attributes(tag.attribute)
202202
self._write(":::::\n")
203203
self._write("::::::\n")

Diff for: sphinxdocs/tests/proto_to_markdown/proto_to_markdown_test.py

+11
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@
8282
default_value: "[BZLMOD_EXT_TAG_A_ATTRIBUTE_1_DEFAULT_VALUE]"
8383
}
8484
}
85+
tag_class: {
86+
tag_name: "bzlmod_ext_tag_no_doc"
87+
attribute: {
88+
name: "bzlmod_ext_tag_a_attribute_2",
89+
type: STRING_LIST
90+
default_value: "[BZLMOD_EXT_TAG_A_ATTRIBUTE_2_DEFAULT_VALUE]"
91+
}
92+
}
8593
}
8694
repository_rule_info: {
8795
rule_name: "repository_rule",
@@ -151,6 +159,9 @@ def test_basic_rendering_everything(self):
151159
self.assertRegex(actual, "bzlmod_ext_tag_a_attribute_1")
152160
self.assertRegex(actual, "BZLMOD_EXT_TAG_A_ATTRIBUTE_1_DOC_STRING")
153161
self.assertRegex(actual, "BZLMOD_EXT_TAG_A_ATTRIBUTE_1_DEFAULT_VALUE")
162+
self.assertRegex(actual, "{bzl:tag-class} bzlmod_ext_tag_no_doc")
163+
self.assertRegex(actual, "bzlmod_ext_tag_a_attribute_2")
164+
self.assertRegex(actual, "BZLMOD_EXT_TAG_A_ATTRIBUTE_2_DEFAULT_VALUE")
154165

155166
self.assertRegex(actual, "{bzl:repo-rule} repository_rule")
156167
self.assertRegex(actual, "REPOSITORY_RULE_DOC_STRING")

0 commit comments

Comments
 (0)