-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
noxfile.py
85 lines (66 loc) · 2.13 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
from pathlib import Path
from tempfile import TemporaryDirectory
import os
import nox
ROOT = Path(__file__).parent
AVIF = ROOT / "avif"
EXAMPLES = ROOT / "examples"
nox.options.sessions = []
SUPPORTED = ["3.10", "3.11", "3.12", "pypy3.10"]
LATEST = "3.12"
def session(default=True, **kwargs): # noqa: D103
def _session(fn):
if default:
nox.options.sessions.append(kwargs.get("name", fn.__name__))
return nox.session(**kwargs)(fn)
return _session
@session(python=SUPPORTED)
def tests(session):
"""
Run the test suite with a corresponding Python version.
"""
session.install(ROOT, "pytest")
if session.posargs and session.posargs[0] == "coverage":
if len(session.posargs) > 1 and session.posargs[1] == "github":
github = os.environ["GITHUB_STEP_SUMMARY"]
else:
github = None
session.install("coverage[toml]")
session.run("coverage", "run", "-m", "pytest", AVIF)
if github is None:
session.run("coverage", "report")
else:
with open(github, "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("pytest", *session.posargs, AVIF)
@session()
def audit(session):
"""
Audit dependencies for vulnerabilities.
"""
session.install("pip-audit", ROOT)
session.run("python", "-m", "pip_audit")
@session(tags=["build"])
def build(session):
"""
Build a distribution suitable for PyPI and check its validity.
"""
session.install("build", "twine")
with TemporaryDirectory() as tmpdir:
session.run("python", "-m", "build", ROOT, "--outdir", tmpdir)
session.run("twine", "check", "--strict", tmpdir + "/*")
@session(tags=["style"])
def style(session):
"""
Check Python code style.
"""
session.install("ruff")
session.run("ruff", "check", ROOT)