简体   繁体   English

如何从docstring生成html文档

[英]How to generate html documents from docstring

I have a Python project, and wrote many docstring in functions,我有一个 Python 项目,在函数中写了很多文档字符串,

how to convert those docstring into html documentation in one or two steps,如何通过一两步将这些 docstring 转换为 html 文档,

I just want the Sphinx can act as doxygen, just convert all my comments or doctring into html documentation.我只希望 Sphinx 可以充当 doxygen,只需将我所有的评论或文档转换为 html 文档。

I run the sphinx-quickstart under the docs folder我在docs文件夹下运行sphinx-quickstart

then然后

> autodoc: automatically insert docstrings from modules (y/n) [n]: y

then modified the conf.py long_term_streaming_monitor/docs/source/conf.py然后修改了 conf.py long_term_streaming_monitor long_term_streaming_monitor/docs/source/conf.py

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

Because all of my source code are put under long_term_streaming_monitor/src因为我所有的源代码都放在long_term_streaming_monitor/src

The generated code is here download生成的代码在这里下载

I followed the tutorial, but when I opened the index.html I got nothing, no module and methods listed on the html file link我遵循了教程,但是当我打开 index.html 时,我什么也没得到,html 文件链接上没有列出模块和方法

.
├── docs
│   ├── _build
│   │   ├── doctrees
│   │   └── html
│   │       ├── _sources
│   │       └── _static
│   ├── _static
│   ├── _templates
│   └── html
└── src
    ├── long_term_streaming_monitor
    │   ├── log
    │   ├── scripts
    │   └── tests
    │       └── log
    └── long_term_streaming_monitor_.egg-info

As mentioned in one of the comments you can use sphinx.ext.autodoc 正如其中一条评论所述,您可以使用sphinx.ext.autodoc

More steps on quickstart here . 这里有关于快速入门的更多步骤。
Check a example configuration file here 在此处查看示例配置文件
Bonus - you can also integrate Travis with sphinx using travis-sphinx to autogenerate your github pages each time you push a code with new docstrings. 额外奖励 - 您还可以使用travis-sphinx将Travis与sphinx集成,以便在每次使用新文档字符串推送代码时自动生成github页面。

如果您发现Sphinx很麻烦,特别适合小型,简单的项目,请尝试使用pdoc

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

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