-
Notifications
You must be signed in to change notification settings - Fork 0
/
noxfile.py
153 lines (122 loc) · 4.74 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
"""
noxfile
~~~~~~~
Nox configuration script
Modified from original source found in the Salt project:
- https://github.com/saltstack/salt
"""
import datetime
import os
import shutil
import sys
from pathlib import Path
# fmt: off
if __name__ == "__main__":
sys.stderr.write(
"Do not execute this file directly. Use nox instead, it will know how to handle this file\n"
)
sys.stderr.flush()
exit(1)
# fmt: on
import nox # isort:skip
from nox.command import CommandFailed # isort:skip
# Global Path Definitions
REPO_ROOT = os.path.abspath(os.path.dirname(__file__))
# Python versions to run against
_PYTHON_VERSIONS = ("3.7", "3.8", "3.9")
# Nox options
# Reuse existing virtualenvs
nox.options.reuse_existing_virtualenvs = True
# Don't fail on missing interpreters
nox.options.error_on_missing_interpreters = False
# Change current directory to REPO_ROOT
os.chdir(REPO_ROOT)
RUNTESTS_LOGFILE = os.path.join(
"artifacts",
"logs",
"runtests-{}.log".format(datetime.datetime.now().strftime("%Y%m%d%H%M%S.%f")),
)
# Prevent Python from writing bytecode
os.environ["PYTHONDONTWRITEBYTECODE"] = "1"
nox.options.sessions = ("docs-html",)
def _get_session_python_version_info(session):
try:
version_info = session._runner._real_python_version_info
except AttributeError:
old_install_only_value = session._runner.global_config.install_only
try:
# Force install only to be false for the following chunk of code
# For additional information as to why see:
# https://github.com/theacodes/nox/pull/181
session._runner.global_config.install_only = False
session_py_version = session.run(
"python",
"-c"
'import sys; sys.stdout.write("{}.{}.{}".format(*sys.version_info))',
silent=True,
log=False,
)
version_info = tuple(
int(part) for part in session_py_version.split(".") if part.isdigit()
)
session._runner._real_python_version_info = version_info
finally:
session._runner.global_config.install_only = old_install_only_value
return version_info
def _get_pydir(session):
version_info = _get_session_python_version_info(session)
if version_info < (3, 5):
session.error("Only Python >= 3.6 is supported")
return "py{}.{}".format(*version_info)
def _install_requirements(session, transport):
# Latest pip, setuptools, and wheel
install_command = ["--progress-bar=off", "-U", "pip", "setuptools", "wheel"]
session.install(*install_command, silent=True)
# Install requirements
requirements_file = os.path.join("docs/requirements.txt")
install_command = ["--progress-bar=off", "-r", requirements_file]
session.install(*install_command, silent=True)
@nox.session(name="docs-html", python="3")
@nox.parametrize("clean", [False, True])
def docs_html(session, clean):
"""
Build Sphinx HTML Documentation
"""
pydir = _get_pydir(session)
# Latest pip, setuptools, and wheel
install_command = ["--progress-bar=off", "-U", "pip", "setuptools", "wheel"]
session.install(*install_command, silent=True)
# Install requirements
requirements_file = Path("docs", "requirements.txt")
install_command = ["--progress-bar=off", "-r", str(requirements_file)]
session.install(*install_command, silent=True)
build_dir = Path("docs", "_build", "html")
sphinxopts = "-Wn"
if clean:
sphinxopts += "E"
args = [sphinxopts, "--keep-going", "docs", str(build_dir)]
session.run("sphinx-build", *args, external=True)
@nox.session(python="3")
def docs(session) -> None:
"""
Build and serve the Sphinx HTML documentation, with live reloading on file changes, via sphinx-autobuild.
Note: Only use this in INTERACTIVE DEVELOPMENT MODE. This SHOULD NOT be called
in CI/CD pipelines, as it will hang.
"""
pydir = _get_pydir(session)
# Latest pip, setuptools, and wheel
install_command = ["--progress-bar=off", "-U", "pip", "setuptools", "wheel"]
session.install(*install_command, silent=True)
# Install requirements
requirements_file = Path("docs", "requirements.txt")
install_command = ["--progress-bar=off", "-r", str(requirements_file)]
session.install(*install_command, silent=True)
# Install autobuild req
install_command = ["--progress-bar=off", "-U", "sphinx-autobuild"]
session.install(*install_command, silent=True)
# Launching LIVE reloading Sphinx session
build_dir = Path("docs", "_build", "html")
args = ["--watch", ".", "--open-browser", "docs", str(build_dir)]
if build_dir.exists():
shutil.rmtree(build_dir)
session.run("sphinx-autobuild", *args)