|
40 | 40 | # documentation root, use os.path.abspath to make it absolute, like shown here.
|
41 | 41 | # sys.path.append(os.path.abspath('.'))
|
42 | 42 | sys.path.insert(0, os.path.abspath('../sphinxext'))
|
43 |
| - |
44 | 43 | sys.path.extend([
|
45 | 44 |
|
46 | 45 | # numpy standard doc extensions
|
|
75 | 74 | 'sphinx.ext.ifconfig',
|
76 | 75 | 'sphinx.ext.linkcode',
|
77 | 76 | 'nbsphinx',
|
| 77 | + 'contributors', # custom pandas extension |
78 | 78 | ]
|
79 | 79 |
|
80 | 80 | try:
|
|
120 | 120 | templates_path = ['../_templates']
|
121 | 121 |
|
122 | 122 | # The suffix of source filenames.
|
123 |
| -source_suffix = '.rst' |
| 123 | +source_suffix = [ |
| 124 | + '.rst', |
| 125 | +] |
124 | 126 |
|
125 | 127 | # The encoding of source files.
|
126 | 128 | source_encoding = 'utf-8'
|
|
298 | 300 | for page in moved_api_pages
|
299 | 301 | }
|
300 | 302 |
|
| 303 | + |
| 304 | +common_imports = """\ |
| 305 | +.. currentmodule:: pandas |
| 306 | +
|
| 307 | +.. ipython:: python |
| 308 | + :suppress: |
| 309 | +
|
| 310 | + import numpy as np |
| 311 | + from pandas import * |
| 312 | + import pandas as pd |
| 313 | + randn = np.random.randn |
| 314 | + np.set_printoptions(precision=4, suppress=True) |
| 315 | + options.display.max_rows = 15 |
| 316 | + from pandas.compat import StringIO |
| 317 | +""" |
| 318 | + |
| 319 | + |
301 | 320 | html_context = {
|
302 |
| - 'redirects': {old: new for old, new in moved_api_pages} |
| 321 | + 'redirects': {old: new for old, new in moved_api_pages}, |
| 322 | + 'common_imports': common_imports, |
303 | 323 | }
|
304 | 324 |
|
305 | 325 | # If false, no module index is generated.
|
|
388 | 408 | category=FutureWarning)
|
389 | 409 |
|
390 | 410 |
|
| 411 | +ipython_warning_is_error = False |
391 | 412 | ipython_exec_lines = [
|
392 | 413 | 'import numpy as np',
|
393 | 414 | 'import pandas as pd',
|
@@ -653,7 +674,23 @@ def process_class_docstrings(app, what, name, obj, options, lines):
|
653 | 674 | ]
|
654 | 675 |
|
655 | 676 |
|
| 677 | +def rstjinja(app, docname, source): |
| 678 | + """ |
| 679 | + Render our pages as a jinja template for fancy templating goodness. |
| 680 | + """ |
| 681 | + # http://ericholscher.com/blog/2016/jul/25/integrating-jinja-rst-sphinx/ |
| 682 | + # Make sure we're outputting HTML |
| 683 | + if app.builder.format != 'html': |
| 684 | + return |
| 685 | + src = source[0] |
| 686 | + rendered = app.builder.templates.render_string( |
| 687 | + src, app.config.html_context |
| 688 | + ) |
| 689 | + source[0] = rendered |
| 690 | + |
| 691 | + |
656 | 692 | def setup(app):
|
| 693 | + app.connect("source-read", rstjinja) |
657 | 694 | app.connect("autodoc-process-docstring", remove_flags_docstring)
|
658 | 695 | app.connect("autodoc-process-docstring", process_class_docstrings)
|
659 | 696 | app.add_autodocumenter(AccessorDocumenter)
|
|
0 commit comments