Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Section ignored by Sphinx using numpy-style formatting

I'm trying to extract from my module the docstrings and build a nice documentation. So here I am with Sphinx, and I can't figure out what's wrong.

My class docstring, inside the _meta file:

class MasterBlock(object):
    """
    Main class for block architecture. All blocks should inherit this class.    

    Methods
    -------
    main()
        Override it to define the main function of this block.
    add_input(Link object)
        Add a Link object as input.
    add_output(Link object)
        Add a Link as output.
    start()
        Start the main() method as a Process.
    stop()
        Stops the process.
    """

my .rst :

Meta
==========================

.. automodule:: crappy.blocks._meta
    :members:
    :undoc-members:
    :show-inheritance:

My configuration file for Sphinx (the part I changed):

autoclass_content = 'both'
extensions = ['sphinx.ext.autodoc','sphinx.ext.napoleon']
napoleon_numpy_docstring = True

When I try make html, it works (no error on this module), but it doesn't display the "Methods" section. If I remove it in the docstring, the only difference it makes with the html is that listed method below are no longer links.

What am I missing?

like image 490
CoMartel Avatar asked Jul 14 '26 05:07

CoMartel


1 Answers

You should try using the numpydoc Sphinx extension. Once you've installed it then you simply include it in your list of Sphinx extensions:

extensions = ['sphinx.ext.autodoc', 'sphinx.ext.napoleon', 'numpydoc']

In conf.py you then have access to the following options:

  • numpydoc_show_class_members: bool

    Whether to show all members of a class in the Methods and Attributes sections automatically. True by default.

  • numpydoc_show_inherited_class_members: bool

    Whether to show all inherited members of a class in the Methods and Attributes sections automatically. If it's false, inherited members won't shown. True by default.

  • numpydoc_class_members_toctree: bool

    Whether to create a Sphinx table of contents for the lists of class methods and attributes. If a table of contents is made, Sphinx expects each entry to have a separate page. True by default.

like image 67
ali_m Avatar answered Jul 20 '26 12:07

ali_m



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!