-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_docs.py
61 lines (51 loc) · 1.24 KB
/
make_docs.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
#!/usr/bin/env python3
"""Generate the documentation for Hylight.
Usage:
hatch shell
./make_docs.py
exit
"""
from shutil import copytree, rmtree, copy
from pathlib import Path
from sphinx.ext.apidoc import main as sphinx_apidoc
from sphinx.cmd.build import main as sphinx_build
# Regen the API docs
errcode = sphinx_apidoc(
[
"--ext-autodoc",
"--ext-mathjax",
"-M",
"-t",
"docs_src/_templates/",
"-o",
"docs_src/ref",
"hylight/",
"hylight/cli/*",
]
)
if errcode != 0:
exit(errcode)
Path("docs_src/ref/modules.rst").unlink()
# Build the static content
errcode = sphinx_build(["-M", "html", "./docs_src", "./public"])
if errcode != 0:
exit(errcode)
errcode = sphinx_build(["-M", "latexpdf", "./docs_src", "./public"])
if errcode != 0:
exit(errcode)
src = Path("public/html/")
docs = Path("docs")
# rm -r docs/*
for elem in docs.glob("*"):
if elem.is_dir():
rmtree(elem)
else:
elem.unlink()
# cp -r public/html/* docs
for elem in src.glob("*"):
if elem.is_dir():
copytree(elem, docs / elem.relative_to(src))
else:
copy(elem, docs)
# Ensure the presence of the .nojekyll for GitHub
(docs / ".nojekyll").touch()