Repository navigation
Expand file tree
/
Copy pathnoxfile.py
More file actions
243 lines (211 loc) · 5.88 KB
/
Copy pathnoxfile.py
File metadata and controls
243 lines (211 loc) · 5.88 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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
from pathlib import Path
from tempfile import TemporaryDirectory
import os
import nox
ROOT = Path(__file__).parent
PACKAGE = ROOT / "jsonschema"
TYPING_TESTS = ROOT / "jsonschema" / "tests" / "typing"
BENCHMARKS = PACKAGE / "benchmarks"
PYPROJECT = ROOT / "pyproject.toml"
CHANGELOG = ROOT / "CHANGELOG.rst"
DOCS = ROOT / "docs"
EXTRAS = [
nox.param(value, id=name)
for name, value in [
("no-extras", None),
("format", "format"),
("format-nongpl", "format-nongpl"),
]
]
SUPPORTED = [
"pypy3.12",
"3.12",
"3.13",
"3.14t",
"3.14",
"3.15t",
"3.15",
]
# 3.15 is still a prerelease, so the non-test sessions run on the latest
# stable interpreter until it's released.
LATEST_STABLE = "3.14"
nox.options.default_venv_backend = "uv"
nox.options.sessions = []
def install(session, *groups, extra=None):
"""
Install the project and the given dependency group(s) via ``uv sync``.
"""
session.run_install(
"uv",
"sync",
*([] if extra is None else [f"--extra={extra}"]),
"--no-default-groups",
*(arg for group in groups for arg in ("--group", group)),
f"--python={session.virtualenv.location}",
env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
)
def session(default=True, python=LATEST_STABLE, **kwargs): # noqa: D103
def _session(fn):
if default:
nox.options.sessions.append(kwargs.get("name", fn.__name__))
return nox.session(python=python, **kwargs)(fn)
return _session
@session(python=SUPPORTED)
@nox.parametrize("extra", EXTRAS)
def tests(session, extra):
"""
Run the test suite with a corresponding Python version.
"""
env = dict(JSON_SCHEMA_TEST_SUITE=str(ROOT / "json"))
install(session, "test", extra=extra)
if session.posargs and session.posargs[0] == "coverage":
if len(session.posargs) > 1 and session.posargs[1] == "github":
posargs = session.posargs[2:]
github = Path(os.environ["GITHUB_STEP_SUMMARY"])
else:
posargs, github = session.posargs[1:], None
session.install("coverage[toml]")
session.run(
"coverage",
"run",
*posargs,
"-m",
"virtue",
PACKAGE,
env=env,
)
if github is None:
session.run("coverage", "report")
else:
with github.open("a") as summary:
summary.write("### Coverage\n\n")
summary.flush() # without a flush, output seems out of order.
session.run(
"coverage",
"report",
"--format=markdown",
stdout=summary,
)
else:
session.run("virtue", *session.posargs, PACKAGE, env=env)
@session()
def license_check(session):
"""
Check that the non-GPL extra does not contain any copyleft licenses.
"""
session.install("amigpl", f"{ROOT}[format-nongpl]")
session.run("amigpl", "check")
@session(tags=["build"])
def build(session):
"""
Build a distribution suitable for PyPI and check its validity.
"""
session.install("build[uv]", "docutils", "twine")
with TemporaryDirectory() as tmpdir:
session.run(
"pyproject-build",
"--installer=uv",
ROOT,
"--outdir",
tmpdir,
)
session.run("twine", "check", "--strict", tmpdir + "/*")
session.run(
"python",
"-m",
"docutils",
"--strict",
CHANGELOG,
os.devnull,
)
@session()
def secrets(session):
"""
Check for accidentally committed secrets.
"""
session.install("detect-secrets")
session.run("detect-secrets", "scan", ROOT, "--exclude-files", "json/")
@session(tags=["style"])
def style(session):
"""
Check Python code style.
"""
session.install("ruff")
session.run("ruff", "check", ROOT, __file__)
@session()
def typing(session):
"""
Check static typing.
"""
session.install("mypy", "types-requests", ROOT)
session.run("mypy", "--config", PYPROJECT, PACKAGE)
session.run(
"mypy",
"--config",
PYPROJECT,
"--warn-unused-ignores",
TYPING_TESTS,
)
@session(tags=["docs"])
@nox.parametrize(
"builder",
[
nox.param(name, id=name)
for name in [
"dirhtml",
"doctest",
"linkcheck",
"man",
"spelling",
]
],
)
def docs(session, builder):
"""
Build the documentation using a specific Sphinx builder.
"""
install(session, "docs", extra="format")
with TemporaryDirectory() as tmpdir_str:
tmpdir = Path(tmpdir_str)
argv = ["-n", "-T", "-W"]
if builder != "spelling":
argv += ["-q"]
posargs = session.posargs or [tmpdir / builder]
session.run(
"python",
"-m",
"sphinx",
"-b",
builder,
DOCS,
*argv,
*posargs,
)
@session(tags=["docs", "style"], name="docs(style)")
def docs_style(session):
"""
Check the documentation style.
"""
session.install(
"doc8",
"pygments",
"pygments-github-lexers",
)
session.run("python", "-m", "doc8", "--config", PYPROJECT, DOCS)
@session(default=False)
@nox.parametrize("extra", EXTRAS)
@nox.parametrize(
"benchmark",
[
nox.param(each.stem, id=each.stem)
for each in BENCHMARKS.glob("[!_]*.py")
],
)
def bench(session, extra, benchmark):
"""
Run a performance benchmark.
"""
install("benchmarks", extra=extra)
tmpdir = Path(session.create_tmp())
output = tmpdir / f"bench-{benchmark}.json"
session.run("python", BENCHMARKS / f"{benchmark}.py", "--output", output)