Skip to content

Commit ffac147

Browse files
author
y-p
committed
Merge pull request #6179 from y-p/PR_fast_docs
BLD/DOC: Speed up doc building via jinja2 and conf.py logic
2 parents 9109812 + a041553 commit ffac147

File tree

4 files changed

+127
-23
lines changed

4 files changed

+127
-23
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ doc/source/generated
1919
doc/source/_static
2020
doc/source/vbench
2121
doc/source/vbench.rst
22+
doc/source/index.rst
2223
doc/build/html/index.html
2324
*flymake*
2425
scikits

doc/make.py

+76-19
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import shutil
2222
import sys
2323
import sphinx
24+
import argparse
25+
import jinja2
2426

2527
os.environ['PYTHONPATH'] = '..'
2628

@@ -77,7 +79,7 @@ def build_pandas():
7779
os.system('python setup.py clean')
7880
os.system('python setup.py build_ext --inplace')
7981
os.chdir('doc')
80-
82+
8183
def build_prev(ver):
8284
if os.system('git checkout v%s' % ver) != 1:
8385
os.chdir('..')
@@ -267,22 +269,77 @@ def _get_config():
267269
# current_dir = os.getcwd()
268270
# os.chdir(os.path.dirname(os.path.join(current_dir, __file__)))
269271

270-
if len(sys.argv) > 2:
271-
ftype = sys.argv[1]
272-
ver = sys.argv[2]
273-
274-
if ftype == 'build_previous':
275-
build_prev(ver)
276-
if ftype == 'upload_previous':
277-
upload_prev(ver)
278-
elif len(sys.argv) > 1:
279-
for arg in sys.argv[1:]:
280-
func = funcd.get(arg)
281-
if func is None:
282-
raise SystemExit('Do not know how to handle %s; valid args are %s' % (
283-
arg, list(funcd.keys())))
284-
func()
285-
else:
286-
small_docs = False
287-
all()
272+
import argparse
273+
argparser = argparse.ArgumentParser(description="""
274+
Pandas documentation builder
275+
""".strip())
276+
277+
# argparser.add_argument('-arg_name', '--arg_name',
278+
# metavar='label for arg help',
279+
# type=str|etc,
280+
# nargs='N|*|?|+|argparse.REMAINDER',
281+
# required=False,
282+
# #choices='abc',
283+
# help='help string',
284+
# action='store|store_true')
285+
286+
# args = argparser.parse_args()
287+
288+
#print args.accumulate(args.integers)
289+
290+
def generate_index(api=True, single=False, **kwds):
291+
from jinja2 import Template
292+
with open("source/index.rst.template") as f:
293+
t = Template(f.read())
294+
295+
with open("source/index.rst","wb") as f:
296+
f.write(t.render(api=api,single=single,**kwds))
297+
298+
import argparse
299+
argparser = argparse.ArgumentParser(description="Pandas documentation builder",
300+
epilog="Targets : %s" % funcd.keys())
301+
302+
argparser.add_argument('--no-api',
303+
default=False,
304+
help='Ommit api and autosummary',
305+
action='store_true')
306+
argparser.add_argument('--single',
307+
metavar='FILENAME',
308+
type=str,
309+
default=False,
310+
help='filename of section to compile, e.g. "indexing"')
311+
312+
def main():
313+
args, unknown = argparser.parse_known_args()
314+
sys.argv = [sys.argv[0]] + unknown
315+
if args.single:
316+
args.single = os.path.basename(args.single).split(".rst")[0]
317+
318+
if 'clean' in unknown:
319+
args.single=False
320+
321+
generate_index(api=not args.no_api and not args.single, single=args.single)
322+
323+
if len(sys.argv) > 2:
324+
ftype = sys.argv[1]
325+
ver = sys.argv[2]
326+
327+
if ftype == 'build_previous':
328+
build_prev(ver)
329+
if ftype == 'upload_previous':
330+
upload_prev(ver)
331+
elif len(sys.argv) == 2:
332+
for arg in sys.argv[1:]:
333+
func = funcd.get(arg)
334+
if func is None:
335+
raise SystemExit('Do not know how to handle %s; valid args are %s' % (
336+
arg, list(funcd.keys())))
337+
func()
338+
else:
339+
small_docs = False
340+
all()
288341
# os.chdir(current_dir)
342+
343+
if __name__ == '__main__':
344+
import sys
345+
sys.exit(main())

doc/source/conf.py

+41-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import sys
1414
import os
15+
import re
1516
from pandas.compat import u
1617

1718
# If extensions (or modules to document with autodoc) are in another directory,
@@ -46,11 +47,50 @@
4647
'sphinx.ext.coverage',
4748
'sphinx.ext.pngmath',
4849
'sphinx.ext.ifconfig',
49-
'sphinx.ext.autosummary',
5050
'matplotlib.sphinxext.only_directives',
5151
'matplotlib.sphinxext.plot_directive',
5252
]
5353

54+
55+
56+
with open("index.rst") as f:
57+
lines = f.readlines()
58+
59+
# only include the slow autosummary feature if we're building the API section
60+
# of the docs
61+
62+
# JP: added from sphinxdocs
63+
autosummary_generate = False
64+
65+
if any([re.match("\s*api\s*",l) for l in lines]):
66+
extensions.append('sphinx.ext.autosummary')
67+
autosummary_generate = True
68+
69+
ds = []
70+
for f in os.listdir(os.path.dirname(__file__)):
71+
if (not f.endswith(('.rst'))) or (f.startswith('.')) or os.path.basename(f) == 'index.rst':
72+
continue
73+
74+
_f = f.split('.rst')[0]
75+
if not any([re.match("\s*%s\s*$" % _f,l) for l in lines]):
76+
ds.append(f)
77+
78+
if ds:
79+
print("I'm about to DELETE the following:\n%s\n" % list(sorted(ds)))
80+
sys.stdout.write("WARNING: I'd like to delete those to speed up proccesing (yes/no)? ")
81+
answer = raw_input()
82+
83+
if answer.lower().strip() in ('y','yes'):
84+
for f in ds:
85+
f = os.path.join(os.path.join(os.path.dirname(__file__),f))
86+
f= os.path.abspath(f)
87+
try:
88+
print("Deleting %s" % f)
89+
os.unlink(f)
90+
except:
91+
print("Error deleting %s" % f)
92+
pass
93+
5494
# Add any paths that contain templates here, relative to this directory.
5595
templates_path = ['../_templates']
5696

@@ -80,9 +120,6 @@
80120
# The full version, including alpha/beta/rc tags.
81121
release = version
82122

83-
# JP: added from sphinxdocs
84-
autosummary_generate = True
85-
86123
# The language for content autogenerated by Sphinx. Refer to documentation
87124
# for a list of supported languages.
88125
# language = None

doc/source/index.rst renamed to doc/source/index.rst.template

+9
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ See the package overview for more detail about what's in the library.
109109
.. toctree::
110110
:maxdepth: 3
111111

112+
{% if single -%}
113+
{{ single }}
114+
{% endif -%}
115+
{%if not single -%}
112116
whatsnew
113117
install
114118
faq
@@ -136,6 +140,11 @@ See the package overview for more detail about what's in the library.
136140
ecosystem
137141
comparison_with_r
138142
comparison_with_sql
143+
{% endif -%}
144+
{% if api -%}
139145
api
146+
{% endif -%}
147+
{%if not single -%}
140148
contributing
141149
release
150+
{% endif -%}

0 commit comments

Comments
 (0)