我正在开发一个只有一个.py模块的Python库,我正在尝试从docstrings为它生成文档。我已经设置了Sphinx并运行了spinx-quickstart脚本,但是当我尝试运行时(在docs目录中)
sphinx-apidoc ../cffiwrap.py -o .
但它只是说:
../cffiwrap.py is not a directory.
是否有其他Sphinx脚本可以自动修改单个文件?我想过只针对..
运行它,但后来我发现它会运行到我的tests目录并尝试从我的单元测试中生成文档......
答案 0 :(得分:0)
手册说:
sphinx-apidoc [options] -o packagedir [pathnames ...]
其中路径名是要排除的目录。
所以试试:
sphinx-apidoc -o . .. ../test_dir
其中test_dir
是您的测试所在的位置。
答案 1 :(得分:0)
简短的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