How do I document members in specific sections using Sphinx?

ぃ、小莉子 提交于 2019-12-01 13:21:52

问题


I'm struggling to figure out how to place the documentation for specific members of my Python class in specific sections of my Sphinx documentation, ideally while auto-documenting the rest in another section.

I have a Python class

class MyClass(object):

    def funky(self, arg):
        """Some docs."""
        ...

defined in my/module.py which works as expected and I can document without issues using

***************************
MyModule - :mod:`my.module`
***************************

.. automodule:: my.module

.. autoclass:: MyClass
   :members:
   :undoc-members:
   :show-inheritance:

But when I try to get more control over the organization of my documentation I can't get things working. Specifically, I'd like to have some members documented in explicit sections (just one is shown here, but there would be several), with the rest auto-documented as a group.

But when I try this with, for example

***************************
MyModule - :mod:`my.module`
***************************

To document
===========

Things that are not yet documented.

.. automodule:: my.module

.. autoclass:: MyClass
   :members:
   :undoc-members:
   :show-inheritance:
   :exclude-members: funky

Funky things
------------

Some funky things.

.. automethod:: funky

I get

WARNING: don't know which module to import for autodocumenting u'funky' (try placing a "module" or "currentmodule" directive in the document, or giving an explicit module name)

but no variations of

.. currentmodule:: my.module
.. class:: MyClass

.. automethod:: funky

or

.. currentmodule:: my.module

   .. automethod:: funky

etc. get me anywhere.

How do I auto-document some members of my class in specific places in my Sphinx documentation?


回答1:


This works:

.. currentmodule:: my.module

.. automethod:: MyClass.funky

You could skip .. currentmodule:: and do it like this:

.. automethod:: my.module.MyClass.funky

A third option:

.. currentmodule:: my.module

.. autoclass:: MyClass   

   .. automethod:: funky


来源:https://stackoverflow.com/questions/34010116/how-do-i-document-members-in-specific-sections-using-sphinx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!