Skip to content

Commit

Permalink
[sphinx] do not execute legacy nbs
Browse files Browse the repository at this point in the history
  • Loading branch information
marscher committed May 29, 2019
1 parent 5eefc8a commit 3e4965f
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,16 @@
'sphinx.ext.autosummary',
'sphinx.ext.napoleon',
'sphinx.ext.mathjax',
#'sphinx.ext.graphviz',
#'sphinx.ext.inheritance_diagram',
'sphinx_issues',
'nbsphinx',
]


def _preprocess_notebooks():
""" hooks into ExecutePreprocessor.preprocess to execute our own filters."""
import nbconvert
import nbsphinx
from nbconvert.preprocessors import Preprocessor
org_method = nbsphinx.Exporter.from_notebook_node #nbconvert.preprocessors.ExecutePreprocessor.preprocess
org_method = nbsphinx.Exporter.from_notebook_node

class RemoveSolutionStubs(Preprocessor):
"""For rendering executed versions of the notebooks, we do not want to have the solution stubs."""
Expand All @@ -43,16 +40,18 @@ def preprocess(self, nb, resources):
nb['cells'] = filtered_cells
return nb, resources

class RewriteNotebookLinks(Preprocessor):
def preprocess_cell(self, cell, resources, index):
new_input = cell.source.replace('.ipynb', '.html')
cell.source = new_input
return cell, resources
class NoExecuteLegacyNotebooks(Preprocessor):
def preprocess(self, nb, resources):
path = resources['metadata']['path']
if 'legacy-notebooks' in path:
nb['metadata']['nbsphinx'] = {'execute': 'never'}
self.log.info('disabled notebook execution: %s', path)
return nb, resources

def my_from_notebook_node(self, nb, resources, **kwargs):
self.log.info('patched preprocessing method')
filters = [RemoveSolutionStubs(),
#RewriteNotebookLinks()
NoExecuteLegacyNotebooks(),
]
for f in filters:
nb, resources = f.preprocess(nb, resources=resources)
Expand Down

0 comments on commit 3e4965f

Please sign in to comment.