summaryrefslogtreecommitdiff
path: root/sphinx/ext/autodoc.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2014-01-19 10:31:15 +0100
committerGeorg Brandl <georg@python.org>2014-01-19 10:31:15 +0100
commit91cd11be3cc9e4eea53a664df722bf60d2f7418b (patch)
treebfa7571ce91ca4a5176bbef8cc3f8384469c6f32 /sphinx/ext/autodoc.py
parent37b604e4cccceab0384bbeebdc659b6817cad70e (diff)
parenta8f65e9d3c8b3ffb16b0ad5004b420a60d1c6a60 (diff)
downloadsphinx-git-91cd11be3cc9e4eea53a664df722bf60d2f7418b.tar.gz
Merged in guibog/sphinx2 (pull request #184)
autodoc extension: add autodoc_mock_imports config value
Diffstat (limited to 'sphinx/ext/autodoc.py')
-rw-r--r--sphinx/ext/autodoc.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py
index 571f36cbe..6c13e2432 100644
--- a/sphinx/ext/autodoc.py
+++ b/sphinx/ext/autodoc.py
@@ -70,6 +70,26 @@ class Options(dict):
return None
+class _MockModule(object):
+ def __init__(self, *args, **kwargs):
+ pass
+
+ def __call__(self, *args, **kwargs):
+ return _MockModule()
+
+ @classmethod
+ def __getattr__(cls, name):
+ if name in ('__file__', '__path__'):
+ return '/dev/null'
+ elif name[0] == name[0].upper():
+ # Not very good, we assume Uppercase names are classes...
+ mocktype = type(name, (), {})
+ mocktype.__module__ = __name__
+ return mocktype
+ else:
+ return _MockModule()
+
+
ALL = object()
INSTANCEATTR = object()
@@ -332,6 +352,8 @@ class Documenter(object):
self.modname, '.'.join(self.objpath))
try:
dbg('[autodoc] import %s', self.modname)
+ for modname in self.env.config.autodoc_mock_imports:
+ self._mock_import(modname)
__import__(self.modname)
parent = None
obj = self.module = sys.modules[self.modname]
@@ -361,6 +383,15 @@ class Documenter(object):
self.env.note_reread()
return False
+ def _mock_import(self, modname):
+ if '.' in modname:
+ pkg, _n, mods = modname.rpartition('.')
+ self._mock_import(pkg)
+ mod = _MockModule()
+ sys.modules[modname] = mod
+ return mod
+
+
def get_real_modname(self):
"""Get the real module name of an object to document.
@@ -1453,6 +1484,7 @@ def setup(app):
app.add_config_value('autodoc_member_order', 'alphabetic', True)
app.add_config_value('autodoc_default_flags', [], True)
app.add_config_value('autodoc_docstring_signature', True, True)
+ app.add_config_value('autodoc_mock_imports', [], True)
app.add_event('autodoc-process-docstring')
app.add_event('autodoc-process-signature')
app.add_event('autodoc-skip-member')