Sphinx: Documentation Generator
Sphinx: 文档生成
创建与配置项目
sphinx-quickstart
使用这个命令,快速创建项目。跟随指导做一些选项。
生成文档
使用命令 sphinx-build -b html sourcedir builddir
或者 make html
基本配置
基本配置在 conf.py
文件中。这个文件就是一个python 脚本,可以执行各种python函数和导入其它库等。
配置参考configuration
写文档
文档结构
-
index.rst
文件是文档的欢迎页面,其中包括- 目录树
toctree
- 目录树
reStructuredText directives
rst 指令的格式中包括
- 参数:在指令名后面的冒号之后,每个指令可以有若干个参数
- 选项:在参数之后,选项的形式是
名-值
的列表,一行一个 - 内容:在参数之后空一行
-
toctree
目录参考:directives/toctree-directive
.. toctree:: :maxdepth: 2 intro strings datatypes numeric (many more documents listed here)
Domains
为了对应 python/c++ 中的名字空间,防止函数名冲突,要把函数的文档写在 domain 里。
参考 domains
-
基本语法
可以一次生成两个函数
.. py:function:: spam(eggs) ham(eggs) Spam or ham the foo.
如果一个函数很长,可以折行并加上
:noindex:
.. py:function:: filterwarnings(action, message='', category=Warning, \ module='', lineno=0, append=False) :noindex:
默认的 domain 是 python,可以用
.. default-domain:: name
修改 -
交叉引用
基本语法是
:role:`title <target>`
这会引用target
但显示的是title
- 前面加
!
不生成引用 - 前面加 波浪线
\~
只会显示最后一个元素的引用:py:meth:`\~Queue.Queue.get`
只显示get
- 前面加
-
C++
Autodoc: 注释文档
通过 autodoc 可以从源码的注释生成文档。需要在 conf.py
的 extensions
中加入 'sphinx.ext.autodoc'
. 之后就可以利用 autofunction
automodule
等指令,将注释作为文档导入。
breathe
breathe 是通过 doxygen 生成 c/c++ 的文档的工具
基本使用
设置 conf.py
breathe_projects_source = {
"my_proj": ("../src", ["oneheader.h"]),
}
breathe_default_project = "my_proj"
就可以在 index.rst
中使用
.. autodoxygenfile:: oneheader.h
评论
Comments powered by Disqus