Skip to content

Commit 831ea80

Browse files
author
y-p
committed
BLD/DOC: use jinja2 templates to allow make.py to build partial docs
1 parent ea11bf3 commit 831ea80

File tree

3 files changed

+63
-19
lines changed

3 files changed

+63
-19
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

+53-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,54 @@ 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+
def main():
299+
generate_index(api=False, single='indexing')
300+
if len(sys.argv) > 2:
301+
ftype = sys.argv[1]
302+
ver = sys.argv[2]
303+
304+
if ftype == 'build_previous':
305+
build_prev(ver)
306+
if ftype == 'upload_previous':
307+
upload_prev(ver)
308+
elif len(sys.argv) == 2:
309+
for arg in sys.argv[1:]:
310+
func = funcd.get(arg)
311+
if func is None:
312+
raise SystemExit('Do not know how to handle %s; valid args are %s' % (
313+
arg, list(funcd.keys())))
314+
func()
315+
else:
316+
small_docs = False
317+
all()
288318
# os.chdir(current_dir)
319+
320+
if __name__ == '__main__':
321+
import sys
322+
sys.exit(main())

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)