Search code examples
pythonpython-sphinxrestructuredtextread-the-docsautodoc

Readthedocs: Is there a way to autodoc same model functions separately in the one file?


Right now my docs/source has an index.rst that in its doctree imports another file called api.rst. In this api.rst file I would like to autodoc a python module. This module is a .py with many functions not attached to any class, but they are organized in groups by their functionality. I could write the api file like this:

fbbotw api
==========

.. automodule:: fbbotw
   :members:

However it will autodoc all functions without considering these groups. Right now, I'm trying to do that using the .. autofunction:: directive like this:

fbbotw Functions reference
==========================

Graph API Functions
-------------------

.. autofunction:: fbbotw.get_user_information


Send Api Functions
------------------

Sender Actions
~~~~~~~~~~~~~~

.. autofunction:: fbbotw.typing

Content Types
~~~~~~~~~~~~~

.. autofunction:: fbbotw.post_text_message
.. autofunction:: fbbotw.post_audio_attachment
.. autofunction:: fbbotw.post_file_attachment
.. autofunction:: fbbotw.post_image_attachment
.. autofunction:: fbbotw.post_video_attachment

Quick Replies
~~~~~~~~~~~~~

.. autofunction:: fbbotw.post_text_w_quickreplies


Templates
~~~~~~~~~

.. autofunction:: fbbotw.post_button_template
.. autofunction:: fbbotw.post_generic_template
.. autofunction:: fbbotw.post_list_template
.. autofunction:: fbbotw.post_receipt_template

Buttons
~~~~~~~

.. autofunction:: fbbotw.post_call_button


Thread Settings Functions
-------------------------

.. autofunction:: fbbotw.post_settings
.. autofunction:: fbbotw.post_greeting_text
.. autofunction:: fbbotw.post_start_button
.. autofunction:: fbbotw.post_persistent_menu
.. autofunction:: fbbotw.post_domain_whitelisting
.. autofunction:: fbbotw.post_account_linking_url

It works locally, but online readthedocs only creates the titles of api.rst but the .. autofunction:: doesn't do anything. Is there another way to do that or am I missing any configuration?

Other things I have tried:

For every group in api.rst create another file and import it toctree, and in these group files use .. automodule: fbbotw :members: function1, function2... specifying the members I want to autodoc in that file.

I really suspect that it may be a bad configuration on the readthedocs admin and I cannot make it work online, since it all works fine locally.


Solution

  • Answered in comments by @MikhailKorobov:

    so the problem is not related to autofunction vs automodule, it is autodocs which is not working, right? They have a FAQ section for this problem: http://read-the-docs.readthedocs.io/en/latest/faq.html#my-project-isn-t-building-with-autodoc

    There was an ImportError on my module so autodoc could not setup it. Checking the readthedocs building log I could see that this ImportError wasn't covered in my tests and also the environment for building the docs was diferent. Working now: http://fbbotw.readthedocs.io/en/latest/