-
Notifications
You must be signed in to change notification settings - Fork 4
/
make.py
45 lines (36 loc) · 1.25 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
import os, shutil
def external_run(os_cmd):
print(f"\n--- Running: {os_cmd}")
errcode = os.system(os_cmd)
if errcode > 0:
exit()
print(f"--- Complete: {os_cmd}")
def copy_dir(dir_src, dir_des, delete_src=False):
"""Overwrite/create the dir_des from the dir_src."""
if os.path.isdir(dir_des):
shutil.rmtree(dir_des)
shutil.copytree(dir_src, dir_des)
if delete_src:
shutil.rmtree(dir_src)
def main(dir_src, dir_serve, char_enc='utf-8'):
docsrc = os.path.join(dir_src)
docs = os.path.join(dir_serve)
build_tmp_dir = os.path.join(docsrc, "_build")
if os.path.isdir(build_tmp_dir):
shutil.rmtree(build_tmp_dir)
# Build to HTML
build_cmd = f'sphinx-build -M html {docsrc} {build_tmp_dir}'
external_run(build_cmd)
# Copy (Overwrite if exists!) build_tmp_dir to docs
build_html_dir = os.path.join(build_tmp_dir, "html")
copy_dir(build_html_dir, docs)
# Github Pages will be hosted at docs
## Create a .nojekyll for Github Pages
nojekyll = os.path.join(docs, ".nojekyll")
if not os.path.exists(nojekyll):
with open(nojekyll, 'w', encoding=char_enc):
pass
# --- Main ---
dir_src = 'docsrc'
dir_serve = 'docs'
main(dir_src, dir_serve)