简体   繁体   English

如何从代码中自动在sphinx中创建顶级文档?

[英]How to create top-level documentation in sphinx automatically from code?

I have a python package and I am able to create sphinx documentation from the python code automatically with 我有一个python包,我可以自动创建python代码中的sphinx文档

sphinx-apidoc -f -o source --full path_to_package
make html

This works fine, and the html lists all submodules with their documentation. 这工作正常,html列出所有子模块及其文档。

But in the html I see the following sections/text: 但是在html中我看到以下部分/文字:

Package name
  Submodules
  First module
    docu...
  Second module
    docu ...

Each module does have its documentation, but how to place tom documentation text directly below the package name? 每个模块都有自己的文档,但是如何将tom文档文本直接放在包名下面? I want to have the following structure: 我想要有以下结构:

Package name
  General package documentation...
  Submodules
  First module
    docu...
  Second module
    docu ...

How to generate a documentation to appear on the top-level of a sphinx-generated documentation, describing the whole package, by ONLY change code in the python package? 如何生成一个文档,以显示在sphinx生成的文档的顶层,描述整个包,只需更改python包中的代码? I do not want to change/add/modify any of the files generated by sphinx. 我不想更改/添加/修改sphinx生成的任何文件。

Is this possible, and how to do that? 这可能吗,怎么做?

First put the documentation as a doc string in the packages __init__.py file. 首先将文档作为文档字符串放在包__init__.py文件中。

Then look in the docs folder containing your .rst files. 然后查看包含.rst文件的docs文件夹。 Edit the .rst for the package - the one with the Module contents at the end. 编辑包的.rst - 最后包含Module内容的包.rst

Then cut the Module Contents section and paste it to be at the top, above subpackages. 然后剪切“模块内容”部分并将其粘贴到顶部,上面的子包中。 Then run make html. 然后运行make html。

I realise that the op stated only changing python code in the original question, but given his later comment this does seem to be the answer. 我意识到op声明只改变了原始问题中的python代码,但考虑到他后来的评论,这似乎就是答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM