sphinx/doc/ext
Robin Jarry ececc4dcfe ext: enhance autodoc_mock_imports
The autodoc_mock_imports option requires to explicitly declare *every*
external module and sub-module that are imported by the documented code.
This is not practical as the list can become very large and must be
maintained as the code changes.

Also, the mocking is minimal which causes errors when compiling the
docs. For example, if you declare:

    autodoc_mock_imports = ['django.template']

And try to document a module:

    .. automodule:: my.lib.util

Which contains this code:

    from django.template import Library
    register = Library()

The following error occurs:

    File ".../my/lib/util.py" line 2
        register = Library()
    TypeError: 'object' object is not callable

Other similar errors can occur such as "TypeError: 'object' object has
no len".

To address these limitations, only require to declare the top-level
module that should be mocked:

    autodoc_mock_imports = ['django']

Will mock "django" but also any sub-module: "django.template",
"django.contrib", etc.

Also, make the mocked modules yield more complete dummy objects to avoid
these TypeError problems.

Behind the scenes, it uses the python import hooks mechanism specified
in PEP 302.

Signed-off-by: Robin Jarry <robin@jarry.cc>
2017-04-18 17:08:17 +02:00
..
autodoc.rst ext: enhance autodoc_mock_imports 2017-04-18 17:08:17 +02:00
autosectionlabel.rst Added autosectionlabel_prefix_document config option. 2017-04-17 14:51:39 +02:00
autosummary.rst BUG: Fix autosummary of members with a trailing underscore 2017-03-26 12:54:03 +01:00
builtins.rst Fix document for Kindle and add description about kindlegen 2016-09-01 12:46:12 +09:00
coverage.rst Add an option for the coverage builder if source-undocumented items are matched. 2011-01-04 22:50:13 +01:00
doctest.rst From version 1.5 to 1.6. Warnings wrapped with locale. 2017-01-26 11:20:24 +01:00
example_google.py fix style check warnings 2017-03-03 22:03:16 +09:00
example_google.rst fix document download roles. download roles works only on html. 2016-07-19 23:15:35 +09:00
example_numpy.py fix style check warnings 2017-03-03 22:03:16 +09:00
example_numpy.rst fix document download roles. download roles works only on html. 2016-07-19 23:15:35 +09:00
extlinks.rst fix http/https 2015-02-28 01:02:41 +09:00
githubpages.rst Add sphinx.ext.githubpages to publish the docs on GitHub Pages 2016-01-06 22:14:57 +09:00
graphviz.rst Drop deprecated options for graphviz extension 2017-01-05 13:52:17 +09:00
ifconfig.rst fix obsoleted documentation 2015-07-25 15:55:43 +02:00
inheritance.rst Fix style checks 2016-07-07 16:48:12 +03:00
intersphinx.rst Fix #2474: Add `intersphinx_timeout option to sphinx.ext.intersphinx` 2016-09-01 23:00:31 +09:00
linkcode.rst rewrapping paragraphs when over 80 characters wide 2014-06-18 11:53:25 -04:00
math.rst Fixup links in the documentation. 2016-02-13 16:00:46 +01:00
napoleon.rst [Napoleon] Removes Python 2/3 compatible type annotation doc example, because they aren't current supported by Sphinx 2016-07-02 11:43:55 -04:00
thirdparty.rst Fix document for Kindle and add description about kindlegen 2016-09-01 12:46:12 +09:00
todo.rst #2680: sphinx.ext.todo now emits warnings if todo_emit_warnings enabled 2016-07-16 00:59:02 +09:00
viewcode.rst Turn off viewcode extension by default 2016-07-28 15:38:38 +09:00