Skip to content

Save module docstring to top of pyi files #385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 23, 2022

Conversation

Alphadelta14
Copy link
Contributor

This attempts to save javadoc-like comments as a module docstring to the top of the pyi files.

I love using this project with Sphinx and this was just a piece of missing information that I want to have exposed, especially since I leave tons of documentation about usage at the top of my protobuf files.

I will take a look at tests if this implementation looks okay (I don't want to overstep and rewrite some of the helper functions to be more elegant to this kind of change).

@nipunn1313
Copy link
Owner

If you add some module docstrings to the top of test.proto and test3.proto that can serve as a test.

@Alphadelta14 Alphadelta14 marked this pull request as ready for review July 21, 2022 04:13
Copy link
Owner

@nipunn1313 nipunn1313 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks for the contribution!
One comment with an idea on how to simplify the hack.

Comment on lines 840 to 841
if not self._write_comments([d.FileDescriptorProto.SYNTAX_FIELD_NUMBER]):
self._write_comments([d.FileDescriptorProto.PACKAGE_FIELD_NUMBER])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd think you'd want to print comments for both here?

Suggested change
if not self._write_comments([d.FileDescriptorProto.SYNTAX_FIELD_NUMBER]):
self._write_comments([d.FileDescriptorProto.PACKAGE_FIELD_NUMBER])
self._write_comments([d.FileDescriptorProto.SYNTAX_FIELD_NUMBER])
self._write_comments([d.FileDescriptorProto.PACKAGE_FIELD_NUMBER])

# HACK: convert single-line docstring to multiline
if self.lines[1].endswith('"""'):
self.lines[1] = self.lines[1][:-3]
self._write_line('"""')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still a hack, but here's a different idea for a hack to get this to work without too much factoring and line fudging.

Remove the inner triple quotes from HEADER and then try:

saved_lines = self.lines
self.lines = []

self._write_comments([d.FileDescriptorProto.SYNTAX_FIELD_NUMBER])
self._write_comments([d.FileDescriptorProto.PACKAGE_FIELD_NUMBER])
if self.lines:
  assert self.lines[0].startswith('"""')
  lines[0] = f'"""{HEADER}{lines[0][3:]}'
else:
  self._write_line(f'"""{HEADER}"""')

@nipunn1313 nipunn1313 merged commit 9f21fec into nipunn1313:main Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants