Skip to content

Commit

Permalink
fix(sphinxdocs): do not crash when tag_class does not have doc (#2585)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
aignas authored Jan 26, 2025
1 parent 80aab4a commit 0475c9e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ Unreleased changes template.
as UTF-8 on all platforms.
* (coverage) Coverage with `--bootstrap_impl=script` is fixed
([#2572](https://github.com/bazelbuild/rules_python/issues/2572)).
* (sphinxdocs) Do not crash when `tag_class` does not have a populated `doc` value.
Fixes ([#2579](https://github.com/bazelbuild/rules_python/issues/2579)).

{#v0-0-0-added}
### Added
Expand Down
2 changes: 1 addition & 1 deletion sphinxdocs/private/proto_to_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def _render_module_extension(self, mod_ext: stardoc_output_pb2.ModuleExtensionIn
# Ensure a newline between the directive and the doc fields,
# otherwise they get parsed as directive options instead.
if not doc_string and tag.attribute:
self.write("\n")
self._write("\n")
self._render_attributes(tag.attribute)
self._write(":::::\n")
self._write("::::::\n")
Expand Down
11 changes: 11 additions & 0 deletions sphinxdocs/tests/proto_to_markdown/proto_to_markdown_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@
default_value: "[BZLMOD_EXT_TAG_A_ATTRIBUTE_1_DEFAULT_VALUE]"
}
}
tag_class: {
tag_name: "bzlmod_ext_tag_no_doc"
attribute: {
name: "bzlmod_ext_tag_a_attribute_2",
type: STRING_LIST
default_value: "[BZLMOD_EXT_TAG_A_ATTRIBUTE_2_DEFAULT_VALUE]"
}
}
}
repository_rule_info: {
rule_name: "repository_rule",
Expand Down Expand Up @@ -151,6 +159,9 @@ def test_basic_rendering_everything(self):
self.assertRegex(actual, "bzlmod_ext_tag_a_attribute_1")
self.assertRegex(actual, "BZLMOD_EXT_TAG_A_ATTRIBUTE_1_DOC_STRING")
self.assertRegex(actual, "BZLMOD_EXT_TAG_A_ATTRIBUTE_1_DEFAULT_VALUE")
self.assertRegex(actual, "{bzl:tag-class} bzlmod_ext_tag_no_doc")
self.assertRegex(actual, "bzlmod_ext_tag_a_attribute_2")
self.assertRegex(actual, "BZLMOD_EXT_TAG_A_ATTRIBUTE_2_DEFAULT_VALUE")

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

0 comments on commit 0475c9e

Please sign in to comment.