python - 为什么 sphinx automodule 不显示任何模块成员?

标签 python module python-sphinx autodoc

我开始研究 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/

相关文章:

python-sphinx - 如何使用 sphinx 分配案例的标签中心?

python - 使用 Python 将 Access 应用程序从 MDB (2000) 转换为 ACCDB (2007/2010)

Python 导入错误 - NUMPY MKL

c# - PRISM:一个区域中的嵌套区域

ruby-on-rails - 如何从复杂的模块(paypal_permissions gem)中包含类?

latex - Sphinx latexpdf 忽略文件的一部分

python - PyQt5:QWebEngineView 中的鼠标点击和源代码

python - 如何在从 Tornado 流式传输视频时减少阻塞

linux - 如何从 proc 文件中读取大数据?

python - Sphinx 生成的文档中模块属性值的省略/截断