[Dynamic Language] 用Sphinx自动生成python代码注释文档
用Sphinx自动生成python代码注释文档
pip install -U sphinx
安装好了之后,对Python代码的文档,一般使用sphinx-apidoc来自动生成:
查看帮助
mac-abeen:doc_logic abeen$ sphinx-apidoc --help
Usage: sphinx-apidoc [options] -o <output_path> <module_path> [exclude_path, ...]
Look recursively in <module_path> for Python modules and packages and create
one reST file with automodule directives per package in the <output_path>.
The <exclude_path>s can be files and/or directories that will be excluded
from generation.
Note: By default this script will not overwrite already created files.
Options:
-h, --help show this help message and exit
-o DESTDIR, --output-dir=DESTDIR
Directory to place all output
-d MAXDEPTH, --maxdepth=MAXDEPTH
Maximum depth of submodules to show in the TOC
(default: 4)
-f, --force Overwrite existing files
-l, --follow-links Follow symbolic links. Powerful when combined with
collective.recipe.omelette.
-n, --dry-run Run the script without creating files
-e, --separate Put documentation for each module on its own page
-P, --private Include "_private" modules
-T, --no-toc Don't create a table of contents file
-E, --no-headings Don't create headings for the module/package packages
(e.g. when the docstrings already contain them)
-M, --module-first Put module documentation before submodule
documentation
-s SUFFIX, --suffix=SUFFIX
file suffix (default: rst)
-F, --full Generate a full project with sphinx-quickstart
-H HEADER, --doc-project=HEADER
Project name (default: root module name)
-A AUTHOR, --doc-author=AUTHOR
Project author(s), used when --full is given
-V VERSION, --doc-version=VERSION
Project version, used when --full is given
-R RELEASE, --doc-release=RELEASE
Project release, used when --full is given, defaults
to --doc-version
--version Show version information and exit
生成命令
sphinx-apidoc [options] -o outputdir packagedir [pathnames]
进入outputdir目录
make html
然后就能在\_build\html文件夹中看到生成好的文档了,还支持查找的功能
注意修改conf.py把项目目录加入,否则生成时找不到模块没法导入
sys.path.append(os.path.abspath('/users/abeen/abeen/**/web'))
示例:
1: 在src(源码目录)目录上级目录下执行
sphinx-apidoc -F -o ./apidoc ./src
在当前目录下新建apidoc目录,生成api文档的文件夹就在此目录下,./src 表示需要生成api文档的目录。
2: 进入apidoc目录 修改conf.py文件 设置代码路径为sys.path.insert(0, os.path.abspath('../src'))
3: 在apidoc目录下执行make html 生成html文件.
Sphinx 标记语法示例
This is a Title
===============
That has a paragraph about a main subject and is set when the '='
is at least the same length of the title itself. Subject Subtitle
----------------
Subtitles are set with '-' and are required to have the same length
of the subtitle itself, just like titles. Lists can be unnumbered like: * Item Foo
* Item Bar Or automatically numbered: #. Item 1
#. Item 2 Inline Markup
-------------
Words can have *emphasis in italics* or be **bold** and you can define
code samples with back quotes, like when you talk about a command: ``sudo``
gives you super user powers! 嵌入代码:
- 行内代码 用``code``
- 简单代码块 在代码块的上一个段落后面加2个冒号,空一行后开始代码块,代码块要缩进.
- 复杂代码块 使用code-block指导语句,还可以选择列出行号和高亮重点行等.
source code below ::
void foo()
{
}
source code again
.. code-block:: c
:linenos:
:emphasize-lines: ,
void foo()
{
}
[Dynamic Language] 用Sphinx自动生成python代码注释文档的更多相关文章
- 利用graphviz软件和pycallgraph库自动生成Python代码函数调用关系图
参考博文:https://blog.csdn.net/qq_36408085/article/details/82952846 https://blog.csdn.net/fondax/article ...
- 使用sphinx快速生成Python API 文档
一 简单介绍 不管是开源还是闭源,文档都是很重要的.当然理论上说,最好的文档就是代码本身,但是要让所有人都能读懂你的代码这太难了.所以我们要写文档.大部分情况,我们不希望维护一份代码再加上一份文档, ...
- 文件参数化-utp框架之根据yaml文件自动生成python文件+utp运行用例
根据yaml文件自动生成python文件 utp框架: bin目录:存放执行文件(run.py) cases目录:存放生成的用例的python文件(该目录下的文件为根据data目录下的测试用例生成的p ...
- wsdl自动生成Java代码,根据wsdl生成Java代码
wsdl自动生成Java代码,根据wsdl生成Java代码 >>>>>>>>>>>>>>>>>&g ...
- 使用xorm工具,根据数据库自动生成 go 代码
使用xorm工具,根据数据库自动生成 go 代码 引入 使用 golang 操作数据库的同学都会遇到一个问题 -- 根据数据表结构创建对应的 struct 模型.因为 golang 的使用首字母控制可 ...
- mybatis自动生成java代码
SSM框架没有DB+Record模式,写起来特别费劲,只能用下面的方法勉强凑合. 上图中,*.jar为下载的,src为新建的空白目录,.xml配置如下. <?xml version=" ...
- PyCharm配置autopep8,自动格式化Python代码
1. 关于PEP 8 PEP 8,Style Guide for Python Code,是Python官方推出编码约定,主要是为了保证 Python 编码的风格一致,提高代码的可读性. 官网地址:h ...
- 基于数据库的自动化生成工具,自动生成JavaBean、数据库文档、框架代码等(v5.8.8版)
TableGo v5.8.8版震撼发布,此次版本更新如下: 1.新增两个扩展字段,用于生成自定义模板时使用. 2.自定义模板新增模板目录,可以选择不同分类目录下的模 ...
- 使用mybatis-generator工具自动生成mybatis代码
使用mybatis-generator工具自动生成mybatis代码 步骤如下: 1.引入maven 依赖,在项目pom.xml文件中添加 <plugin> <groupId> ...
随机推荐
- QuicKHit
public class Level { private int levelNo;// 各级别编号 private int strLength;// 各级别一次输出字符串的长度 private int ...
- sublime通用快捷键 汉化 安装 插件
Ctrl+Alt+P 切换项目 1.Ctrl+Shift+P 打开Package Control Ctrl + Shift + P ,输入View, 选择Toogle Tabs ...
- 毕设1--利用Java实现网页的模板功能技术---简要了解
首先,关于我对自己的毕业设计题目的理解,其中没有接触过的技术有怎么用Java实现将原有的Word的模板上传到网页中,在网页中进行相关操作.之所以把这部分放在一开始来进行了解是因为没有接触过这一方面,比 ...
- css控制段落
<p></p>标签:一段话或者段落适宜于用p标签: 段落缩进:text-indent:50px: 文字方向:text-align:center居中.left往左显示.right ...
- 采用阿里的API进行动态域名解析
#!/usr/bin/env python # -*- coding:utf-8 -*- import os from aliyunsdkcore import client from aliyuns ...
- js中的逻辑与(&&)和逻辑或(||)(转载)
var a = 2; var b = 3; var andflag = a && b ; var orflag = a || b; 问andflag 和orflag 分别是什么? 起初 ...
- rpm与yum
设置本地源与网络源:https://my.oschina.net/u/1861462/blog/723958 rpm命令:http://man.linuxde.net/rpm https://my.o ...
- sed处理url编码解码=== web日志的url处理
URL 编码/解码方法(linux shell实现),方法如下: 1.编码的两种方法: admin@~ 11:14:29>echo '手机' | tr -d '\n' | xxd -plain ...
- Angular动态编译Html
//取得scope,有时可以使用this var scope=angular.element(this).scope(); var el= $compile(html)(scope); //加入到Do ...
- CURL in windows
目前版本为: 7.50.3 >> 不同操作系统及版本的下载页面 https://curl.haxx.se/download/?C=M;O=D Windows上的下载入口及地址为: htt ...