-
Notifications
You must be signed in to change notification settings - Fork 0
/
noxfile.py
149 lines (124 loc) · 4.19 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
# pylint: disable=missing-function-docstring,protected-access
import os
import shutil
import sys
from importlib import metadata
from pathlib import Path
import nox
os.environ["PYTHONDONTWRITEBYTECODE"] = "1"
REPO_ROOT = Path(__file__).resolve().parent
ARTIFACTS_DIR = REPO_ROOT / "artifacts"
COVERAGE_REPORT_DB = REPO_ROOT / ".coverage"
COVERAGE_REPORT_PROJECT = "coverage-project.xml"
COVERAGE_REPORT_TESTS = "coverage-tests.xml"
SKIP_REQUIREMENTS_INSTALL = os.environ.get("SKIP_REQUIREMENTS_INSTALL", "0") == "1"
PYTHON_VERSIONS = ("3.10", "3.11", "3.12", "3.13")
nox.options.reuse_existing_virtualenvs = True
# Speed up all sessions by using uv if possible
if tuple(map(int, metadata.version("nox").split("."))) >= (2024, 3):
nox.options.default_venv_backend = "uv|virtualenv"
def _install(session, *args):
if SKIP_REQUIREMENTS_INSTALL:
return
session.install(*args)
@nox.session(python="3")
def docs(session):
"""
Build Docs
"""
_install(session, "-e", ".[docs]")
os.chdir("docs/")
session.run("make", "clean", external=True)
session.run("make", "linkcheck", "SPHINXOPTS=-W", external=True)
session.run("make", "html", "SPHINXOPTS=-W", external=True)
os.chdir(str(REPO_ROOT))
@nox.session(name="docs-dev", python="3")
def docs_dev(session):
"""
Rebuild docs on changes (live preview).
"""
_install(session, "-e", ".[docs,docsauto]")
build_dir = Path("docs", "_build", "html")
# Allow specifying sphinx-autobuild options, like --host.
args = ["--watch", "."] + session.posargs
if not any(arg.startswith("--host") for arg in args):
# If the user is overriding the host to something other than localhost,
# it's likely they are rendering on a remote/headless system and don't
# want the browser to open.
args.append("--open-browser")
args += ["docs", str(build_dir)]
if build_dir.exists():
shutil.rmtree(build_dir)
session.run("sphinx-autobuild", *args)
@nox.session(python="3")
def tests(session):
return _tests(session)
@nox.session(python=PYTHON_VERSIONS)
def tests_all(session):
return _tests(session)
def _tests(session): # pylint: disable=too-many-branches
_install(session, "-e", ".[tests]")
interpreter_version = session.python
if interpreter_version == "3":
interpreter_version += f".{sys.version_info.minor}"
env = {
"COVERAGE_FILE": str(COVERAGE_REPORT_DB),
}
args = [
"--rootdir",
str(REPO_ROOT),
"--showlocals",
"-ra",
"-s",
]
if session._runner.global_config.forcecolor:
args.append("--color=yes")
if not session.posargs:
args.append("tests/")
else:
for arg in session.posargs:
if arg.startswith("--color") and args[0].startswith("--color"):
args.pop(0)
args.append(arg)
for arg in session.posargs:
if arg.startswith("-"):
continue
if arg.startswith(f"tests{os.sep}"):
break
try:
Path(arg).resolve().relative_to(REPO_ROOT / "tests")
break
except ValueError:
continue
else:
args.append("tests/")
session.run("coverage", "erase")
try:
session.run("coverage", "run", "-m", "pytest", *args, env=env)
finally:
session.run(
"coverage",
"xml",
"-o",
str(ARTIFACTS_DIR / interpreter_version / COVERAGE_REPORT_PROJECT),
"--omit=tests/*",
"--include=src/dooti/*",
)
session.run(
"coverage",
"xml",
"-o",
str(ARTIFACTS_DIR / interpreter_version / COVERAGE_REPORT_TESTS),
"--omit=src/dooti/*",
"--include=tests/*",
)
try:
session.run(
"coverage", "report", "--show-missing", "--include=src/dooti/*,tests/*"
)
finally:
if COVERAGE_REPORT_DB.exists():
shutil.move(
str(COVERAGE_REPORT_DB),
str(ARTIFACTS_DIR / interpreter_version / COVERAGE_REPORT_DB.name),
)