这篇简短的博客文章似乎展示了一种为单个模块生成自动 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