Structuring Sphinx documentation

后端 未结 3 1186
既然无缘
既然无缘 2021-02-13 18:52

I have started documenting a Python project using Sphinx. It is the first time I use it - I am used to tools which work with a JavaDoc-like syntax, and I have some doubts.

相关标签:
3条回答
  • 2021-02-13 19:06

    Even I am not an expert in this, but I think I can answer what you have asked here(about having the organization of the documentation/ rst files).

    The key you may be missing here is instead of using the autoclass/automodule/automethod calls in the same top level TOCs rst-file, this top level file should contain links to other rst files containing these calls.

    suppose you have all rst files inside doc dir (and subdirs),

    Table of contents
    =================
    The contents of the docs are:
    
    .. toctree::
        :maxdepth: 1
    
        module_1/index
        module_2/index
    

    in the dir containing this top level index.rst, you will have subdirs with name module_1 and module_2. These will have index.rst (name is just example specific) which in turn will contain the .. automodule::, .. autoclass::, and .. automethod::. It can contain something like

    :mod:`module_1`
    ---------------
    
    ..automodule:: module_1
        :show-inheritance:
    
    .. autoclass:: module_1.MyClass
    

    Of course, this is not something like standard, or ideal way of doing, I am suggesting this because it's neater. you can alternatively have all the rst files with module/class/method docs in the same dir as the top level index.rst, with structure

    Table of contents
    =================
    The contents of the docs are:
    
    .. toctree::
        :maxdepth: 1
    
        module_1
        module_2
    

    and the same dir will contain the doc-files module_1.rst, module_2.rst etc. The paths are relative to the config.py file.

    0 讨论(0)
  • 2021-02-13 19:08

    I am by no means an expert on Sphinx, but from reading the documentation it seems that you can include TOC trees in subdirectories. The TOC tree page also gives some information on paths within the tree; have you experimented with using paths in the tree?

    0 讨论(0)
  • 2021-02-13 19:15

    I found this autopackage script from a comment here. It generates the necessary .rst files according to the structure of your packages.

    side note: I still feel I am missing something, as I cannot believe that a tool like Sphinx, which is renowned as the most advanced tool for documenting Python, misses the functionality to do basic API documentation. Hence I will leave the question open for a while before accepting my own answer.

    0 讨论(0)
提交回复
热议问题