我正在开发一个只有一个 .py 模块的 Python 库,我正在尝试从文档字符串为其生成文档。我设置了 Sphinx 并运行了 spinx-quickstart 脚本,但是当我尝试运行时(在 docs 目录中)
sphinx-apidoc ../cffiwrap.py -o .
但它只是说:
../cffiwrap.py is not a directory.
是否有其他一些 Sphinx 脚本来自动记录单个文件?我考虑过只针对 ..
运行它,但后来我认为它会运行到我的测试目录并尝试从我的单元测试生成文档...
最佳答案
这个短blog post似乎显示了另一种为单个模块生成自动 api 文档的方法。为了方便和持久性复制在这里:
放置conf.py
文件在与您的模块相同的目录中:
import os
import sys
# enable autodoc to load local modules
sys.path.insert(0, os.path.abspath("."))
project = "<project>"
copyright = "year, author"
author = "author"
extensions = ["sphinx.ext.autodoc", "sphinx.ext.intersphinx"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
templates_path = ["_templates"]
html_theme = "alabaster"
html_static_path = ["_static"]
intersphinx_mapping = {
"python": ("https://docs.python.org/3", None)
}
html_theme_options = {"nosidebar": True}
添加这个index.rst
旁边
<project>
=========
.. automodule:: <project>
:members:
最后,替换<project>
用你的模块名称,pip install sphinx
并运行:
sphinx-build -b html . _build
关于Python:在单个模块上使用 Sphinx 生成 autodoc?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18702857/