Commit 67167830 by Julian Arni

Fix import mocks.

    Prevents sphinx from bailing on builds that involve unavailable imports.
parent 0bbd80fe
...@@ -26,7 +26,7 @@ html_static_path.append('source/_static') ...@@ -26,7 +26,7 @@ html_static_path.append('source/_static')
# If extensions (or modules to document with autodoc) are in another directory, # If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the # add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here. # documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('../../..')) sys.path.insert(0, os.path.abspath('../../..'))
root = os.path.abspath('../../..') root = os.path.abspath('../../..')
sys.path.append(root) sys.path.append(root)
...@@ -64,6 +64,45 @@ exclude_patterns = ['build'] ...@@ -64,6 +64,45 @@ exclude_patterns = ['build']
# Output file base name for HTML help builder. # Output file base name for HTML help builder.
htmlhelp_basename = 'edXDocs' htmlhelp_basename = 'edXDocs'
# --- Mock modules ------------------------------------------------------------
# Mock all the modules that the readthedocs build can't import
import mock
class Mock(object):
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()
# The list of modules and submodules that we know give RTD trouble.
# Make sure you've tried including the relevant package in
# docs/share/requirements.txt before adding to this list.
MOCK_MODULES = [
'numpy',
'matplotlib',
'matplotlib.pyplot',
'scipy.interpolate',
'scipy.constants',
'scipy.optimize',
]
for mod_name in MOCK_MODULES:
sys.modules[mod_name] = Mock()
# -----------------------------------------------------------------------------
# from http://djangosnippets.org/snippets/2533/ # from http://djangosnippets.org/snippets/2533/
# autogenerate models definitions # autogenerate models definitions
...@@ -109,27 +148,7 @@ def strip_tags(html): ...@@ -109,27 +148,7 @@ def strip_tags(html):
s.feed(html) s.feed(html)
return s.get_data() return s.get_data()
class Mock(object):
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 = ['scipy', 'numpy']
for mod_name in MOCK_MODULES:
sys.modules[mod_name] = Mock()
def process_docstring(app, what, name, obj, options, lines): def process_docstring(app, what, name, obj, options, lines):
"""Autodoc django models""" """Autodoc django models"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment