Skip to content

Commit

Permalink
Simplify setting of jupyter backend
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Mueller <[email protected]>
  • Loading branch information
johannes-mueller committed Dec 8, 2023
1 parent 63c2ebd commit e490849
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,33 +49,14 @@
ep.preprocess(nb, {'metadata': {'path': os.path.dirname(fn)}})


# Inject code to set pyvista jupyter backend into relevant notebooks
#
import nbsphinx
original_from_notebook_node = nbsphinx.Exporter.from_notebook_node

from nbconvert.preprocessors import Preprocessor

def from_notebook_node(self, nb, resources, **kwargs):

class InjectPyvistaBackendPreprocessor(Preprocessor):
def preprocess(self, nb, resources):
for index, cell in enumerate(nb.cells):
if cell['cell_type'] == 'code' and 'import pyvista as pv' in cell['source'] :
cell['source'] += "\npv.set_jupyter_backend('html')\n"
break
return nb, resources

nb, resources = InjectPyvistaBackendPreprocessor().preprocess(nb, resources=resources)
return original_from_notebook_node(self, nb, resources, **kwargs)

nbsphinx.Exporter.from_notebook_node = from_notebook_node


# Don't try to use C-code for the pytensor stuff when building the docs.
# Otherwise the demo notebooks fail on readthedocs
os.environ['PYTHONWARNINGS'] = 'ignore'

os.environ["PYVISTA_JUPYTER_BACKEND"] = 'html'

import asyncio

# See https://bugs.python.org/issue37373 :(
Expand Down

0 comments on commit e490849

Please sign in to comment.