This repository was archived by the owner on Aug 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnoxfile.py
More file actions
119 lines (92 loc) · 3.05 KB
/
noxfile.py
File metadata and controls
119 lines (92 loc) · 3.05 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import shutil
import subprocess
import sys
import nox
sys.path.insert(0, "")
from src.helpers import (
BUILD_PATH,
CONF_PY_FILE,
PUBLIC_PATH,
RENDER_INFO_FILE,
IsolatedEnvironment,
load_themes,
patch_sample_docs_for,
)
def _prepare_output_directory(destination):
# Clean up existing stuff
if destination.exists():
shutil.rmtree(destination)
# Make the barebones skeleton
destination.mkdir()
(destination / "preview-images").mkdir()
(destination / "sample-sites").mkdir()
def _generate_docs(session, theme):
session.log(f" {theme.name} ".center(80, "-"))
# Setup the isolated environment
env = IsolatedEnvironment(theme.name)
session.run("virtualenv", str(env.path), silent=True)
# Install required packages
packages = sorted({"sphinx", theme.pypi}) # prevents duplication
env.install(*packages)
# Run sphinx
patch_sample_docs_for(theme)
env.run(
"sphinx-build",
"-v",
"-b",
"html",
"sample-docs",
str(BUILD_PATH / theme.name),
silent=True,
)
shutil.move(
str(BUILD_PATH / theme.name), str(PUBLIC_PATH / "sample-sites" / theme.name),
)
shutil.copy(
str(CONF_PY_FILE), str(PUBLIC_PATH / "sample-sites" / theme.name),
)
def with_every_theme(session, function, message):
"""Nice little helper, to make looping through all the themes easier.
"""
themes = load_themes(*session.posargs)
failed = []
for theme in themes:
try:
function(session, theme)
except subprocess.CalledProcessError:
failed.append(theme)
continue
if failed:
parts = [f"Failed to {message.lower()} for:"]
for theme in failed:
parts.append(f"- {theme.name}")
session.error("\n".join(parts))
@nox.session(python=False)
def publish(session):
session.notify("render-sample-sites")
session.notify("generate-previews")
session.notify("render-index")
@nox.session(name="render-sample-sites", python=False)
def render_sample_sites(session):
_prepare_output_directory(PUBLIC_PATH)
_prepare_output_directory(BUILD_PATH)
with_every_theme(session, _generate_docs, "Render")
@nox.session(name="generate-previews")
def generate_previews(session):
assert PUBLIC_PATH.exists(), "Did you run 'render-sample-sites' yet?"
session.install("selenium", "pillow", "colorama")
session.run("python", "tools/generate-previews.py", *session.posargs)
source = BUILD_PATH / "preview-images"
destination = PUBLIC_PATH / "preview-images"
for file in source.iterdir():
assert file.is_file(), repr(file)
shutil.move(str(file), str(destination / file.name))
@nox.session(name="render-index")
def render_index(session):
session.install("jinja2")
session.run("python", "tools/render-index.py")
shutil.move(str(BUILD_PATH / "index.html"), str(PUBLIC_PATH / "index.html"))
@nox.session
def lint(session):
session.install("pre-commit")
session.run("pre-commit", "run", "--all-files")