How can I use Sphinx' Autodoc-extension for private methods?

15,870

Solution 1

if you are using sphinx 1.1 or above, from the sphinx documentation site at http://www.sphinx-doc.org/en/master/ext/autodoc.html,

:special-members:
:private-members:

Solution 2

You can add this to conf.py file:

autodoc_default_flags = ['members', 'undoc-members', 'private-members', 'special-members', 'inherited-members', 'show-inheritance']

Solution 3

One way to get around this is to explicitly force Sphinx to document private members. You can do this by appending automethod to the end of the class level docs:

class SmokeMonster(object):
   """
   A large smoke monster that protects the island.
   """
   def __init__(self,speed):
      """
      :param speed: Velocity in MPH of the smoke monster
      :type  speed: int

      .. document private functions
      .. automethod:: _evaporate
      """
      self.speed = speed

   def _evaporate(self):
      """
      Removes the smoke monster from reality. Not to be called by client.
      """
      pass

Solution 4

Have you tried using a custom method for determining whether a member should be included in the documentation, using autodoc-skip-member?

Solution 5

Looking at apidoc code, we can change what sphinx-apidoc generate setting an environment variable:

export SPHINX_APIDOC_OPTIONS='members,special-members,private-members,undoc-members,show-inheritance'

You can also add this setup into your Makefile (if your package uses one):

docs:
    rm -rf docs/api
    SPHINX_APIDOC_OPTIONS='members,special-members,private-members,undoc-members,show-inheritance' sphinx-apidoc -o docs/api/ intellprice
    $(MAKE) -C docs clean
    $(MAKE) -C docs html
Share:
15,870
cnu
Author by

cnu

A computer programmer, recently became an entrepreneur ready to make my own dent.

Updated on June 19, 2022

Comments

  • cnu
    cnu about 2 years

    I am using Sphinx for documenting my python project. I have the autodoc extension enabled and have the following in my docs.

    .. autoclass:: ClassName
       :members:
    

    The problem is, it only documents the non-private methods in the class. How do I include the private methods too?