Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to document Python function parameters with sphinx-apidoc?

Tags:

I'm trying to clean up my python code documentation, and decided to use sphinx-doc because it looks good. I like how I can reference other classes and methods with tags like:

:class:`mymodule.MyClass` About my class.
:meth:`mymodule.MyClass.myfunction` And my cool function

I'm trying to figure out though how to document parameter names in a function, so that if I have a function like:

def do_this(parameter1, parameter2):
   """
   I can describe do_this.

   :something?:`parameter1` And then describe the parameter.

   """

What's the best practice for this?

Update:

The correct syntax is:

def do_this(parameter1, parameter2):
   """
   I can describe do_this.

   :something parameter1: And then describe the variable
   """
like image 397
Adam Morris Avatar asked Mar 02 '12 13:03

Adam Morris


People also ask

What does Sphinx-Apidoc do?

sphinx-apidoc is a tool for automatic generation of Sphinx sources that, using the autodoc extension, document a whole package in the style of other automatic API documentation tools. MODULE_PATH is the path to a Python package to document, and OUTPUT_PATH is the directory where the generated sources are placed.

Does Sphinx support markdown?

To support Markdown-based documentation, Sphinx can use MyST-Parser. MyST-Parser is a Docutils bridge to markdown-it-py, a Python package for parsing the CommonMark Markdown flavor.


2 Answers

Typically "function variables" are called parameters ;).

It's documented here: http://www.sphinx-doc.org/en/master/usage/restructuredtext/domains.html#signatures

And the answer is :param ________

EDIT Disclaimer: I've never used or heard of sphinx... This post is mostly a "what words to search for." Hope it helped.

like image 80
Chris Pfohl Avatar answered Oct 18 '22 18:10

Chris Pfohl


Adding this answer to consolidate options:

pydoc is basic with no special formatting

epydoc uses the format '@param var:'

Doxygen is oriented for a larger range of languages

Sphinx uses the format ':param type var:'. Also see more examples. This was used to create the Python 3.5 documentation.

like image 28
Robert E Avatar answered Oct 18 '22 18:10

Robert E