-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake.py
257 lines (191 loc) · 7.08 KB
/
make.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/usr/bin/env python
# Build script for Sphinx documentation
import os
import shlex
import shutil
import subprocess
import sys
from collections import OrderedDict
# You can set these variables from the command line.
SPHINXOPTS = os.getenv('SPHINXOPTS', '')
SPHINXBUILD = os.getenv('SPHINXBUILD', 'sphinx-build')
PAPER = os.getenv('PAPER', None)
BUILDDIR = os.getenv('BUILDDIR', 'build')
SOURCEDIR = os.getenv('SRCDIR', 'source')
TARGETS = OrderedDict()
def target(function):
TARGETS[function.__name__] = function
return function
# User-friendly check for sphinx-build
def check_sphinx_build():
with open(os.devnull, 'w') as devnull:
try:
if subprocess.call([SPHINXBUILD, '--version'],
stdout=devnull, stderr=devnull) == 0:
return
except FileNotFoundError:
pass
print("The '{0}' command was not found. Make sure you have Sphinx "
"installed, then set the SPHINXBUILD environment variable "
"to point to the full path of the '{0}' executable. "
"Alternatively you can add the directory with the "
"executable to your PATH. If you don't have Sphinx "
"installed, grab it from http://sphinx-doc.org/)"
.format(SPHINXBUILD))
sys.exit(1)
@target
def all():
"""the default target"""
return html()
@target
def clean():
"""remove the build directory"""
shutil.rmtree(BUILDDIR, ignore_errors=True)
def build(builder, success_msg=None, extra_opts=None, outdir=None,
doctrees=True):
builddir = os.path.join(BUILDDIR, outdir or builder)
command = [SPHINXBUILD, '-b', builder]
if doctrees:
command.extend(['-d', os.path.join(BUILDDIR, 'doctrees')])
if extra_opts:
command.extend(extra_opts)
command.extend(shlex.split(SPHINXOPTS))
command.extend([SOURCEDIR, builddir])
print(' '.join(command))
if subprocess.call(command) == 0:
print('Build finished. ' + success_msg.format(builddir))
@target
def html():
"""make standalone HTML files"""
return build('html', 'The HTML pages are in {}.')
@target
def dirhtml():
"""make HTML files named index.html in directories"""
return build('dirhtml', 'The HTML pages are in {}')
@target
def singlehtml():
"""make a single large HTML file"""
return build('singlehtml', 'The HTML page is in {}.')
@target
def pickle():
"""make pickle files"""
return build('pickle', 'Now you can process the pickle files.')
@target
def json():
"""make JSON files"""
return build('json', 'Now you can process the JSON files.')
@target
def htmlhelp():
"""make HTML files and a HTML help project"""
return build('htmlhelp', 'Now you can run HTML Help Workshop with the '
'.hhp project file in {}.')
@target
def qthelp():
"""make HTML files and a qthelp project"""
return build('qthelp', 'Now you can run "qcollectiongenerator" with the '
'.qhcp project file in {0}, like this: \n'
'# qcollectiongenerator {0}/RinohType.qhcp\n'
'To view the help file:\n'
'# assistant -collectionFile {0}/RinohType.qhc')
@target
def devhelp():
"""make HTML files and a Devhelp project"""
return build('devhelp', 'To view the help file:\n'
'# mkdir -p $HOME/.local/share/devhelp/RinohType\n'
'# ln -s {} $HOME/.local/share/devhelp/RinohType\n'
'# devhelp')
@target
def epub():
"""make an epub"""
return build('epub', 'The epub file is in {}.')
@target
def rinoh():
"""make a PDF using rinohtype"""
return build('rinoh', 'The PDF file is in {}.')
@target
def latex():
"""make LaTeX files, you can set PAPER=a4 or PAPER=letter"""
extra_opts = ['-D', 'latex_paper_size={}'.format(PAPER)] if PAPER else None
return build('latex', 'The LaTeX files are in {}.\n'
"Run 'make' in that directory to run these through "
"(pdf)latex (use the 'latexpdf' target to do that "
"automatically).", extra_opts)
@target
def latexpdf():
"""make LaTeX files and run them through pdflatex"""
rc = latex()
print('Running LaTeX files through pdflatex...')
builddir = os.path.join(BUILDDIR, 'latex')
subprocess.call(['make', '-C', builddir, 'all-pdf'])
print('pdflatex finished; the PDF files are in {}.'.format(builddir))
@target
def latexpdfja():
"""make LaTeX files and run them through platex/dvipdfmx"""
rc = latex()
print('Running LaTeX files through platex and dvipdfmx...')
builddir = os.path.join(BUILDDIR, 'latex')
subprocess.call(['make', '-C', builddir, 'all-pdf-ja'])
print('pdflatex finished; the PDF files are in {}.'.format(builddir))
@target
def text():
"""make text files"""
return build('text', 'The text files are in {}.')
@target
def man():
"""make manual pages"""
return build('man', 'The manual pages are in {}.')
@target
def texinfo():
"""make Texinfo files"""
return build('texinfo', 'The Texinfo files are in {}.\n'
"Run 'make' in that directory to run these "
"through makeinfo (use the 'info' target to do "
"that automatically).")
@target
def info():
"""make Texinfo files and run them through makeinfo"""
rc = texinfo()
print('Running Texinfo files through makeinfo...')
builddir = os.path.join(BUILDDIR, 'texinfo')
subprocess.call(['make', '-C', builddir, 'info'])
print('makeinfo finished; the Info files are in {}.'.format(builddir))
@target
def gettext():
"""make PO message catalogs"""
return build('gettext', 'The message catalogs are in {}.', outdir='locale',
doctrees=False)
@target
def changes():
"""make an overview of all changed/added/deprecated items"""
return build('changes', 'The overview file is in {}.')
@target
def xml():
"""make Docutils-native XML files"""
return build('xml', 'The XML files are in {}.')
@target
def pseudoxml():
"""make pseudoxml-XML files for display purposes"""
return build('pseudoxml', 'The pseudo-XML files are in {}.')
@target
def linkcheck():
"""check all external links for integrity"""
return build('linkcheck', 'Look for any errors in the above output or in '
'{}/output.txt.')
@target
def doctest():
"""run all doctests embedded in the documentation (if enabled)"""
return build('doctest', 'Look at the results in {}/output.txt.')
@target
def help():
"""List all targets"""
print("Please use '{} <target>' where <target> is one of"
.format(sys.argv[0]))
width = max(len(name) for name in TARGETS)
for name, target in TARGETS.items():
print(' {name:{width}} {descr}'.format(name=name, width=width,
descr=target.__doc__))
if __name__ == '__main__':
check_sphinx_build()
args = sys.argv[1:] or ['all']
for arg in args:
TARGETS[arg]()