打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
利用Sphinx为python项目生成文档
Sphinx最初是为python而产生的,用于生成新的python官方文档, 现可支持其它语言.

以下环境都为 Ubuntu14.04+python3.4

安装Sphnix:
  $ pip3 search Sphinx
  $ pip3 install Sphinx

为项目生成文档(sphinx支持从 .py代码提取docstring来生成文档)
$ cd myproject
$ ls
a.py b.py c.py
$ sphinx-quickstart
Enter the root path for documentation.
> Root path for the documentation [.]: doc
> autodoc: automatically insert docstrings from modules (y/n) [n]: y
其它项都选择默认
完成之后,会在当前目录创建 doc 目录. 所有sphinx相关的文件都在 doc目录下

$ ls doc/
_build conf.py index.rst Makefile _static _templates

*****************注意**********************
一定要更改 doc/conf.py
$ vi doc/conf.py
sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath('..')) # **IMPORTANT** 缺少此行会导致在make html时提示 __import__出错. 所以必须把上一级目录(即代码所在目录)include进来

生成apidoc
$ sphinx-apidoc -o .doc/ .
Creating file doc/a.rst.
Creating file doc/modules.rst

# 把生成的 doc/modules.rst添加到index.rst
$ vi doc/index.rst

Contents:
 .. toctree::
    :maxdepth: 2

    modules.rst

生成html页面
$ cd doc
$ make html

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Sphinx初尝
使用 Sphinx 制作简洁而又美观的文档
如何使用 Sphinx 给 Python 代码写文档
ubuntu 查看 rst 格式 文件
使用sphinx记笔记 - 步进 - 博客园
不会写文档,叫什么高级程序员!
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服