Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple way to convert Python docstrings from reStructured Text to Google style?

Does anyone now a simple way do convert all docstrings in an existing project from reStructured Text to the Google format?

It looks like Napoleon can do something like that, but it looks very complicated, so I figured I'd ask if someone has done that before. Any idea would be much appreciated.

like image 634
gmolau Avatar asked Jul 06 '17 17:07

gmolau


People also ask

What is Google style docstrings?

Docstrings may extend over multiple lines. Sections are created with a section header and a colon followed by a block of indented text. Example: Examples can be given using either the ``Example`` or ``Examples`` sections.

How do you generate a docstring in Python?

Declaring Docstrings: The docstrings are declared using ”'triple single quotes”' or “””triple double quotes””” just below the class, method or function declaration. All functions should have a docstring.

What is docstrings in Python give an example?

As mentioned above, Python docstrings are strings used right after the definition of a function, method, class, or module (like in Example 1). They are used to document our code. We can access these docstrings using the __doc__ attribute.


2 Answers

Try using pyment to convert docstrings from reStructuredText to Google format. Then use Napolean to generate documentation via Sphinx.

Napoleon is a pre-processor that parses NumPy and Google style docstrings and converts them to reStructuredText before Sphinx attempts to parse them.

like image 117
Steve Piercy Avatar answered Oct 10 '22 00:10

Steve Piercy


There is also docconvert at https://github.com/cbillingham/docconvert.

I personally found it did a much better job;

  • better indentation and line wrapping (personal choice)
  • coped with docstrings that were a mix of google and reSTructured styles in the same docstring!
like image 1
dsz Avatar answered Oct 10 '22 02:10

dsz