安装
pip install sphinx
使用
sphinx-quickstart
快速构建框架
mkdir docs
cd docs
sphinx-quickstart # 按提示输入
目录结构
.
├── build
├── make.bat
├── Makefile
└── source
├── conf.py # 配置文件
├── index.rst # 入口文件
├── _static
└── _templates
修改配置文件
import os
import sys
BASE_DIR = os.path.dirname(os.path.realpath(__file__))
PKG_DIR = os.path.dirname(os.path.dirname(BASE_DIR))
print(PKG_DIR)
sys.path.insert(0, PKG_DIR) # 添加docs上层目录到PYTHONPATH中,才可以搜索到上层目录的package
# ...
# 修改extensions
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.coverage',
'sphinx.ext.intersphinx',
'sphinx.ext.viewcode',
]
# 替换主题
# html_theme = 'alabaster'
html_theme = 'sphinx_rtd_theme'
# 添加master_doc(否则Read the Docs构建时会报错)
master_doc = 'index'
sphinx-apidoc
为上层目录的
bam2html
目录自动生成apidoc
sphinx-apidoc -o source/api ../bam2html/
make
构建HTML
编辑index.rst
.. bam2html documentation master file, created by
sphinx-quickstart on Fri Aug 28 14:33:06 2020.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
====================================
Bam2HTML |version| Documentation
====================================
Bam2HTML is a tool to generate highlighted html file from bam, which is based on
the command `samtools tview`.
API Reference
=============
.. toctree::
:caption: APIs
:hidden:
api/modules
:doc:`api/modules`
The APIs of modules
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
make html
浏览器查看效果
cd build/html
python -m SimpleHTTPServer 8088