用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代码注释文档的更多相关文章

  1. 利用graphviz软件和pycallgraph库自动生成Python代码函数调用关系图

    参考博文:https://blog.csdn.net/qq_36408085/article/details/82952846 https://blog.csdn.net/fondax/article ...

  2. 使用sphinx快速生成Python API 文档

    一  简单介绍 不管是开源还是闭源,文档都是很重要的.当然理论上说,最好的文档就是代码本身,但是要让所有人都能读懂你的代码这太难了.所以我们要写文档.大部分情况,我们不希望维护一份代码再加上一份文档, ...

  3. 文件参数化-utp框架之根据yaml文件自动生成python文件+utp运行用例

    根据yaml文件自动生成python文件 utp框架: bin目录:存放执行文件(run.py) cases目录:存放生成的用例的python文件(该目录下的文件为根据data目录下的测试用例生成的p ...

  4. wsdl自动生成Java代码,根据wsdl生成Java代码

    wsdl自动生成Java代码,根据wsdl生成Java代码 >>>>>>>>>>>>>>>>>&g ...

  5. 使用xorm工具,根据数据库自动生成 go 代码

    使用xorm工具,根据数据库自动生成 go 代码 引入 使用 golang 操作数据库的同学都会遇到一个问题 -- 根据数据表结构创建对应的 struct 模型.因为 golang 的使用首字母控制可 ...

  6. mybatis自动生成java代码

    SSM框架没有DB+Record模式,写起来特别费劲,只能用下面的方法勉强凑合. 上图中,*.jar为下载的,src为新建的空白目录,.xml配置如下. <?xml version=" ...

  7. PyCharm配置autopep8,自动格式化Python代码

    1. 关于PEP 8 PEP 8,Style Guide for Python Code,是Python官方推出编码约定,主要是为了保证 Python 编码的风格一致,提高代码的可读性. 官网地址:h ...

  8. 基于数据库的自动化生成工具,自动生成JavaBean、数据库文档、框架代码等(v5.8.8版)

    TableGo v5.8.8版震撼发布,此次版本更新如下:          1.新增两个扩展字段,用于生成自定义模板时使用.          2.自定义模板新增模板目录,可以选择不同分类目录下的模 ...

  9. 使用mybatis-generator工具自动生成mybatis代码

    使用mybatis-generator工具自动生成mybatis代码 步骤如下: 1.引入maven  依赖,在项目pom.xml文件中添加 <plugin> <groupId> ...

随机推荐

  1. pyspider 安装时 Could not run curl-config

    sudo aptitude install libcurl4-openssl-dev

  2. UNIX常用命令

    以下只说明各常用指令的基本用法, 若需详细说明, 请用 man 去读详细的 manual. 1.关於档案/目录处理的命令 ls--列目录 这是最基本的档案指令. ls 的意义为 "list& ...

  3. Linux-001-nmon系统性能监控工具的使用及报表产出

    在进行性能测试的时候,需要获取服务器的各项指标,例如 CPU.MEM.I/O.DISK 等.网上有很多的监控工具,nmon 就是其中的一个,其可与 JMeter结合使用,测试系统的性能.其概要的介绍, ...

  4. test [ ] 四类

    test可理解的表达式类型分为四类:     表达式判断     字符串比较     数字比较     文件比较 test xxx 可以简写成 [  xxx  ] 的形式,注意两端的空格.   1)判 ...

  5. Issue 6: 装机系列1,PC下windows系统安装指南

    0.前言 接触电脑将近7年时间,多次说要写下这篇文章,一直未曾提笔,始终怕给人以误导.到如今,来来回回装系统的次数得超过百次了.本着不误导人的想法,本文试着总结一下装系统的基本方法和思路,但不会过多涉 ...

  6. Python之路-python(css、JavaScript)

    css JavaScript 一.CSS 分层: position: fixed;(固定到页面的具体位置) 例如:返回顶部 <!DOCTYPE html> <html lang=&q ...

  7. ios - NSTimer中target的self是强引用问题

    当控制器ViewController跳转进入控制器OneViewController中的时候开启定时器,让定时器每隔一段时间打印一次,当OneViewController dismiss的时候,控制器 ...

  8. sql rank()函数

    RANK() OVER([<partiton_by_clause>]) partition_by_clause 将from子句生成的结果集划分为应用到RANK函数的分区.  Order_b ...

  9. C# EasyUI树形结构权限管理模块

    最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来. 十年河东十年河西,莫欺少年穷 学无止境,精益求精 本节和大家探讨下C#使用EasyUI树形结构/Tree构 ...

  10. HTTP和HTTPS的区别

    1.HTTP和HTTPS的概念 超文本传输协议HTTP(Hypertext transfer protocol)是一种详细规定了浏览器和万维网服务器之间相互通信的规则,通过因特网传送万维网文档的数据传 ...