forked from vsalvino/sphinx-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
63 lines (50 loc) · 1.89 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
60
61
62
63
"""
Utility script to compile all theme SCSS files.
"""
import os
import sass
from sphinx.application import Sphinx
from sphinx.highlighting import PygmentsBridge
from sphinx.util.docutils import docutils_namespace, patch_docutils
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
DOCS_IN_DIR = os.path.join(BASE_DIR, "docs-source")
DOCS_OUT_DIR = os.path.join(BASE_DIR, "docs")
SASS_DIR = os.path.join(BASE_DIR, "sphinx_library", "scss")
STATIC_DIR = CSS_DIR = os.path.join(BASE_DIR, "sphinx_library", "static")
CSS_DIR = os.path.join(STATIC_DIR, "library")
# -- COMPILE SCSS -------------------------------------------------------------
# Generate pygment themes into scss files.
disclaimer = """/*
* This file is auto-generated by ``build_sass.py``.
* Edit pygments themes directly in ``sphinx_library.theme``
*/
"""
light_highlighter = PygmentsBridge("html", "sphinx_library.theme.LibraryLight")
with open(os.path.join(SASS_DIR, "_pygments-light.scss"), "w") as f:
f.write(disclaimer)
f.write(light_highlighter.get_stylesheet())
dark_highlighter = PygmentsBridge("html", "sphinx_library.theme.LibraryDark")
with open(os.path.join(SASS_DIR, "_pygments-dark.scss"), "w") as f:
f.write(disclaimer)
f.write(dark_highlighter.get_stylesheet())
# Compile theme scss.
sass.compile(
output_style="compressed",
dirname=(SASS_DIR, CSS_DIR),
)
# Copy pygments to main static dir, to override sphinx's pygments file.
os.replace(
os.path.join(CSS_DIR, "pygments.css"),
os.path.join(STATIC_DIR, "pygments.css"),
)
# -- BUILD PROJECT DOCS --------------------------------------------------------
with patch_docutils(DOCS_IN_DIR), docutils_namespace():
app = Sphinx(
srcdir=DOCS_IN_DIR,
confdir=DOCS_IN_DIR,
outdir=DOCS_OUT_DIR,
doctreedir=os.path.join(DOCS_OUT_DIR, ".doctrees"),
buildername="html",
warningiserror=True
)
app.build()