我想为我的Python代码生成Sphinx文档。此代码从numpy
进行一些导入。我在mycode上使用sphinx-apidoc
,然后运行make html
。它会生成文档,但也包含uniform
中numpy
函数的文档。如何禁用这种多余的包含物?
这是我的代码:
# 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
答案 0 :(得分:1)
这是Sphinx处理C ++扩展时的一个已知错误;他们可以
不必要地包含在文档中。有一个半官员
workaround建议您使用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()
答案 1 :(得分:0)
解决这个问题的方法之一就是改变你的第一个。
.. 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!