我开始研究 python 模块,并希望“就地”记录代码。所以我在一个带有 sphinx-quickstart 的子目录中设置了 sphinx,导致了这个目录结构(只显示了我编辑的文件):
- 我的项目/
- __初始化__.py
- 主要文件
- docs/(斯芬克斯目录)
- 构建/
- 来源/
- 配置文件
- index.rst
- setup.py
我的 index.rst 包含:
Welcome to My Module's documentation!
=====================================
.. toctree::
:maxdepth: 2
:caption: Contents:
.. automodule:: myproject
:members:
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
当我运行时
make html
我得到的文档缺少自动模块部分,尽管我在 main.py 中记录了每个类和每个方法,如下所示:
class Thing:
"""This class represents Things
:param color: how the thing should look like
"""
def __init__(self, color):
pass
def color(self):
"""Tells you the color of the thing.
:returns: Color string
:rtype: str or unicode
"""
pass
Sys.path 也设置正确,因为它现在在制作时抛出错误
sys.path.insert(0, os.path.abspath('../../'))
如果相关,我还包括 setup.py:
from setuptools import setup
setup(name='My Module',
version='0.1',
description='Internet of Things',
url='https://example.com',
author='Master Yoda',
author_email='yoda@example.com',
license='GPLv3',
packages=['mymodule'],
zip_safe=False)
我可以更改什么以使 autodoc 正常工作?
最佳答案
如果你的类导入到 __init__.py
你可能还需要 :imported-members:
像这样:
.. automodule:: myproject
:imported-members:
:members:
:undoc-members:
:show-inheritance:
关于python - 为什么 sphinx automodule 不显示任何模块成员?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55051112/