geo*_*ika 9 python python-sphinx autodoc
我想在我的Sphinx文档中只包含特定函数的docstring.但是,使用http://sphinx.pocoo.org/ext/autodoc.html似乎没有选项只显示这些细节而没有相关的类和函数定义
我已经尝试在Sphinx文档中创建show*only*docstring中概述的类,但我不确定它是如何适应模板的.
我也尝试过autodoc-process-docstring事件处理程序而没有运气.
而不是我的文档显示(因为它是当前):
class module.MyClass(param)
This is the class doc string
my_method()
This is my method doc string
Run Code Online (Sandbox Code Playgroud)
我只是想显示:
This is my method doc string
Run Code Online (Sandbox Code Playgroud)
我在.txt文件中的当前模板是:
.. autoclass:: module.MyClass
:members: my_method
Run Code Online (Sandbox Code Playgroud)
geo*_*ika 14
在查看源代码并进行实验之后 - 这里是如何在Sphinx 1.1中完成的.
在conf.py文件中创建一个新的MethodDocumenter子类.在这里你可以设置一个新的"objtype",确保文档字符串没有缩进,并删除标题.
from sphinx.ext import autodoc
class SimpleDocumenter(autodoc.MethodDocumenter):
objtype = "simple"
#do not indent the content
content_indent = ""
#do not add a header to the docstring
def add_directive_header(self, sig):
pass
Run Code Online (Sandbox Code Playgroud)
然后确保使用以下函数将其添加到可用的文档中(再次在conf.py中):
def setup(app):
app.add_autodocumenter(SimpleDocumenter)
Run Code Online (Sandbox Code Playgroud)
然后,当您只想显示方法的文档字符串时,请在.txt或.rst文件中使用以下格式.只需在你的objname前加上auto.
.. autosimple:: mod.MyClass.my_method
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2346 次 |
| 最近记录: |