为什么 sphinx automodule 不显示任何模块成员?
Why is sphinx automodule not showing any module members?
我开始研究 python 模块并想记录代码 "in place"。所以我在一个带有 sphinx-quickstart 的子目录中设置了 sphinx,导致了这个目录结构(只显示了我编辑的文件):
- 我的项目/
- __init__.py
- main.py
- docs/(斯芬克斯目录)
- 构建/
- 来源/
- conf.py
- 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
我得到的文档缺少自动模块部分,尽管我记录了每个 class 和 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 正常工作?
main
模块在 myproject
包中。为了记录 main
,您需要以下内容:
.. automodule:: myproject.main
:members:
如果您的 class 被导入 __init__.py
,您可能还需要 :imported-members:
,如下所示:
.. automodule:: myproject
:imported-members:
:members:
:undoc-members:
:show-inheritance:
我开始研究 python 模块并想记录代码 "in place"。所以我在一个带有 sphinx-quickstart 的子目录中设置了 sphinx,导致了这个目录结构(只显示了我编辑的文件):
- 我的项目/
- __init__.py
- main.py
- docs/(斯芬克斯目录)
- 构建/
- 来源/
- conf.py
- 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
我得到的文档缺少自动模块部分,尽管我记录了每个 class 和 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 正常工作?
main
模块在 myproject
包中。为了记录 main
,您需要以下内容:
.. automodule:: myproject.main
:members:
如果您的 class 被导入 __init__.py
,您可能还需要 :imported-members:
,如下所示:
.. automodule:: myproject
:imported-members:
:members:
:undoc-members:
:show-inheritance: