-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathmakedoc.py
70 lines (59 loc) · 2.19 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
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
"""Automatically build documentation with Sphinx and copy it in the package."""
import argparse
import logging
import os
import shutil
import subprocess
logger = logging.getLogger()
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(build_dir)
except FileNotFoundError as err:
logger.error(err)
if __name__ == '__main__':
args = _parse_command_line()
builder = args.builder
doc_dir = './doc'
build_dir = '_build'
os.chdir(doc_dir)
shutil.copy2(f"indices/index_{builder}.rst", "index.rst")
try:
subprocess.run(["/home/user/miniconda3/envs/leo/bin/sphinx-build", "-b", builder, ".", build_dir], check=True)
except subprocess.CalledProcessError as err:
logger.error(err)
# Move documentation to its final destination
if builder == 'html':
static_dir = f'{build_dir}/_static'
sources_dir = f'{build_dir}/_sources'
htmldocs_dir = '../vitables/htmldocs'
shutil.move(f'{static_dir}/basic.css',
f'{static_dir}/classic.css')
shutil.rmtree(sources_dir)
if os.path.isdir(htmldocs_dir):
shutil.rmtree(htmldocs_dir)
shutil.copytree(build_dir, htmldocs_dir)
elif builder == 'latex':
os.chdir(build_dir)
try:
subprocess.run('pdflatex UsersGuide.tex', check=True)
subprocess.run('pdflatex UsersGuide.tex', check=True)
except subprocess.CalledProcessError as err:
logger.error(err)
shutil.copy2('UsersGuide.pdf', '../../UsersGuide.pdf')
os.chdir('..')
# Cleanup the doc directory
_cleanup()