我目前迁移所有现有的(不完全的)文档来斯芬克斯

的问题是,文档用途 Python的文档字符串(模块是用C,但它可能并不重要)和类文件必须转换成一个形式可用于斯芬克斯。

有是 sphinx.ext.autodoc ,但它会自动将当前文档字符串到文献。我要生成基于当前的文档字符串,它然后我可以编辑在( RST )源文件并手动提高。

您将如何转换成文档字符串为RST狮身人面像?

有帮助吗?

解决方案

在车博士不产生RST只存在把它弄出来的它没有正式的办法。最简单的黑客得到它是通过改变sphinx.ext.autodoc.Documenter.add_line方法发出我,它变得就行了。

由于所有我想要的是一个时间的迁移,并输出到stdout是配不上我:

def add_line(self, line, source, *lineno):
    """Append one line of generated reST to the output."""
    print self.indent + line
    self.directive.result.append(self.indent + line, source, *lineno)
产生

现在车博士打印RST在stdout运行时,你可以简单地重定向或复制到其他地方。

其他提示

猴子修补车博士因此它可以无需任何编辑:

import sphinx.ext.autodoc
rst = []
def add_line(self, line, source, *lineno):
    """Append one line of generated reST to the output."""
    rst.append(line)
    self.directive.result.append(self.indent + line, source, *lineno)
sphinx.ext.autodoc.Documenter.add_line = add_line
try:
    sphinx.main(['sphinx-build', '-b', 'html', '-d', '_build/doctrees', '.', '_build/html'])
except SystemExit:
    with file('doc.rst', 'w') as f:
        for line in rst:
            print >>f, line

据我所知没有自动化的工具来做到这一点。因此,我的方法将是写一个小脚本读取相关的模块(基于sphinc.ext.autodoc)并抛出文档字符串到一个文件(适当格式化的)。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top