为什么 sphinx 自动模块不显示任何模块成员?

lal*_*alu 9 python module python-sphinx autodoc

我开始研究一个 python 模块,并希望“就地”记录代码。因此,我使用 sphinx-quickstart 在子目录中设置了 sphinx,从而生成了此目录结构(仅显示了我编辑的文件):

  • 我的项目/
    • __init__.py
    • 主文件
  • docs/(狮身人面像目录)
    • 建造/
    • 来源/
      • 配置文件
      • 索引.rst
  • 设置文件

我的 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`
Run Code Online (Sandbox Code Playgroud)

当我跑

make html
Run Code Online (Sandbox Code Playgroud)

我得到了一个缺少自动模块部分的文档,尽管我记录了 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
Run Code Online (Sandbox Code Playgroud)

Sys.path 也设置正确,因为它现在在制作时抛出错误

sys.path.insert(0, os.path.abspath('../../'))
Run Code Online (Sandbox Code Playgroud)

如果相关,我还包括 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)
Run Code Online (Sandbox Code Playgroud)

我可以更改什么才能使 autodoc 工作?

spa*_*her 9

如果您的课程被导入,__init__.py您可能还需要:imported-members:像这样:

.. automodule:: myproject
   :imported-members:
   :members:
   :undoc-members:
   :show-inheritance:
Run Code Online (Sandbox Code Playgroud)


mzj*_*zjn 5

main模块在myproject包中。为了记录main,您需要以下内容:

.. automodule:: myproject.main
   :members:
Run Code Online (Sandbox Code Playgroud)