似乎有太多的Python文档工具.我碰到的另一个是epydoc.似乎Sphinx是事实上的标准,因为它用于生成官方Python文档.有人可以帮我理清Python文档工具的当前状态吗?
我刚开始使用Sphinx工具为我的代码生成文档.但我有点困惑,因为它并不像我预期的那么容易.我使用以下方法创建Sphinx文档:
sphinx-quickstart
Run Code Online (Sandbox Code Playgroud)
然后我将我的*.rst文件创建到"source"文件夹中.好像我需要为我想要为其创建文档的每个模块创建一个*.rst文件.对于test.py,我创建了test.rst.在test.rst中,我有:
.. automodule:: test
:members:
:show-inheritance:
Run Code Online (Sandbox Code Playgroud)
然后在test.py里面,我有:
"""
.. module:: test
:platform: Unix, Windows
:synopsis: A useful module indeed.
"""
Run Code Online (Sandbox Code Playgroud)
然后我使用以下方法生成文档:
sphinx-build -b html source/ build/
Run Code Online (Sandbox Code Playgroud)
一切都按预期工作,但问题是它并不像我预期的那么容易.我想必须有一个更简单的方法来跳过其中的一些步骤.我想知道是否有任何方法可以为包内的所有模块生成文档,而不是为每个模块生成*.rst文件.
谢谢.
我正在尝试在sphinx中为我的项目编写文档,每当sphinx在我的模块中遇到OptionParser时,它就会给我:
sphinx-build: error: no such option: -b
Run Code Online (Sandbox Code Playgroud)
我认为这是不可能的,所以我写了一个简单的模块来检查:
from optparse import OptionParser
"""some comment here"""
parser = OptionParser(conflict_handler='resolve')
parser.add_option('', '--force', action='store_true', dest='force', default=False, help='gqdel will skip asking questions, and delete them all.');
parser.add_option('', '--verbose', action='store_true', dest='verbose', default=False, help='Report additional information from gqdel')
(options, args) = parser.parse_args()
"""and here"""
print "foo"
Run Code Online (Sandbox Code Playgroud)
它给了我同样的错误.我的第一个看起来像这样:
some title
==========
.. automodule:: test
:members:
Run Code Online (Sandbox Code Playgroud) 我正在使用 PyCharm 处理 Python 项目,现在我需要生成相应的 API 文档。我正在使用docstrings. 我读过关于 Sphinx 和 Doxygen 的文章,Sphinx 是目前最受推荐的。我试图配置 Sphinx whitin PyCharm,但我没有让它工作。
这是项目结构:
这是与命令Sphinx Quickstart的 I/O 交互
C:\Python\Python36\Scripts\sphinx-quickstart.exe
Welcome to the Sphinx 1.6.3 quickstart utility.
Please enter values for the following settings (just press Enter to
accept a default value, if one is given in brackets).
Enter the root path for documentation.
> Root path for the documentation [.]:
You have two options for placing the build directory for Sphinx …Run Code Online (Sandbox Code Playgroud) 方案如下。有一个名为foo(正在大力开发的 API,处于第一个 alpha 阶段)的包,其rst文件是使用sphinx-apidoc.
为了在foo生成这些文件后有更好的文档,需要进行一些编辑。比如说,foo.bar.rst在生成的内容中添加了一些段落sphinx-apidoc
sphinx-apidoc当进行新的呼叫时,如何才能不丢失所有这些信息?当然,我希望反映 API 中的潜在更改,并保留添加的手动信息。