-
Notifications
You must be signed in to change notification settings - Fork 297
/
noxfile.py
102 lines (80 loc) · 3.03 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
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
import nox
from pathlib import Path
nox.options.reuse_existing_virtualenvs = True
def _should_install(session):
"""Decide if we should install an environment or if it already exists.
This speeds up the local install considerably because building the wheel
for this package takes some time.
We assume that if `sphinx-build` is in the bin/ path, the environment is
installed.
"""
if session.bin_paths is None:
session.log("Running with `--no-venv` so don't install anything...")
return False
bin_files = list(Path(session.bin).glob("*"))
sphinx_is_installed = any("sphinx-build" in ii.name for ii in bin_files)
force_reinstall = "reinstall" in session.posargs or "-r" in session.posargs
should_install = not sphinx_is_installed or force_reinstall
if should_install:
session.log("Installing fresh environment...")
else:
session.log("Skipping environment install...")
return should_install
@nox.session
def compile(session):
if _should_install(session):
session.install("-e", ".")
session.install("sphinx-theme-builder[cli]")
session.run("stb", "compile")
@nox.session
def docs(session):
if _should_install(session):
session.install("-e", ".[doc]")
session.run("sphinx-build", "-b=html", "docs/", "docs/_build/html")
@nox.session(name="docs-live")
def docs_live(session):
if _should_install(session):
session.install("-e", ".[doc]")
session.install("sphinx-theme-builder[cli]")
session.run("stb", "serve", "docs", "--open-browser")
@nox.session(name="test")
def test(session):
if _should_install(session):
session.install("-e", ".[test]")
session.run("pytest", *session.posargs)
@nox.session(name="profile")
def profile(session):
"""Generate a profile chart with py-spy.
The chart will be placed at profile.svg and can be viewed in the browser.
"""
import shutil as sh
import tempfile
from textwrap import dedent
if _should_install(session):
session.install("-e", ".[test]")
session.install("py-spy")
with tempfile.TemporaryDirectory() as tmpdir:
# Copy over our base test site to the temporary folder
path_base = Path("tests/sites/base/")
path_tmp = Path(tmpdir) / path_base
sh.copytree(path_base, path_tmp)
# Add a bunch of extra files to increase the build length
index = path_tmp / "index.rst"
text = index.read_text()
text += dedent(
"""
.. toctree::
:glob:
many/*
"""
)
index.write_text(text)
(path_tmp / "many").mkdir()
# Create a bunch of empty pages to slow the build
for ii in range(50):
(path_tmp / "many" / f"{ii}.rst").write_text("Test\n====\n\nbody\n")
# Specify our output directory and profile the build
path_tmp_out = path_tmp / "_build"
session.run(
*f"py-spy record -o profile.svg -- sphinx-build {path_tmp} {path_tmp_out}".split() # noqa
)