Skip to content

Commit d6049a0

Browse files
Revert "DOC: Remove vendored IPython.sphinext (#18193)" (#18320)
This reverts commit ca737ac.
1 parent 774030c commit d6049a0

File tree

6 files changed

+1213
-6
lines changed

6 files changed

+1213
-6
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,3 @@ doc/build/html/index.html
106106
doc/tmp.sv
107107
doc/source/styled.xlsx
108108
doc/source/templates/
109-
doc/source/savefig/

doc/source/conf.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@
5656
'sphinx.ext.extlinks',
5757
'sphinx.ext.todo',
5858
'numpydoc',
59-
'IPython.sphinxext.ipython_directive',
60-
'IPython.sphinxext.ipython_console_highlighting',
59+
'ipython_sphinxext.ipython_directive',
60+
'ipython_sphinxext.ipython_console_highlighting',
61+
'IPython.sphinxext.ipython_console_highlighting', # lowercase didn't work
6162
'sphinx.ext.intersphinx',
6263
'sphinx.ext.coverage',
6364
'sphinx.ext.mathjax',

doc/source/whatsnew/v0.7.3.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ New features
2222
from pandas.tools.plotting import scatter_matrix
2323
scatter_matrix(df, alpha=0.2)
2424

25-
.. image:: savefig/scatter_matrix_kde.png
25+
.. image:: _static/scatter_matrix_kde.png
2626
:width: 5in
2727

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

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

35-
.. image:: savefig/bar_plot_stacked_ex.png
35+
.. image:: _static/bar_plot_stacked_ex.png
3636
:width: 4in
3737

3838
.. code-block:: python
3939

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

42-
.. image:: savefig/barh_plot_stacked_ex.png
42+
.. image:: _static/barh_plot_stacked_ex.png
4343
:width: 4in
4444

4545
- Add log x and y :ref:`scaling options <visualization.basic>` to

doc/sphinxext/ipython_sphinxext/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
"""reST directive for syntax-highlighting ipython interactive sessions.
2+
3+
XXX - See what improvements can be made based on the new (as of Sept 2009)
4+
'pycon' lexer for the python console. At the very least it will give better
5+
highlighted tracebacks.
6+
"""
7+
8+
#-----------------------------------------------------------------------------
9+
# Needed modules
10+
11+
# Standard library
12+
import re
13+
14+
# Third party
15+
from pygments.lexer import Lexer, do_insertions
16+
from pygments.lexers.agile import (PythonConsoleLexer, PythonLexer,
17+
PythonTracebackLexer)
18+
from pygments.token import Comment, Generic
19+
20+
from sphinx import highlighting
21+
22+
#-----------------------------------------------------------------------------
23+
# Global constants
24+
line_re = re.compile('.*?\n')
25+
26+
#-----------------------------------------------------------------------------
27+
# Code begins - classes and functions
28+
29+
30+
class IPythonConsoleLexer(Lexer):
31+
32+
"""
33+
For IPython console output or doctests, such as:
34+
35+
.. sourcecode:: ipython
36+
37+
In [1]: a = 'foo'
38+
39+
In [2]: a
40+
Out[2]: 'foo'
41+
42+
In [3]: print(a)
43+
foo
44+
45+
In [4]: 1 / 0
46+
47+
Notes:
48+
49+
- Tracebacks are not currently supported.
50+
51+
- It assumes the default IPython prompts, not customized ones.
52+
"""
53+
54+
name = 'IPython console session'
55+
aliases = ['ipython']
56+
mimetypes = ['text/x-ipython-console']
57+
input_prompt = re.compile("(In \[[0-9]+\]: )|( \.\.\.+:)")
58+
output_prompt = re.compile("(Out\[[0-9]+\]: )|( \.\.\.+:)")
59+
continue_prompt = re.compile(" \.\.\.+:")
60+
tb_start = re.compile("\-+")
61+
62+
def get_tokens_unprocessed(self, text):
63+
pylexer = PythonLexer(**self.options)
64+
tblexer = PythonTracebackLexer(**self.options)
65+
66+
curcode = ''
67+
insertions = []
68+
for match in line_re.finditer(text):
69+
line = match.group()
70+
input_prompt = self.input_prompt.match(line)
71+
continue_prompt = self.continue_prompt.match(line.rstrip())
72+
output_prompt = self.output_prompt.match(line)
73+
if line.startswith("#"):
74+
insertions.append((len(curcode),
75+
[(0, Comment, line)]))
76+
elif input_prompt is not None:
77+
insertions.append((len(curcode),
78+
[(0, Generic.Prompt, input_prompt.group())]))
79+
curcode += line[input_prompt.end():]
80+
elif continue_prompt is not None:
81+
insertions.append((len(curcode),
82+
[(0, Generic.Prompt, continue_prompt.group())]))
83+
curcode += line[continue_prompt.end():]
84+
elif output_prompt is not None:
85+
# Use the 'error' token for output. We should probably make
86+
# our own token, but error is typicaly in a bright color like
87+
# red, so it works fine for our output prompts.
88+
insertions.append((len(curcode),
89+
[(0, Generic.Error, output_prompt.group())]))
90+
curcode += line[output_prompt.end():]
91+
else:
92+
if curcode:
93+
for item in do_insertions(insertions,
94+
pylexer.get_tokens_unprocessed(curcode)):
95+
yield item
96+
curcode = ''
97+
insertions = []
98+
yield match.start(), Generic.Output, line
99+
if curcode:
100+
for item in do_insertions(insertions,
101+
pylexer.get_tokens_unprocessed(curcode)):
102+
yield item
103+
104+
105+
def setup(app):
106+
"""Setup as a sphinx extension."""
107+
108+
# This is only a lexer, so adding it below to pygments appears sufficient.
109+
# But if somebody knows that the right API usage should be to do that via
110+
# sphinx, by all means fix it here. At least having this setup.py
111+
# suppresses the sphinx warning we'd get without it.
112+
pass
113+
114+
#-----------------------------------------------------------------------------
115+
# Register the extension as a valid pygments lexer
116+
highlighting.lexers['ipython'] = IPythonConsoleLexer()

0 commit comments

Comments
 (0)