-
Notifications
You must be signed in to change notification settings - Fork 0
/
noxfile.py
323 lines (252 loc) · 8.89 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
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# SPDX-FileCopyrightText: 2023 Maxwell G <[email protected]>
#
# SPDX-License-Identifier: GPL-2.0-or-later OR MIT
from __future__ import annotations
import os
from collections.abc import Sequence
from contextlib import suppress
from glob import iglob
from pathlib import Path
from shutil import copy2
import nox
IN_CI = "JOB_ID" in os.environ or "CI" in os.environ
ALLOW_EDITABLE = os.environ.get("ALLOW_EDITABLE", str(not IN_CI)).lower() in (
"1",
"true",
)
PINNED = os.environ.get("PINNED", "true").lower() in (
"1",
"true",
)
PROJECT = "fedrq"
SPECFILE = "fedrq.spec"
LINT_SESSIONS = ("formatters", "codeqa", "typing", "basedpyright")
LINT_FILES = (f"src/{PROJECT}", "tests/", "noxfile.py")
nox.options.sessions = ("lint", "covtest", "mkdocs")
nox.options.reuse_existing_virtualenvs = True
# Helpers
def install(
session: nox.Session, *args, editable=False, constraint: str | None = None, **kwargs
):
# nox --no-venv
if isinstance(session.virtualenv, nox.virtualenv.PassthroughEnv):
session.warn(f"No venv. Skipping installation of {args}")
return
largs = []
if constraint and PINNED:
largs.extend(("-c", f"requirements/{constraint}.txt"))
if editable and ALLOW_EDITABLE:
largs.append("-e")
session.install(*largs, *args, **kwargs)
def git(session: nox.Session, *args, **kwargs):
return session.run("git", *args, **kwargs, external=True)
# General
@nox.session(venv_params=["--system-site-packages"])
def test(
session: nox.Session,
backend: str | None = None,
posargs: Sequence[str] | None = None,
):
if not backend:
# Make sure pytest is updated, as using the version from system
# site-packages causes problems with plugins.
install(session, ".[test]", constraint="test", editable=True)
tmp = Path(session.create_tmp())
env = {"FEDRQ_BACKEND": backend} if backend else {}
if any(i.startswith("--cov") for i in session.posargs):
install(session, "coverage[toml]", "pytest-cov")
env |= {"COVERAGE_FILE": str(tmp / ".coverage")}
session.run(
"pytest", *(posargs if posargs is not None else session.posargs), env=env
)
@nox.session
def coverage(session: nox.Session):
install(session, "coverage[toml]")
session.run("coverage", "combine", "--keep", *iglob(".nox/*test/tmp/.coverage"))
session.run("coverage", "html")
session.run("coverage", "report", "--fail-under=90")
@nox.session(venv_backend=None)
def covtest(session: nox.Session):
session.run("rm", "-f", *iglob(".nox/*/tmp/.coverage"), external=True)
for name in ("dnf_test", "libdnf5_test", "pydanticv1_test", "coverage"):
session.notify(name, [*session.posargs, "--cov"])
@nox.session(venv_backend="none")
def lint(session: nox.Session):
"""
Run formatters, codeql, typing, and reuse sessions
"""
for notify in LINT_SESSIONS:
session.notify(notify)
@nox.session()
def codeqa(session: nox.Session):
install(session, ".[codeqa]", constraint="codeqa")
session.run("ruff", "check", *session.posargs, *LINT_FILES)
session.run("reuse", "lint")
@nox.session
def formatters(session: nox.Session):
install(session, ".[formatters]", constraint="formatters")
posargs = session.posargs
if IN_CI:
posargs.append("--check")
session.run("black", *posargs, *LINT_FILES)
session.run("isort", *posargs, *LINT_FILES)
@nox.session
def alltyping(session: nox.Session):
session.notify("typing")
session.notify("basedpyright")
@nox.session
def typing(session: nox.Session):
install(session, ".[typing]", editable=True, constraint="typing")
session.run("mypy", "src/fedrq/", "tests/unit", "tests/integration")
@nox.session(venv_params=["--system-site-packages"])
def basedpyright(session: nox.Session):
"""
Run basedpyright with system dependencies enabled
"""
install(session, ".[typing]", editable=True, constraint="typing")
session.run("basedpyright", "--project", "custom-basedpyright.toml")
@nox.session(reuse_venv=False)
def bump(session: nox.Session):
version = session.posargs[0]
install(session, "releaserr", "flit", "fclogr")
session.run("releaserr", "check-tag", version)
session.run("releaserr", "ensure-clean")
session.run("releaserr", "set-version", "-s", "file", version)
install(session, ".")
# Bump specfile
# fmt: off
session.run(
"fclogr", "bump",
"--new", version,
"--comment", f"Release {version}.",
SPECFILE,
)
# fmt: on
# Bump changelog, commit, and tag
git(session, "add", SPECFILE, f"src/{PROJECT}/__init__.py")
session.run("releaserr", "clog", version, "--tag")
session.run("releaserr", "build", "--sign", "--backend", "flit_core")
@nox.session(reuse_venv=False)
def publish(session: nox.Session):
# Setup
install(session, "releaserr", "twine")
session.run("releaserr", "ensure-clean")
# Upload to PyPI
session.run("releaserr", "upload")
# Push to git, publish artifacts to sourcehut, and release to copr
if not session.interactive or input(
"Push to Sourcehut and copr build (Y/n)"
).lower() in ("", "y"):
git(session, "push", "--follow-tags")
session.run("hut", "git", "artifact", "upload", *iglob("dist/*"), external=True)
copr_release(session)
# Post-release bump
session.run("releaserr", "post-version", "-s", "file")
git(session, "add", f"src/{PROJECT}/__init__.py")
git(session, "commit", "-S", "-m", "Post release version bump")
@nox.session
def copr_release(session: nox.Session):
install(session, "copr-cli", "requests-gssapi", "specfile")
tmp = Path(session.create_tmp())
dest = tmp / SPECFILE
copy2(SPECFILE, dest)
session.run("python", "contrib/fedoraify.py", str(dest))
session.run("copr-cli", "build", "--nowait", f"gotmax23/{PROJECT}", str(dest))
@nox.session
def srpm(session: nox.Session, posargs=None):
install(session, "-r", "requirements/srpm.in", constraint="srpm")
posargs = posargs or session.posargs
session.run("python3", "-m", "fclogr", "--debug", "dev-srpm", *posargs)
@nox.session
def mockbuild(session: nox.Session):
tmp = Path(session.create_tmp())
srpm(session, ("-o", tmp, "--keep"))
spec_path = tmp / "fedrq.spec"
margs = [
"mock",
"--spec",
str(spec_path),
"--source",
str(tmp),
*session.posargs,
]
if not session.interactive:
margs.append("--verbose")
session.run(*margs, external=True)
# fedrq specific
@nox.session
def mkdocs(session: nox.Session):
install(session, "-e", ".[doc]", constraint="doc")
session.run("mkdocs", *(session.posargs or ["build"]))
@nox.session(venv_backend="none")
def testa(session: nox.Session):
session.notify("dnf_test")
session.notify("libdnf5_test")
session.notify("pydanticv1_test")
@nox.session(venv_params=["--system-site-packages"])
def dnf_test(session: nox.Session):
install(session, ".[test]", constraint="test", editable=True)
test(session, "dnf")
@nox.session
def libdnf5_test(session: nox.Session):
install(session, ".[test]", "libdnf5-shim", constraint="test", editable=True)
test(session, "libdnf5")
@nox.session(venv_params=["--system-site-packages"])
def pydanticv1_test(session: nox.Session):
install(session, ".[test]", constraint="pydanticv1_test", editable=True)
test(session, "dnf", ["tests/unit"])
@nox.session(name="pip-compile", python=["3.9"], reuse_venv=False)
def pip_compile(session: nox.Session):
# session.install("pip-tools")
session.install("uv")
Path("requirements").mkdir(exist_ok=True)
# Use --upgrade by default unless a user passes -P.
args = list(session.posargs)
if not any(
arg.startswith(("-P", "--upgrade-package", "--no-upgrade")) for arg in args
):
args.append("--upgrade")
with suppress(ValueError):
args.remove("--no-upgrade")
# pip_compile_cmd = ("pip-compile",)
pip_compile_cmd = (
"uv",
"pip",
"compile",
"pyproject.toml",
"--quiet",
"--universal",
)
# fmt: off
session.run(
*pip_compile_cmd,
"-o", "requirements/requirements.txt",
*args,
)
extras = (
"codeqa",
"doc",
"formatters",
"typing",
"test",
)
for extra in extras:
session.run(
*pip_compile_cmd,
"-o", f"requirements/{extra}.txt",
f"--extra={extra}",
*args,
)
extras_a = [f"--extra={extra}" for extra in extras]
session.run(*pip_compile_cmd, "-o", "requirements/all.txt", *extras_a, *args)
session.run(
*pip_compile_cmd, "-o", "requirements/srpm.txt", *args, "requirements/srpm.in"
)
session.run(
*pip_compile_cmd,
"-o", "requirements/pydanticv1_test.txt",
"-c", "requirements/pydanticv1.in",
"--extra=test",
*args,
)
# fmt: on