16

I am trying to document a package in Python. At the moment I have the following directory structure:

.
└── project
    ├── _build
    │   ├── doctrees
    │   └── html
    │       ├── _sources
    │       └── _static
    ├── conf.py
    ├── index.rst
    ├── __init__.py
    ├── make.bat
    ├── Makefile
    ├── mod1
    │   ├── foo.py
    │   └── __init__.py
    ├── mod2
    │   ├── bar.py
    │   └── __init__.py
    ├── _static
    └── _templates

This tree is the result of the firing of sphinx-quickstart. In conf.py I uncommented sys.path.insert(0, os.path.abspath('.')) and I have extensions = ['sphinx.ext.autodoc'].

My index.rst is:

.. FooBar documentation master file, created by
   sphinx-quickstart on Thu Aug 28 14:22:57 2014.
   You can adapt this file completely to your liking, but it should at least
   contain the root `toctree` directive.

Welcome to FooBar's documentation!
==================================

Contents:

.. toctree::
   :maxdepth: 2

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

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

In all the __init__.py's I have a docstring and same goes to the modules foo.py and bar.py. However, when running make html in the project I don't see any of the docstings.

4
  • You have a single top level index.rst file but nothing else. That is not enough. You need to run sphinx-apidoc to generate the needed .rst sources (or create them "by hand"). Commented Aug 28, 2014 at 13:10
  • Sphinx requires .rst files with directives like automodule or autoclass in order to generate API documentation. It does not extract from the sources without that. Maybe you expected Sphinx to work like Epydoc or Doxygen, but it does not. See also these answers: stackoverflow.com/a/2441159/407651, stackoverflow.com/a/6109098/407651. Commented Aug 28, 2014 at 13:28
  • 1
    Let us continue this discussion in chat. Commented Aug 28, 2014 at 14:28
  • 1
    Just wrote a complete working example with PyCharm, it can be used for inspiration. stackoverflow.com/a/46362065/1980180 Commented Sep 25, 2017 at 10:09

1 Answer 1

12

Here is an outline:

  1. Document your package using docstrings in the sources.
  2. Use sphinx-quickstart to create a Sphinx project.
  3. Run sphinx-apidoc to generate .rst sources set up for use with autodoc. More information here.

    Using this command with the -F flag also creates a complete Sphinx project. If your API changes a lot, you may need to re-run this command several times.

  4. Build the documentation using sphinx-build.

Notes:

Sign up to request clarification or add additional context in comments.

4 Comments

Where should I run sphinx-apidoc? What do do with generated .rst files? Where to put them? How is using -F different from spinx-quickstart?
@minerals. Where should I run sphinx-apidoc? What do you mean by "where"? What is the problem? What do do with generated .rst files? Where to put them? You put them wherever is convenient. And then you run sphinx-build on them.
@minerals. How is using -F different from spinx-quickstart? If you run sphinx-apidoc -F, you in effect run sphinx-quickstart and sphinx-apidoc in one go. That's just another way of doing it.
@minerals. Regarding sphinx-apidoc: I linked to sphinx-doc.org/man/sphinx-apidoc.html in my answer. Is there something that is unclear on that page? Also note that if you have a stable API, it's not necessary to run sphinx-apidoc over and over again. See stackoverflow.com/q/28481471/407651.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.