Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "DOC: Remove vendored IPython.sphinext (#18193)" #18320

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,3 @@ doc/build/html/index.html
doc/tmp.sv
doc/source/styled.xlsx
doc/source/templates/
doc/source/savefig/
5 changes: 3 additions & 2 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@
'sphinx.ext.extlinks',
'sphinx.ext.todo',
'numpydoc',
'IPython.sphinxext.ipython_directive',
'IPython.sphinxext.ipython_console_highlighting',
'ipython_sphinxext.ipython_directive',
'ipython_sphinxext.ipython_console_highlighting',
'IPython.sphinxext.ipython_console_highlighting', # lowercase didn't work
'sphinx.ext.intersphinx',
'sphinx.ext.coverage',
'sphinx.ext.mathjax',
Expand Down
6 changes: 3 additions & 3 deletions doc/source/whatsnew/v0.7.3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ New features
from pandas.tools.plotting import scatter_matrix
scatter_matrix(df, alpha=0.2)

.. image:: savefig/scatter_matrix_kde.png
.. image:: _static/scatter_matrix_kde.png
:width: 5in

- Add ``stacked`` argument to Series and DataFrame's ``plot`` method for
Expand All @@ -32,14 +32,14 @@ New features

df.plot(kind='bar', stacked=True)

.. image:: savefig/bar_plot_stacked_ex.png
.. image:: _static/bar_plot_stacked_ex.png
:width: 4in

.. code-block:: python

df.plot(kind='barh', stacked=True)

.. image:: savefig/barh_plot_stacked_ex.png
.. image:: _static/barh_plot_stacked_ex.png
:width: 4in

- Add log x and y :ref:`scaling options <visualization.basic>` to
Expand Down
Empty file.
116 changes: 116 additions & 0 deletions doc/sphinxext/ipython_sphinxext/ipython_console_highlighting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
"""reST directive for syntax-highlighting ipython interactive sessions.

XXX - See what improvements can be made based on the new (as of Sept 2009)
'pycon' lexer for the python console. At the very least it will give better
highlighted tracebacks.
"""

#-----------------------------------------------------------------------------
# Needed modules

# Standard library
import re

# Third party
from pygments.lexer import Lexer, do_insertions
from pygments.lexers.agile import (PythonConsoleLexer, PythonLexer,
PythonTracebackLexer)
from pygments.token import Comment, Generic

from sphinx import highlighting

#-----------------------------------------------------------------------------
# Global constants
line_re = re.compile('.*?\n')

#-----------------------------------------------------------------------------
# Code begins - classes and functions


class IPythonConsoleLexer(Lexer):

"""
For IPython console output or doctests, such as:

.. sourcecode:: ipython

In [1]: a = 'foo'

In [2]: a
Out[2]: 'foo'

In [3]: print(a)
foo

In [4]: 1 / 0

Notes:

- Tracebacks are not currently supported.

- It assumes the default IPython prompts, not customized ones.
"""

name = 'IPython console session'
aliases = ['ipython']
mimetypes = ['text/x-ipython-console']
input_prompt = re.compile("(In \[[0-9]+\]: )|( \.\.\.+:)")
output_prompt = re.compile("(Out\[[0-9]+\]: )|( \.\.\.+:)")
continue_prompt = re.compile(" \.\.\.+:")
tb_start = re.compile("\-+")

def get_tokens_unprocessed(self, text):
pylexer = PythonLexer(**self.options)
tblexer = PythonTracebackLexer(**self.options)

curcode = ''
insertions = []
for match in line_re.finditer(text):
line = match.group()
input_prompt = self.input_prompt.match(line)
continue_prompt = self.continue_prompt.match(line.rstrip())
output_prompt = self.output_prompt.match(line)
if line.startswith("#"):
insertions.append((len(curcode),
[(0, Comment, line)]))
elif input_prompt is not None:
insertions.append((len(curcode),
[(0, Generic.Prompt, input_prompt.group())]))
curcode += line[input_prompt.end():]
elif continue_prompt is not None:
insertions.append((len(curcode),
[(0, Generic.Prompt, continue_prompt.group())]))
curcode += line[continue_prompt.end():]
elif output_prompt is not None:
# Use the 'error' token for output. We should probably make
# our own token, but error is typicaly in a bright color like
# red, so it works fine for our output prompts.
insertions.append((len(curcode),
[(0, Generic.Error, output_prompt.group())]))
curcode += line[output_prompt.end():]
else:
if curcode:
for item in do_insertions(insertions,
pylexer.get_tokens_unprocessed(curcode)):
yield item
curcode = ''
insertions = []
yield match.start(), Generic.Output, line
if curcode:
for item in do_insertions(insertions,
pylexer.get_tokens_unprocessed(curcode)):
yield item


def setup(app):
"""Setup as a sphinx extension."""

# This is only a lexer, so adding it below to pygments appears sufficient.
# But if somebody knows that the right API usage should be to do that via
# sphinx, by all means fix it here. At least having this setup.py
# suppresses the sphinx warning we'd get without it.
pass

#-----------------------------------------------------------------------------
# Register the extension as a valid pygments lexer
highlighting.lexers['ipython'] = IPythonConsoleLexer()
Loading