forked from suttang/docker-sphinx-rtd-theme
/
quickstart.py
92 lines (70 loc) · 2.49 KB
/
quickstart.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import os
import sys
import copy
import shutil
from sphinx import quickstart
from sphinx.quickstart import generate
d = {}
additional_config = """
# ----- blockdiag settings
extensions.extend([
'sphinxcontrib.blockdiag',
'sphinxcontrib.seqdiag',
'sphinxcontrib.actdiag',
'sphinxcontrib.nwdiag',
])
blockdiag_fontpath = '/fonts/ipag00303/ipag.ttf'
seqdiag_fontpath = '/fonts/ipag00303/ipag.ttf'
actdiag_fontpath = '/fonts/ipag00303/ipag.ttf'
nwdiag_fontpath = '/fonts/ipag00303/ipag.ttf'
blockdiag_antialias = True
seqdiag_antialias = True
actdiag_antialias = True
nwdiag_antialias = True
# ----- Read the Docs Theme
html_theme = "sphinx_rtd_theme"
# ----- pdf print styles settings
def setup(app):
app.add_stylesheet('css/print-reset.css')
app.add_stylesheet('css/print-theme-default.css')
app.add_javascript('js/print.js')
"""
additional_make = """
livehtml:
\tsphinx-autobuild -b html $(SOURCEDIR) $(BUILDDIR)/html -H 0.0.0.0
"""
def patch_generate(original_d, overwrite=True, silent=False, templatedir=None):
global d
d = copy.copy(original_d)
generate(original_d, overwrite, silent=False, templatedir=None)
def main(argv=sys.argv):
# Patch original generate function
quickstart.generate = patch_generate
# Run sphinx-quickstart
return_code = quickstart.main(argv)
if return_code:
return return_code
# TODO: quickstart.get_parser を拡張する
# Sphinx 1.6.5 で下記対応がなされているが、pip install した Sphinx 1.6.5 で
# このコードが存在しないため、反映されたら実装をする
# https://github.com/sphinx-doc/sphinx/commit/101b2893516dbbfb92767efff1c30488e651ccfc
# いまいまは直書きで対応する
#
# https://github.com/pashango2/sphinx-qsp
# これにPR送ってもよし
srcdir = d['sep'] and os.path.join(d['path'], 'source') or d['path']
conf_path = os.path.join(srcdir, 'conf.py')
make_path = os.path.join(d['path'], 'Makefile')
with open(conf_path, 'a') as f:
f.write(additional_config)
if d.get('makefile', False):
with open(make_path, 'a') as f:
f.write(additional_make)
# Copy files for pdf print style
source = d['sep'] and os.path.join(d['path'], 'source') or d['path']
prefix = d['dot'] or '_'
shutil.copytree('/files/css', f'{source}/{prefix}static/css')
shutil.copytree('/files/js', f'{source}/{prefix}static/js')
return return_code
if __name__ == '__main__':
sys.exit(main(sys.argv))