簡體   English   中英

Sphinx在我的文檔中添加了有關NumPy模塊的文檔

[英]Sphinx adds documentation for NumPy modules to my docs

我想為我的Python代碼生成Sphinx文檔。 此代碼從numpy進行了一些導入。 我在mycode上使用sphinx-apidoc ,然后運行make html 它生成文檔,但也包括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

這是Sphinx處理C ++擴展的一個已知錯誤。 它們可以不必要地包含在文檔中。 有一個半官方的解決方法,建議您用conf.py Mock對象替換這些模塊,如下所示:

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。

 .. 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!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM