-
Notifications
You must be signed in to change notification settings - Fork 55
/
makedoc.py
61 lines (50 loc) · 1.94 KB
/
makedoc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Automatically build documentation with Sphinx and copy it in the package."""
import argparse
import os
import shutil
import subprocess
def _parse_command_line():
"""Parse the arguments passed to makedoc.py script."""
usage = '%(prog)s [option]'
description = 'Build the ViTables documentation using Sphinx'
parser = argparse.ArgumentParser(usage=usage, description=description)
# Positional arguments
parser.add_argument(
'builder', choices=['html', 'latex'], nargs='?', metavar='BUILDER',
help='builder to be used by Sphinx. Can be html or latex')
parser.set_defaults(builder='html')
return parser.parse_args()
def _cleanup():
"""Cleanup the build directory."""
try:
os.remove('index.rst')
shutil.rmtree('{0}'.format(build_dir))
except FileNotFoundError as err:
print(err)
if __name__ == '__main__':
args = _parse_command_line()
builder = args.builder
build_dir = '_build'
os.chdir('./doc')
shutil.copy2("indices/index_{0}.rst".format(builder), "index.rst")
subprocess.run(["sphinx-build", "-b", builder, ".", build_dir])
# Move documentation to its final destination
if builder == 'html':
static_dir = '{0}/_static'.format(build_dir)
sources_dir = '{0}/_sources'.format(build_dir)
htmldocs_dir = '../vitables/htmldocs'
shutil.move('{0}/basic.css'.format(static_dir),
'{0}/classic.css'.format(static_dir))
shutil.rmtree('{0}'.format(sources_dir))
shutil.rmtree('{0}'.format(htmldocs_dir))
shutil.copytree(build_dir, '{0}'.format(htmldocs_dir))
elif builder == 'latex':
os.chdir('./_build')
subprocess.run('pdflatex UsersGuide.tex')
subprocess.run('pdflatex UsersGuide.tex')
shutil.copy2('UsersGuide.pdf', '../../UsersGuide.pdf')
os.chdir('..')
# Cleanup the doc directory
_cleanup()