【问题标题】:How to document Python packages using Sphinx如何使用 Sphinx 记录 Python 包
【发布时间】:2014-08-28 12:53:43
【问题描述】:

我正在尝试用 Python 记录一个包。目前我有以下目录结构:

.
└── project
    ├── _build
    │   ├── doctrees
    │   └── html
    │       ├── _sources
    │       └── _static
    ├── conf.py
    ├── index.rst
    ├── __init__.py
    ├── make.bat
    ├── Makefile
    ├── mod1
    │   ├── foo.py
    │   └── __init__.py
    ├── mod2
    │   ├── bar.py
    │   └── __init__.py
    ├── _static
    └── _templates

这棵树是sphinx-quickstart 触发的结果。在conf.py 中,我取消了sys.path.insert(0, os.path.abspath('.')) 的注释,而我有extensions = ['sphinx.ext.autodoc']

我的index.rst 是:

.. FooBar documentation master file, created by
   sphinx-quickstart on Thu Aug 28 14:22:57 2014.
   You can adapt this file completely to your liking, but it should at least
   contain the root `toctree` directive.

Welcome to FooBar's documentation!
==================================

Contents:

.. toctree::
   :maxdepth: 2

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

在所有__init__.py 中,我都有一个文档字符串,模块foo.pybar.py 也是如此。但是,在项目中运行 make html 时,我看不到任何文档。

【问题讨论】:

标签: python package python-sphinx sphinx-apidoc


【解决方案1】:

这是一个大纲:

  1. 使用源中的文档字符串记录您的包。
  2. 使用 sphinx-quickstart 创建一个 Sphinx 项目。
  3. 运行sphinx-apidoc 以生成设置为与autodoc 一起使用的.rst 源。更多信息here

    将此命令与-F 标志一起使用还可以创建一个完整的Sphinx 项目。如果您的 API 变化很大,您可能需要多次重新运行此命令。

  4. 使用 sphinx-build 构建文档。

注意事项:

【讨论】:

  • 我应该在哪里运行sphinx-apidoc?如何处理生成的 .rst 文件?把它们放在哪里?使用-Fspinx-quickstart 有何不同?
  • @minerals。 我应该在哪里运行 sphinx-apidoc? “在哪里”是什么意思?问题是什么? 如何处理生成的 .rst 文件?把它们放在哪里? 你把它们放在方便的地方。然后你在他们身上运行sphinx-build
  • @minerals。 使用 -F 与 spinx-quickstart 有何不同? 如果您运行sphinx-apidoc -F,实际上您可以一次性运行sphinx-quickstartsphinx-apidoc。这只是另一种方式。
  • @minerals。关于sphinx-apidoc:我在回答中链接到sphinx-doc.org/man/sphinx-apidoc.html。该页面上是否有不清楚的地方?另请注意,如果您有稳定的 API,则无需一遍又一遍地运行 sphinx-apidoc。见stackoverflow.com/q/28481471/407651
猜你喜欢
  • 1970-01-01
  • 2016-07-24
  • 2018-07-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-04
相关资源
最近更新 更多