Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is sphinx automodule not showing any module members?

I started working on a python module and wanted to document the code "in place". So i set up sphinx in a subdirectory with sphinx-quickstart resulting in this directory structure (only the files i edited are shown):

  • myproject/
    • __init__.py
    • main.py
  • docs/ (sphinx directory)
    • build/
    • source/
      • conf.py
      • index.rst
  • setup.py

My index.rst contains:

Welcome to My Module's documentation!
=====================================

.. toctree::
   :maxdepth: 2
   :caption: Contents:

.. automodule:: myproject
    :members:


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

When i run

make html

i get a documentation that is missing the automodule part allthough i documented every class and every method in main.py like this:

class Thing:
    """This class represents Things

    :param color: how the thing should look like
    """

    def __init__(self, color):
        pass

    def color(self):
        """Tells you the color of the thing.

        :returns: Color string
        :rtype: str or unicode
        """
        pass

Sys.path is also setup correctly, as it throws now error when making

sys.path.insert(0, os.path.abspath('../../'))

If it is relevant i also include the setup.py:

from setuptools import setup

setup(name='My Module',
      version='0.1',
      description='Internet of Things',
      url='https://example.com',
      author='Master Yoda',
      author_email='[email protected]',
      license='GPLv3',
      packages=['mymodule'],
      zip_safe=False)

What can i change to make autodoc work?

like image 947
lalu Avatar asked Mar 07 '19 19:03

lalu


2 Answers

If your class is imported into __init__.py you may also need :imported-members: like so:

.. automodule:: myproject
   :imported-members:
   :members:
   :undoc-members:
   :show-inheritance:
like image 116
spacether Avatar answered Nov 09 '22 02:11

spacether


The main module is in the myproject package. In order to document main, you need the following:

.. automodule:: myproject.main
   :members:
like image 35
mzjn Avatar answered Nov 09 '22 02:11

mzjn