Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Add the necessary default settings to enable HTML output in the Jupyter
Browse files Browse the repository at this point in the history
Notebook pager for the IPython shell.

We need to replace the monkeypatching of getdoc -> sage_getdoc with
getdoc -> sage_getdoc_original.  The difference is that the former also
runs sage.misc.sagedoc.format() over the docstring, whereas the latter
doesn't.  This is necessary so that by the time the docstring reaches
sphinxify_mimebundle() it hasn't been re-formatted yet.

That said, it's still not entirely clear how this change will affect
other functionality, as getdoc is used in several places by
IPython.core.oinspect.

We also need to inject our sphinxify_mimebundle() in place of the
default sphinxify in IPython.core.interactiveshell.  Unfortunate but not
easily avoidable at the moment.
  • Loading branch information
embray committed Sep 23, 2019
1 parent 5ed3d00 commit ec1e13a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/sage/repl/ipython_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,10 @@ def __init__(self, shell=None):

self.register_interface_magics()

# Change some default settings to allow displaying HTML help
self.shell.enable_html_pager = True
self.shell.sphinxify_docstring = True

if SAGE_IMPORTALL == 'yes':
self.init_environment()

Expand Down Expand Up @@ -497,11 +501,18 @@ def init_inspector(self):
# the global :class:`IPython.core.oinspect` module namespace.
# Thus, we have to monkey-patch.
import IPython.core.oinspect
IPython.core.oinspect.getdoc = LazyImport("sage.misc.sageinspect", "sage_getdoc")
IPython.core.oinspect.getdoc = \
LazyImport("sage.misc.sageinspect", "sage_getdoc_original")
IPython.core.oinspect.getsource = LazyImport("sage.misc.sagedoc", "my_getsource")
IPython.core.oinspect.find_file = LazyImport("sage.misc.sageinspect", "sage_getfile")
IPython.core.oinspect.getargspec = LazyImport("sage.misc.sageinspect", "sage_getargspec")

# Similarly to enable Sage's sphinxify we must use a similar hack, but
# on IPython.core.interactiveshell
import IPython.core.interactiveshell
IPython.core.interactiveshell.sphinxify = \
LazyImport("sage.misc.sphinxify", "sphinxify_mimebundle")

def init_line_transforms(self):
"""
Set up transforms (like the preparser).
Expand Down

0 comments on commit ec1e13a

Please sign in to comment.