使用sphinx自动化记录python类和模块

2024-05-13 11:38:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经安装了Sphinx,以便记录一些我正在处理的python模块和类。虽然标记语言看起来很不错,但我还没有成功地自动记录python代码。

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

SegLib.py

其中还有一个名为Seg的类。我想在生成的sphinx文档中显示类和模块的docstrings,并向其中添加进一步的格式化文本。

我的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只是用粗体打印,没有链接到类的自动生成文档。

正在尝试: 参见:类:Seg 模块:mod:'SegLib' 模块:mod:'SegLib.py'

也帮不上忙。 有什么想法或好的指导链接吗?

编辑:将SegLib更改为segments(谢谢,iElectric!),并将第1.rst章更改为: :mod:segments模块 --------------------------

.. 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"

你知道如何用一个简短的命令自动记录函数和类吗?

Udi公司


Tags: 模块函数text文档pymodsphinx记录