栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Sphinx使用说明

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Sphinx使用说明

link:https://blog.csdn.net/sinat_29957455/article/details/83657029

1. 安装插件:
pip3 install sphinx
pip3 install sphinx_rtd_theme
2. 新建一个项目:

3. 使用sphinx建立API文档项目:

进入到doc目录下,输入sphinx-quickstart命令,会输出选项。

注意看图中需要输入的内容!
项目创建后目录结构如下:

build:用来存放通过make html生成文档网页文件的目录
source:存放用于生成文档的源文件
conf.py:Sphinx的配置文件
index.rst:主文档

4. 修改source/conf.py文件中的配置信息:

模板如下,使用模板注意修改源文件位置等内容

# -*- coding: utf-8 -*-

# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))


# -- Project information -----------------------------------------------------

import os
import sys
sys.path.insert(0, os.path.abspath('E:/zhibenzhu/xxx/client/python/dqlib'))
sys.path.insert(0, os.path.abspath('E:/zhibenzhu/xxx/client/python/'))

project = 'test01汉语'
copyright = '2022, test1'
author = 'test1汉语'

# The full version, including alpha/beta/rc tags
release = '1.0'


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc',
    'sphinx.ext.doctest',
    'sphinx.ext.intersphinx',
    'sphinx.ext.todo',
    'sphinx.ext.coverage',
    'sphinx.ext.napoleon',
    'sphinx.ext.autodoc',
	'sphinx.ext.mathjax']

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = 'zh_CN'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages.  See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']


因为我们需要从Python代码的注释中自动导出API文档,所以需要将autodoc: automatically insert docstrings from modules (y/n) [n]: y如果忘记设置,可以在conf.py中的extensions中添加’sphinx.ext.autodoc’。选项后面没有输入的,直接按回车键使用默认设置。选项后面有输入的,按照我的设置即可,如果不使用中文文档,可以在language配置中使用默认设置。

其中,sphinx.ext.napoleon可以为sphinx添加额外的扩展,如果想要将html文档转换为PDF,只需要先安装扩展,然后再此处添加即可使用。由于我们的注释代码主要同时支持googlestyle和numpy style,所以我们需要添加一个扩展来支持。

html_theme = 'sphinx_rtd_theme'
5. 将命令行切换到doc目录下,将source和src修改为自己source和src所在路径,执行命令:
sphinx-apidoc -o source ../src/

6. 清理文件(doc目录下):
./make clean

7. 生成html文件(doc目录下):

tip:再次确认conf.py和index.rst两文件的编码格式是UTF-8,否则会乱码。

./make html
8. 打开build/html/index.html


home内容,版权所有内容和创作者内容可在conf.py中修改。
各级标题内容可在index.rst中修改。
修改后./make clean ,然后生成./make html。

9. 若不想显示某些module下的文件文档,可在source目录下删除对应.rst文件即可。
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/878917.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号