-
Notifications
You must be signed in to change notification settings - Fork 0
/
noxfile.py
69 lines (59 loc) · 1.62 KB
/
noxfile.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
from shutil import rmtree
from textwrap import dedent
from pathlib import Path
import nox
ROOT = Path(__file__).parent
STYLEGUIDE = ROOT / "styleguide"
SRC_DIRECTORY = STYLEGUIDE
BUILD_DIRECTORY = STYLEGUIDE / "_build"
nox.options.sessions = ['build', 'open']
@nox.session(python=None)
def build(session):
"""Build the styleguide."""
session.run(
"sphinx-build",
f"{SRC_DIRECTORY.resolve()}",
f"{(BUILD_DIRECTORY / 'html').resolve()}",
external=True
)
@nox.session(python=None)
def clean(session):
"""Remove the build directory."""
if BUILD_DIRECTORY.exists():
rmtree(BUILD_DIRECTORY.resolve())
session.log(f"Removed {BUILD_DIRECTORY}")
@nox.session(python=None)
def open(session):
"""Open the styleguide in the browser."""
index_page = BUILD_DIRECTORY / "html" / "index.html"
if not index_page.exists():
session.error(
dedent(
f"""
File {index_page} does not exist.
Please run `nox -s build` first
"""
)
)
session.run(
"python",
"-m",
"webbrowser",
"-t",
f"{index_page.resolve()}",
external=True
)
@nox.session(python=None)
def verify(session):
"""Checks if the styleguide builds successfully."""
if BUILD_DIRECTORY.exists():
rmtree(BUILD_DIRECTORY.resolve())
session.log(f"Removed {BUILD_DIRECTORY}")
session.run(
"sphinx-build",
"-W",
"--keep-going",
f"{SRC_DIRECTORY.resolve()}",
f"{(BUILD_DIRECTORY / 'html').resolve()}",
external=True
)