Skip to content
Snippets Groups Projects
Commit f8729660 authored by Gigg, Martyn Anthony's avatar Gigg, Martyn Anthony
Browse files

Undo and redo a monkey patch by IPython

The patch causes Sphinx to fall over when running inside MantidPlot due
to the presence of IPython.
parent 1ef77d71
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,13 @@ import types
from PyQt4 import QtGui
# IPython monkey patches the pygments.lexer.RegexLexer.get_tokens_unprocessed method
# and breaks Sphinx when running within MantidPlot.
# We store the original method definition here on the pygments module before importing IPython
from pygments.lexer import RegexLexer
# Monkeypatch!
RegexLexer.get_tokens_unprocessed_unpatched = RegexLexer.get_tokens_unprocessed
from IPython.qt.console.rich_ipython_widget import RichIPythonWidget
from IPython.qt.inprocess import QtInProcessKernelManager
......
......@@ -64,7 +64,18 @@ def main(sysarg):
# Run
import sphinx
sys.exit(sphinx.main(argv))
# IPython monkey patches the RegexLexer.get_tokens_unprocessed method and
# causes Sphinx to fall over. We need to put it back while processing
# the documentation
from pygments.lexer import RegexLexer
# Reverse monkeypatch using unpatched function stored in mantid_ipython_widget!
RegexLexer.get_tokens_unprocessed = RegexLexer.get_tokens_unprocessed_unpatched
try:
return_value = sphinx.main(argv)
finally:
from IPython.qt.console import pygments_highlighter
RegexLexer.get_tokens_unprocessed = pygments_highlighter.get_tokens_unprocessed
sys.exit(return_value)
#-----------------------------------------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment