sphinx-autogen

提要

sphinx-autogen [选项] <源文件> …

描述

sphinx-autogen 是一个工具,用于自动生成 Sphinx 源文件,这些源文件使用 autodoc 扩展,记录 autosummary 列表中的项目。

源文件 是一个或多个包含设置了 :toctree: 选项的 autosummary 条目的 reStructuredText 文档的路径。源文件 可以是 fnmatch 风格的模式。

选项

-o <输出目录>

放置输出文件的目录。如果不存在,则创建。默认为传递给 :toctree: 选项的值。

-s <后缀>, --suffix <后缀>

生成文件使用的默认后缀。默认为 rst

-t <模板>, --templates <模板>

自定义模板目录。默认为 None

-i, --imported-members

记录导入的成员。

-a, --respect-module-all

精确地记录模块 __all__ 属性中的成员。

--remove-old

删除输出目录中不再生成的现有文件。

示例

给定以下目录结构

docs
├── index.rst
└── ...
foobar
├── foo
│   └── __init__.py
└── bar
    ├── __init__.py
    └── baz
        └── __init__.py

并假设 docs/index.rst 包含以下内容

Modules
=======

.. autosummary::
   :toctree: modules

   foobar.foo
   foobar.bar
   foobar.bar.baz

如果您运行以下命令

$ PYTHONPATH=. sphinx-autogen docs/index.rst

那么将在 docs 中创建以下存根文件

docs
├── index.rst
└── modules
    ├── foobar.bar.rst
    ├── foobar.bar.baz.rst
    └── foobar.foo.rst

并且每个文件都将包含 autodoc 指令和其他一些信息。

另请参阅

sphinx-build(1), sphinx-apidoc(1)