如何从文档字符串生成用于功能代码的 API 文档



我想要的只是从源代码中的函数文档字符串生成API文档,大概是通过sphinx的autodoc扩展,以构成我的精益API文档。我的代码遵循函数式编程范式,而不是 OOP,如下所示。

作为第二步,我可能会为项目添加一个或多个文档页面,托管介绍性注释、代码示例(我猜利用doctest(等内容,当然还有链接到 API 文档本身。

从这里的文档字符串完成文档的简单流程是什么?狮身人面像是一个非常流行的工具,但我发现它的入门页面有点密集。

我尝试过什么,在我的源目录中:

$ mkdir documentation
$ sphinx-apidoc -f --ext-autodoc -o documentation .

没有错误消息,但这在我的源文件中找不到(或处理(文档字符串;它只是为每个源创建一个 rst 文件,内容如下:

tokenizer module
================
.. automodule:: tokenizer
:members:
:undoc-members:
:show-inheritance:

基本上,我的源文件如下所示,其中没有太多的模块仪式或面向对象的内容(我喜欢函数式编程,即使这次是python(。当然,我已经截断了下面的示例源文件,它包含下面未显示的更多函数。

tokenizer.py

from hltk.util import clean, safe_get, safe_same_char
"""
Basic tokenization for text
not supported:
+ forms of pseuod elipsis (...)

support for the above should be added only as part of an automata rewrite
"""
always_swallow_separators = u" tnvfru200e"
always_separators = ",!?()[]{}:;"
def is_one_of(char, chars):
'''
Returns whether the input `char` is any of the characters of the string `chars`
'''
return chars.count(char)

或者您会为此用例推荐不同的工具和流程吗?

非常感谢!

如果您发现狮身人面像太麻烦且特别不适合用于简单的项目,请尝试 pdoc:

$ pdoc --html tokenizer.py

最新更新