安装

  1. pip install sphinx

使用

sphinx-quickstart

快速构建框架

  1. mkdir docs
  2. cd docs
  3. sphinx-quickstart # 按提示输入

image.png
目录结构

  1. .
  2. ├── build
  3. ├── make.bat
  4. ├── Makefile
  5. └── source
  6. ├── conf.py # 配置文件
  7. ├── index.rst # 入口文件
  8. ├── _static
  9. └── _templates

修改配置文件

  1. import os
  2. import sys
  3. BASE_DIR = os.path.dirname(os.path.realpath(__file__))
  4. PKG_DIR = os.path.dirname(os.path.dirname(BASE_DIR))
  5. print(PKG_DIR)
  6. sys.path.insert(0, PKG_DIR) # 添加docs上层目录到PYTHONPATH中,才可以搜索到上层目录的package
  7. # ...
  8. # 修改extensions
  9. extensions = [
  10. 'sphinx.ext.autodoc',
  11. 'sphinx.ext.coverage',
  12. 'sphinx.ext.intersphinx',
  13. 'sphinx.ext.viewcode',
  14. ]
  15. # 替换主题
  16. # html_theme = 'alabaster'
  17. html_theme = 'sphinx_rtd_theme'
  18. # 添加master_doc(否则Read the Docs构建时会报错)
  19. master_doc = 'index'

sphinx-apidoc

为上层目录的bam2html目录自动生成apidoc

  1. sphinx-apidoc -o source/api ../bam2html/

image.png

make

构建HTML

编辑index.rst

  1. .. bam2html documentation master file, created by
  2. sphinx-quickstart on Fri Aug 28 14:33:06 2020.
  3. You can adapt this file completely to your liking, but it should at least
  4. contain the root `toctree` directive.
  5. ====================================
  6. Bam2HTML |version| Documentation
  7. ====================================
  8. Bam2HTML is a tool to generate highlighted html file from bam, which is based on
  9. the command `samtools tview`.
  10. API Reference
  11. =============
  12. .. toctree::
  13. :caption: APIs
  14. :hidden:
  15. api/modules
  16. :doc:`api/modules`
  17. The APIs of modules
  18. Indices and tables
  19. ==================
  20. * :ref:`genindex`
  21. * :ref:`modindex`
  1. make html

image.png
浏览器查看效果

  1. cd build/html
  2. python -m SimpleHTTPServer 8088

image.png