Skip to content

Commit

Permalink
debugging docs for RTD
Browse files Browse the repository at this point in the history
  • Loading branch information
jonrkarr committed Mar 19, 2018
1 parent 1277e40 commit 2c5ac90
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 55 deletions.
56 changes: 4 additions & 52 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
'sphinx.ext.mathjax',
'sphinx.ext.napoleon',
'sphinx.ext.todo',
'sphinxcontrib.addmetahtml',
'sphinxcontrib.bibtex',
'sphinxcontrib.googleanalytics',
'sphinxcontrib.spelling',
Expand Down Expand Up @@ -403,56 +404,7 @@ def linkcode_resolve(domain, info):
googleanalytics_id = 'UA-86340737-1'


# -- Run sphinx-apidoc within ReadTheDocs on sphinx-build -----------------

from six.moves.configparser import ConfigParser
from sphinx.ext import apidoc

def run_apidoc(app):
this_dir = os.path.dirname(__file__)
parser = ConfigParser()
parser.read(os.path.join(this_dir, '..', 'setup.cfg'))
packages = parser.get('sphinx-apidocs', 'packages').strip().split('\n')
for package in packages:
apidoc.main(argv=['-f', '-P', '-o', os.path.join(this_dir, 'source'), os.path.join(this_dir, '..', package)])


# -- mock the import of modules that are not installed -------------------
import importlib
import mock
import pip_check_reqs.common
import six

# find packages
parent_dir = os.path.join(os.path.dirname(__file__), '..')
parser = ConfigParser()
parser.read(os.path.join(parent_dir, 'setup.cfg'))
packages = parser.get('sphinx-apidocs', 'packages').strip().split('\n')

# find imported modules
options = mock.Mock()
options.paths = [os.path.join(parent_dir, p) for p in packages]
options.ignore_files = pip_check_reqs.common.ignorer([])
options.ignore_mods = pip_check_reqs.common.ignorer([])
import_mods = pip_check_reqs.common.find_imported_modules(options)

# mock non-installed modules
class ModuleMock(mock.MagicMock):
@classmethod
def __getattr__(cls, name):
return ModuleMock()
for import_mod in import_mods.keys():
if six.PY2:
import imp
installed = imp.find_module(import_mod.partition('.')[0]) is not None
else:
import importlib
installed = importlib.util.find_spec(import_mod) is not None

if not installed:
sys.modules.update((import_mod, ModuleMock()))

# -- if RTD, redirect to https://docs.karrlab.org ------------------------

# -- trigger API doc generation with docs compilation --------------------
def setup(app):
app.connect('builder-inited', run_apidoc)
addmetahtml_content = '<meta http-equiv="refresh" content="0; url=https://docs.karrlab.org/unitth" />'
addmetahtml_enabled = os.getenv('READTHEDOCS', '') == 'True'
4 changes: 1 addition & 3 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
mock
pip_check_reqs
robpol86_sphinxcontrib_googleanalytics
six
sphinx >= 1.7
sphinx_rtd_theme
sphinxcontrib_addmetahtml
sphinxcontrib_bibtex
sphinxcontrib_spelling

0 comments on commit 2c5ac90

Please sign in to comment.