【发布时间】:2021-07-20 03:03:28
【问题描述】:
我以前在这里看到过这个问题,例如here,或here,或最有用的here。但我相信我的问题与他们的不同,或者我做错了什么。
我的python文件hello_world是:
import numpy as np
"""
This is the header
"""
def say_hi(name):
"""
This is just a test
:param param1: this is the name
:returns returns the name entered
"""
print(name)
return None
我创建了一个文件夹docs,并在其中运行sphinx-quickstart。我得到了conf.py 和index.rst,我将它们更改为:
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath('..'))
# -- Project information -----------------------------------------------------
project = 'project'
copyright = '2021, lol'
author = 'lol'
# The full version, including alpha/beta/rc tags
release = '0.0.1'
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
所以,我告诉 sphinx 寻找什么路径。如this 教程中所示,我将modules 添加到index.rst。因此,该文件如下所示:
.. project documentation master file, created by
sphinx-quickstart on Mon Jul 19 21:46:14 2021.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to project's documentation!
===================================
.. toctree::
:maxdepth: 2
:caption: Contents:
modules
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
然后,我运行sphinx-apidoc -o . ..,最后运行make html。
该过程会生成一个 html 文件,但它没有任何文档 image
有谁知道如何解决这个问题?或者有人知道一个真正有效的教程吗?谢谢!
编辑*
Sphinx 在运行 make html: WARNING: Unknown directive type "automodule" 时会输出警告。我用谷歌搜索并找到了这个 https://cloud.tencent.com/developer/ask/111346 。将extensions = ['sphinx.ext.autodoc'] 包含到 index.rst 文件后,它会输出:
虽然我的格式似乎有问题,但这是一个不同的问题。
【问题讨论】:
-
Sphinx 是否输出任何错误或警告信息? hello_world.py 到底在项目中的什么位置? modules.rst 的内容是什么?请确保您提供minimal reproducible example。
-
尝试
make clean然后构建。您可能有页面的缓存版本。 -
我编辑了这个问题。我注意了警告,现在它似乎正在工作(我很愚蠢,只是忽略了警告)。文档的格式不正确,但这是另一个问题。谢谢!
-
如果问题得到解决,请将解决方案作为答案发布。不要将解决方案放在问题中。
extensions = ['sphinx.ext.autodoc']进入 conf.py,而不是 index.rst。
标签: python python-sphinx autodoc