用sphinx,git,readthedoc維護(hù)API文檔

安裝sphinx:

# apt install python-pip

# pip install sphinx

# pip install sphinx_rtd_theme

# mkdir -p doc

# cd doc

# sphinx-quickstart

Note that some configurations needto change:

>?Separate?source?and?build?directories?(y/N)?[n]:

y

>?Name?prefix?for?templates?and?static?dir?[_]:

>?Project?name:

ABC

>?Author?name(s):

Aarpm

>?Project?version:

1.0

>?autodoc:?automatically?insert?docstrings?from?modules?(y/N)?[n]:

y

>?doctest:?automatically?test?code?snippets?in?doctest?blocks?(y/N)?[n]:

y

>?intersphinx:?link?between?Sphinx?documentation?of?different?projects?(y/N)?[n]:

y

>?todo:?write?“todo”?entries?that?can?be?shown?or?hidden?on?build?(y/N)?[n]:

y

>?ifconfig:?conditional?inclusion?of?content?based?on?config?values?(y/N)?[n]:

y

>?Create?Makefile??(Y/n)?[y]:

y

>?Create?Windows?command?file??(Y/n)?[y]:

y

配置sphinx:

# vim source/conf.py

Uncomment:

"

import os

import sys

sys.path.insert(0,os.path.abspath('..'))

"

Add lines as follows:

autodoc_mock_imports = ['xx'] /*這部分的內(nèi)容取決于項(xiàng)目需要stub的python模塊,主要用作做mock那些無法正常import的模塊*/

extensions = [

???'sphinx.ext.autodoc',

???'sphinx.ext.intersphinx',

???'sphinx.ext.ifconfig',

???'sphinx.ext.doctest',

???'sphinx.ext.todo',

???'sphinx.ext.coverage',

???'sphinx.ext.viewcode', /*該選項(xiàng)可以讓你在web上直接點(diǎn)擊API來瀏覽源代碼*/

]

html_theme = 'sphinx_rtd_theme'

# sphinx-apidoc -f -o ./source/home/xx/<your project folder>

# make html

Running Sphinx v1.7.5

loading pickled environment... done

building [mo]: targets for 0 pofiles that are out of date

building [html]: targets for 0source files that are out of date

updating environment: 0 added, 1changed, 0 removed

reading sources... [100%]api.generic

looking for now-outdated files...none found

pickling environment... done

checking consistency... done

preparing documents... done

writing output... [100%] index

generating indices... genindexpy-modindex

highlighting module code... [100%]api.structures.objects

writing additional pages... search

copying static files... done

copying extra files... done

dumping search index in English(code: en) ... done

dumping object inventory... done

build succeeded.

The HTML pages are in build/html.

修改生成的*.rst做格式調(diào)整(斜體部分為范例)

For index.rst

Welcome to xx documentation!

===============================

.. toctree::

??:maxdepth: 2

??:caption: Contents:

??api.adapter

??api.generic

??api.structures

Remove 'package', 'submodule' stuff in other rst file

api.adapter

===================

.. toctree::

???:maxdepth: 2

???:numbered: 2 ---- mark for number displaying

???api.adapter.xx

???api.adapter.xx

git push你的改動

# git add .

# git commit -m "xx"

# git push origin master

git中添加web hook

訪問https://readthedocs.io/導(dǎo)入github上的項(xiàng)目(https://github.com/xx/)

托管網(wǎng)站會自動編譯并識別其中的rst文件,訪問https://<your project name>.readthedocs.io/en/latest/index.html來查看最終的效果。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容