繁体   English   中英

使用 sphinx 自动记录 python 类、模块

[英]Using sphinx to auto-document a python class, module

我安装了Sphinx以记录我正在处理的一些 Python 模块和类。 虽然标记语言看起来非常好,但我还没有设法自动记录 Python 代码。

基本上,我有以下 Python 模块:

SegLib.py

还有一个叫做Seg的类。 我想在生成的 Sphinx 文档中显示类和模块的文档字符串,并向其中添加进一步格式化的文本。

我的index.rst看起来像这样:

Contents:

.. toctree::
:maxdepth: 2

chapter1.rst

chapter1.rst

This is a header
================
Some text, *italic text*, **bold text**

* bulleted list.  There needs to be a space right after the "*"
* item 2

.. note::
   This is a note.

See :class:`Seg`

但是Seg只是以粗体打印,并没有链接到该类的自动生成文档。

尝试以下方法也无济于事:

See :class:`Seg`
Module :mod:'SegLib'
Module :mod:'SegLib.py'

编辑:将 SegLib 更改为段(感谢 iElectric)。 并将 chapter1:rst 更改为:

The :mod:`segments` Module
--------------------------

.. automodule:: segments.segments

.. autoclass:: segments.segments.Seg

尽管如此,仍然无法让 Sphinx 直接记录类中的函数,或者更好的是 - 自动将类中的所有函数添加到文档中。 试过:

.. autofunction:: segments.segments.Seg.sid

并得到:

 autodoc can't import/find function 'segments.segments.Seg.sid', it reported error: "No module named Seg"

关于如何使用简短命令自动记录函数和类的任何想法?

在文件开头添加:

.. module:: SegLib

尝试对类文档使用:autoclass:指令。

顺便说一句:模块名称应该是小写的。

编辑:我从阅读其他源文件中学到了很多东西

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM