Browse code

add jupyter-sphinx to documentation config

Joseph Weston authored on 25/04/2019 15:41:23
Showing 2 changed files
... ...
@@ -241,7 +241,7 @@ build documentation:
241 241
   script:
242 242
     - pip install git+https://github.com/jupyter-widgets/jupyter-sphinx
243 243
     - python -m ipykernel install --user --name kwant-latest
244
-    - make -C doc realclean; make -C doc html SPHINXOPTS='-A website_deploy=True -n -W' SOURCE_LINK_TEMPLATE="$CI_PROJECT_URL"/blob/\$\$r/\$\$f
244
+    - make -C doc realclean; make -C doc html SPHINXOPTS='-A website_deploy=True -n -W -D jupyter_execute_default_kernel=kwant-latest' SOURCE_LINK_TEMPLATE="$CI_PROJECT_URL"/blob/\$\$r/\$\$f
245 245
   artifacts:
246 246
     paths:
247 247
       - doc/build/html/
... ...
@@ -255,7 +255,7 @@ build PDF documentation:
255 255
   script:
256 256
     - pip install git+https://github.com/jupyter-widgets/jupyter-sphinx
257 257
     - python -m ipykernel install --user --name kwant-latest
258
-    - make -C doc latex SPHINXOPTS='-n -W'
258
+    - make -C doc latex SPHINXOPTS='-n -W -D jupyter_execute_default_kernel=kwant-latest'
259 259
     - cd doc/build/latex
260 260
     - make all-pdf
261 261
   artifacts:
... ...
@@ -15,8 +15,15 @@ import sys
15 15
 import os
16 16
 import string
17 17
 from distutils.util import get_platform
18
-sys.path.insert(0, "../../build/lib.{0}-{1}.{2}".format(
19
-        get_platform(), *sys.version_info[:2]))
18
+
19
+package_path = os.path.abspath(
20
+    "../../build/lib.{0}-{1}.{2}"
21
+    .format(get_platform(), *sys.version_info[:2]))
22
+
23
+# Insert into sys.path so that we can import kwant here
24
+sys.path.insert(0, package_path)
25
+# Insert into PYTHONPATH so that jupyter-sphinx will pick it up
26
+os.environ['PYTHONPATH'] = ':'.join((package_path, os.environ.get('PYTHONPATH','')))
20 27
 
21 28
 import kwant
22 29
 import kwant.qsymm
... ...
@@ -31,7 +38,7 @@ sys.path.insert(0, os.path.abspath('../sphinxext'))
31 38
 
32 39
 extensions = ['sphinx.ext.autodoc', 'sphinx.ext.autosummary',
33 40
               'sphinx.ext.todo', 'sphinx.ext.mathjax', 'numpydoc',
34
-              'kwantdoc', 'sphinx.ext.linkcode']
41
+              'kwantdoc', 'sphinx.ext.linkcode', 'jupyter_sphinx.execute']
35 42
 
36 43
 # Add any paths that contain templates here, relative to this directory.
37 44
 templates_path = ['../templates']
... ...
@@ -239,7 +246,6 @@ autosummary_generate = True
239 246
 autoclass_content = "both"
240 247
 autodoc_default_flags = ['show-inheritance']
241 248
 
242
-
243 249
 # -- Teach Sphinx to document bound methods like functions ---------------------
244 250
 import types
245 251
 from sphinx.ext import autodoc