-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.py
59 lines (48 loc) · 1.9 KB
/
build.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
#!/usr/bin/env python3
import os
import glob
import shutil
import argparse
import subprocess
def postprocess_html(root):
print('Rendering MathJax')
to_process = []
for root, _dirs, files in os.walk(root):
for file in files:
if file.endswith('.html'):
to_process.append(os.path.join(root, file))
subprocess.run(['yarn', 'mjrender', *to_process]).check_returncode()
print('Fixing up alabaster.css')
with open('build/html/_static/alabaster.css', 'r+') as cssfile:
lines = cssfile.readlines()
for i, line in enumerate(lines):
if line.startswith('@import url("basic.css");'):
lines[i] = '@import "./basic.css";\n'
break
cssfile.seek(0, 0)
cssfile.writelines(lines)
print('Delete unused files')
for file in glob.glob('build/html/_static/underscore-*.js'):
os.remove(file)
for file in glob.glob('build/html/_static/jquery-*.js'):
os.remove(file)
os.remove('build/html/objects.inv')
def clean_command(args):
shutil.rmtree('build', ignore_errors=True)
shutil.rmtree('dist', ignore_errors=True)
shutil.rmtree('.cache', ignore_errors=True)
def build_command(args):
subprocess.run(['sphinx-build', '-M', 'html', 'source', 'build']).check_returncode()
postprocess_html('build/html')
def main():
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(required=True, help='sub-command help')
clean_parser = subparsers.add_parser('clean', help='clean help')
clean_parser.set_defaults(func=clean_command)
build_parser = subparsers.add_parser('build', help='build help')
build_parser.add_argument('-p, --production', dest='production', action='store_true', help='build for production')
build_parser.set_defaults(func=build_command)
args = parser.parse_args()
args.func(args)
if __name__ == '__main__':
main()