Skip to content

Commit ef35d7e

Browse files
committed
DOC: add option for skipping execution of code blocks
This should make documentation builds faster for people who aren't working on the code samples.
1 parent 309cf3a commit ef35d7e

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

doc/make.py

+11
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def __init__(
4141
self,
4242
num_jobs=0,
4343
include_api=True,
44+
no_ipython=False,
4445
single_doc=None,
4546
verbosity=0,
4647
warnings_are_errors=False,
@@ -57,6 +58,9 @@ def __init__(
5758
elif not include_api:
5859
os.environ["SPHINX_PATTERN"] = "-api"
5960

61+
if no_ipython:
62+
os.environ["SPHINX_SKIP_IPYTHON"] = "TRUE"
63+
6064
self.single_doc_html = None
6165
if single_doc and single_doc.endswith(".rst"):
6266
self.single_doc_html = os.path.splitext(single_doc)[0] + ".html"
@@ -302,6 +306,12 @@ def main():
302306
argparser.add_argument(
303307
"--no-api", default=False, help="omit api and autosummary", action="store_true"
304308
)
309+
argparser.add_argument(
310+
"--no-ipython",
311+
default=False,
312+
help="skip execution of code blocks",
313+
action="store_true",
314+
)
305315
argparser.add_argument(
306316
"--single",
307317
metavar="FILENAME",
@@ -353,6 +363,7 @@ def main():
353363
builder = DocBuilder(
354364
args.num_jobs,
355365
not args.no_api,
366+
args.no_ipython,
356367
args.single,
357368
args.verbosity,
358369
args.warnings_are_errors,

doc/source/conf.py

+15
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import jinja2
2121
from numpydoc.docscrape import NumpyDocString
22+
from IPython.sphinxext.ipython_directive import IPythonDirective
2223
from sphinx.ext.autosummary import _import_by_name
2324

2425
logger = logging.getLogger(__name__)
@@ -744,6 +745,16 @@ def rstjinja(app, docname, source):
744745
source[0] = rendered
745746

746747

748+
class SkipIPython(IPythonDirective):
749+
"""
750+
Treats all ipython directives as :verbatim:, to speed up build time.
751+
"""
752+
753+
def run(self):
754+
self.options["verbatim"] = True
755+
return super().run()
756+
757+
747758
def setup(app):
748759
app.connect("source-read", rstjinja)
749760
app.connect("autodoc-process-docstring", remove_flags_docstring)
@@ -754,3 +765,7 @@ def setup(app):
754765
app.add_autodocumenter(AccessorMethodDocumenter)
755766
app.add_autodocumenter(AccessorCallableDocumenter)
756767
app.add_directive("autosummary", PandasAutosummary)
768+
769+
if os.environ.get("SPHINX_SKIP_IPYTHON"):
770+
# override the directive
771+
app.add_directive("ipython", SkipIPython)

doc/source/development/contributing.rst

+3
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,9 @@ reducing the turn-around time for checking your changes.
595595
python make.py clean
596596
python make.py --no-api
597597

598+
# skip executing the code blocks
599+
python make.py --no-ipython
600+
598601
# compile the docs with only a single section, relative to the "source" folder.
599602
# For example, compiling only this guide (doc/source/development/contributing.rst)
600603
python make.py clean

0 commit comments

Comments
 (0)