Skip to content

Commit 3027eea

Browse files
committed
DOC: Use nbsphinx
Update header levels for nbsphinx Link to nb, nicer default table
1 parent 5067708 commit 3027eea

File tree

8 files changed

+1034
-193
lines changed

8 files changed

+1034
-193
lines changed

ci/requirements-3.5_DOC_BUILD.run

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ sphinx
44
nbconvert
55
nbformat
66
notebook
7+
nbsphinx
78
matplotlib
89
scipy
910
lxml

doc/README.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ have ``sphinx`` and ``ipython`` installed. `numpydoc
8181
<https://github.com/numpy/numpydoc>`_ is used to parse the docstrings that
8282
follow the Numpy Docstring Standard (see above), but you don't need to install
8383
this because a local copy of ``numpydoc`` is included in the pandas source
84-
code.
84+
code. `nbsphinx <https://nbsphinx.readthedocs.io/>`_ is used to convert
85+
Jupyter notebooks. You will need to install it if you intend to modify any of
86+
the notebooks included in the documentation.
8587

8688
Furthermore, it is recommended to have all `optional dependencies
8789
<http://pandas.pydata.org/pandas-docs/dev/install.html#optional-dependencies>`_

doc/make.py

-79
Original file line numberDiff line numberDiff line change
@@ -116,93 +116,14 @@ def cleanup_nb(nb):
116116
pass
117117

118118

119-
def get_kernel():
120-
"""Find the kernel name for your python version"""
121-
return 'python%s' % sys.version_info.major
122-
123-
124-
def execute_nb(src, dst, allow_errors=False, timeout=1000, kernel_name=''):
125-
"""
126-
Execute notebook in `src` and write the output to `dst`
127-
128-
Parameters
129-
----------
130-
src, dst: str
131-
path to notebook
132-
allow_errors: bool
133-
timeout: int
134-
kernel_name: str
135-
defualts to value set in notebook metadata
136-
137-
Returns
138-
-------
139-
dst: str
140-
"""
141-
import nbformat
142-
from nbconvert.preprocessors import ExecutePreprocessor
143-
144-
with io.open(src, encoding='utf-8') as f:
145-
nb = nbformat.read(f, as_version=4)
146-
147-
ep = ExecutePreprocessor(allow_errors=allow_errors,
148-
timeout=timeout,
149-
kernel_name=kernel_name)
150-
ep.preprocess(nb, resources={})
151-
152-
with io.open(dst, 'wt', encoding='utf-8') as f:
153-
nbformat.write(nb, f)
154-
return dst
155-
156-
157-
def convert_nb(src, dst, to='html', template_file='basic'):
158-
"""
159-
Convert a notebook `src`.
160-
161-
Parameters
162-
----------
163-
src, dst: str
164-
filepaths
165-
to: {'rst', 'html'}
166-
format to export to
167-
template_file: str
168-
name of template file to use. Default 'basic'
169-
"""
170-
from nbconvert import HTMLExporter, RSTExporter
171-
172-
dispatch = {'rst': RSTExporter, 'html': HTMLExporter}
173-
exporter = dispatch[to.lower()](template_file=template_file)
174-
175-
(body, resources) = exporter.from_filename(src)
176-
with io.open(dst, 'wt', encoding='utf-8') as f:
177-
f.write(body)
178-
return dst
179-
180-
181119
def html():
182120
check_build()
183121

184-
notebooks = [
185-
'source/html-styling.ipynb',
186-
]
187-
188-
for nb in notebooks:
189-
with cleanup_nb(nb):
190-
try:
191-
print("Converting %s" % nb)
192-
kernel_name = get_kernel()
193-
executed = execute_nb(nb, nb + '.executed', allow_errors=True,
194-
kernel_name=kernel_name)
195-
convert_nb(executed, nb.rstrip('.ipynb') + '.html')
196-
except (ImportError, IndexError) as e:
197-
print(e)
198-
print("Failed to convert %s" % nb)
199-
200122
if os.system('sphinx-build -P -b html -d build/doctrees '
201123
'source build/html'):
202124
raise SystemExit("Building HTML failed.")
203125
try:
204126
# remove stale file
205-
os.remove('source/html-styling.html')
206127
os.remove('build/html/pandas.zip')
207128
except:
208129
pass

doc/source/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
'sphinx.ext.pngmath',
5050
'sphinx.ext.ifconfig',
5151
'sphinx.ext.linkcode',
52+
'nbsphinx',
5253
]
5354

5455

0 commit comments

Comments
 (0)