乐于分享
好东西不私藏

使用Sphinx构建软件说明书(2):配置文件

使用Sphinx构建软件说明书(2):配置文件

使用Sphinx构建软件说明书(2):配置文件

微信公众号:生信小知识
关注可了解更多的生物信息学教程及知识。问题或建议,请公众号留言;

目录

前言1. Sphinx配置2. 项目信息3. 一般配置项4. HTML输出选项后记

前言

我决定使用Sphinx对开发的软件包写一个说明书,这里记录我学习Sphinx的记录。

所有知识来源:

  • https://www.osgeo.cn/sphinx-note/intro.html
  • Sphinx 1.3.1 中文手册 (推荐查看)

已发布教程:

1. Sphinx配置

我们用 sphinx-quickstart 帮我生成了下面几个文件:

  • Makefile
  • build目录:空白
  • make.bat
  • source 目录
    • _static:用于存放图片之类的多媒体文件
    • _templates
    • conf.py:配置文件
    • index.rst:主页文件
$ tree
.
|-- Makefile
|-- README.md
|-- build
|-- make.bat
`-- source
    |-- _static
    |-- _templates
    |-- conf.py
    `-- index.rst

我们再看看配置文件具体长什么样:

# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

import sphinx_rtd_theme

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'Try Sphinx'
copyright = '2025, fatyang'
author = 'fatyang'
release = 'V1.0'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = []

templates_path = ['_templates']
exclude_patterns = []

language = 'zh_CN'

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
html_static_path = ['_static']

而根据前面的章节中,我们大概知道了对于生成的文档而言,主要的美化工作、格局配置等都依赖于配置文件。

这里我们就对Sphinx配置进行详细探索。

2. 项目信息

  1. project:项目名称
  2. author:该文件的作者姓名
  3. copyright:2020, Author Name 风格的版权声明
  4. version:主要项目版本, 用作 version 的替代
  5. release:完整的项目版本, 用作 release 的替代

详细信息可以查阅:https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

3. 一般配置项

  1. extensions:扩展,如若指定,需保证其已经被安装。

  2. source_suffix:源文件的文件扩展名, Sphinx将具有此后缀的文件视为源。

    source_suffix = {
    '.rst''restructuredtext',
    '.md''markdown',
    }
  3. source_encoding:所有 rst源文件的编码,推荐的编码和默认值是 ‘utf-8-sig’ 。

  4. master_doc:主目录文件名,默认为index

  5. exclude_patterns:查找源文件时应排除的glob样式模式列表。

  6. templates_path:包含额外模板的路径列表,使用相对路径(相对于配置目录)。

  7. rst_epilog:一串reStructuredText,它将添加到每个读取的源文件的末尾。例如:rst_epilog = "end"

  8. rst_prolog:一串reStructuredText,它将添加到每个读取的源文件的开头。例如:rst_epilog = "begin"

  9. suppress_warnings:用于禁止任意警告消息的警告类型列表。

  10. numfig:如果为 True,那么图片、表格和代码块如果有标题则会自动编号。

  11. numfig_format: 默认是将 ‘figure’ 映射为 Fig. %s,‘table’ 映射为 Table %s,‘code-block’ 映射为 Listing %s 和 ‘section’ 映射为 ‘Section’ 。

    numfig_format = {
    'code-block''Listing %s',
    'figure''Fig. %s',
    'section''Section',
    'table''Table %s',
    }
  12. numfig_secnum_depth:用于标注章节数字的位数

    • 设置为 0:编号类似1,2,3…
    • 设置为 1:编号类似x.1,x.2,x.3…  (x代表了章节数字)【默认模式】
    • 设置为 2:编号类似x.y.1,x.y.2,x.y.3…  (x代表了章节数字,y代表小节)
  13. show_authors:是否在构建的文件中展示作者,默认 False

  14. language:文档编写的语言,默认为 en

详细信息可以查阅:https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

4. HTML输出选项

  1. html_theme:页面主题模板,默认是 alabaster。自带的主题包括:basic, alabaster, sphinx_rtd_theme, classic, sphinxdoc, scrolls, agogo, traditional, nature, haiku, pyramid, bizstyle, epub
  2. html_theme_path:包含自定义主题的路径列表
  3. html_title:使用Sphinx内置模板生成的html页面的title。默认 project release documentation
  4. html_logo:文档徽标的路径,logo会被放在侧边栏的顶部,宽度不应超过200像素,使用相对路径(相对于配置目录)。默认值:None
  5. html_favicon:文档的favicon。它应该是一个Windows风格的图标文件(.ico),大小为16×16或32×32像素。默认值: None 。
  6. html_static_path:包含自定义静态文件的路径列表,使用相对路径(相对于配置目录)。
  7. html_show_copyright:在HTML Footer显示 “(C) Copyright …”, 默认True
  8. html_show_sphinx:在HTML Footer显示 “Created using Sphinx” ,”Built with Sphinx”,默认True
  9. html_output_encoding:HTML输出文件的编码。默认为 ‘utf-8’
  10. html_secnumber_suffix:章节编号的后缀(最后一个,与章节标题相连的部分),默认是 ”.“,比如 “2.1.1. 章节标题”

详细信息可以查阅:https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

后记

这里我们重点记录了一些构建文档网页时的配置设置,后面我们则进一步对构建过程中涉及到的文件和命令进行一定的探索~

本站文章均为手工撰写未经允许谢绝转载:夜雨聆风 » 使用Sphinx构建软件说明书(2):配置文件

评论 抢沙发

9 + 2 =
  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
×
订阅图标按钮