Configuration

Project information

sophon.yml must contain following information.

code_dir

指定您Python项目所在的文件夹。


template_dir

存放Markdown模板的文件夹。 模板文件就是Markdown文件,只不还包含了一些形如{{tag_name}}的标记。更多详细用法请看tags


build_dir

生成的API文档所存放的文件夹。


repo_url

指定存放了源代码的仓库,可以在API文档中为每个API生成一个链接到源代码的超链接。


branch

指定源代码仓库上的分支。


style

指定您Python代码中docstring所使用的风格。


pages

pages是一个包含了0个或多个page的列表,包含了所有要生成的文档。更多详细用法请看page


page

page表示一个生成的API Markdown文档。格式为:

# filename: /home/user/sophon.yml
build_dir: api
template_dir: templates

pages:
- page: test/aa.md
  template: bb.md
- page: cc.md
  template: test/dd.md

tags

tags是一个包含了0个或多个tag的列表,也是page的成员。更多详细用法请看tag


tag

tag表示一个标记,通常结合模板文件来使用,表示生成的API Markdown text应该插入到模板文件的哪个地方。

举个例子,假设模板文件/home/user/templates/bb.md内容为:

# Hello World

{{tag0}}

## Hello Sophon

{{tag1}}

配置文件为:

# filename: /home/user/sophon.yml
build_dir: api
template_dir: templates

pages:
- page: test/aa.md
  template: bb.md
  tags:
  - tag: tag0
    functions:
    - mod.func
  - tag: tag1
    classes:
    - mod.clazz

则运行Sophon之后:

注意的是,以下几种情况中,该tag下包含的函数、类的API Markdown text会依次添加在文件末尾,而不是替换掉模板文件中的{{tag}}

每个tag所包含的API按照固定顺序classes->classes_with_members->functions依次生成API Markdown text。

另外,Sophon不会对存在于模板文件但是却没有在配置文件中指定的tag作任何处理,也就是一切以配置文件为准。


classes

classes是一个包含多个类的包路径的列表。

Sophon在生成一个类的API文档时,只会选择该类的docstring来生成该类构造函数的API Markdown text, 并不包括该类的成员函数与方法。


classes_with_methods

classes_with_methods是一个包含多个函数的包路径的列表。

Sophon在生成一个类的API文档时,会生成包括构造函数在内的该类所有公有成员函数与方法的API Markdown text。


functions

functions是一个包含多个函数的包路径的列表。