Python Sphinx将NumPy模块的文档添加到我的文档中

Python Sphinx将NumPy模块的文档添加到我的文档中,python,python-sphinx,Python,Python Sphinx,我想为我的Python代码生成Sphinx文档。此代码从numpy进行一些导入。我在mycode上使用sphinxapidoc,然后运行makehtml。它生成文档,但也包括来自numpy的uniform函数的文档。如何禁用此类冗余包含 这是我的密码: # encoding: utf-8 """ This module does blah blah. """ from numpy.random import uniform #WHY IS IT INCLUDED IN SPHINX DOC?

我想为我的Python代码生成Sphinx文档。此代码从
numpy
进行一些导入。我在mycode上使用
sphinxapidoc
,然后运行
makehtml
。它生成文档,但也包括来自
numpy
uniform
函数的文档。如何禁用此类冗余包含

这是我的密码:

# encoding: utf-8
"""
This module does blah blah.
"""

from numpy.random import uniform  #WHY IS IT INCLUDED IN SPHINX DOC?!!!!

class UberMegaClass(object):
    """Hell yeah!"""
    def __init__(self, num_of_something):
        print("---")
        self.num_of_something = num_of_something

一种方法是改变你的rst

 .. automodule:: module

 .. autoclass:: module.UberMegaClass
     :members:
     :undoc-members:
     :show-inheritance:
这将产生:

This module does blah blah.

class module.UberMegaClass(num_of_something)
    Bases: object

    Hell yeah!

这是狮身人面像处理C++扩展的一个已知错误;他们可能是 不必要地包含在文档中。有一个半官方的 建议您使用

Mock
对象替换这些模块 在您的
conf.py
中,如下所示:

import sys

class Mock(object):

    __all__ = []

    def __init__(self, *args, **kwargs):
        pass

    def __call__(self, *args, **kwargs):
        return Mock()

    @classmethod
    def __getattr__(cls, name):
        if name in ('__file__', '__path__'):
            return '/dev/null'
        elif name[0] == name[0].upper():
            mockType = type(name, (), {})
            mockType.__module__ = __name__
            return mockType
        else:
            return Mock()

MOCK_MODULES = ['pygtk', 'gtk', 'gobject', 'argparse',
                'numpy', 'numpy.random']
for mod_name in MOCK_MODULES:
    sys.modules[mod_name] = Mock()

谢谢你的回复,但我已经找到了一个不修改RST的解决方案。解决方案是在导致错误的C++扩展中生成<代码>模拟<代码>。这是: