-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoxfile.py
89 lines (71 loc) · 2.75 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
import tempfile
from pathlib import Path
import nox
PYTHON_VERSIONS = ["3.11", "3.10", "3.9", "3.8"]
DJANGO_VERSIONS = ["4.2", "4.1", "4.0", "3.2"]
def install_poetry_groups(session, *groups: str) -> None:
"""Install dependencies from poetry groups.
Using this as a workaround until my PR is merged in:
https://github.com/cjolowicz/nox-poetry/pull/1080
"""
with tempfile.NamedTemporaryFile() as requirements:
session.run(
"poetry",
"export",
*[f"--only={group}" for group in groups],
"--format=requirements.txt",
"--without-hashes",
f"--output={requirements.name}",
external=True,
)
session.install("-r", requirements.name)
@nox.session(python=PYTHON_VERSIONS[0])
def lint(session: nox.Session) -> None:
"""Lint using pre-commit."""
args = session.posargs or [
"run",
"--all-files",
"--hook-stage=manual",
]
session.run("pre-commit", *args, external=True)
@nox.session(python=PYTHON_VERSIONS)
@nox.parametrize("django_version", DJANGO_VERSIONS)
def test(session: nox.Session, django_version: str) -> None:
"""Run the pytest suite."""
args = session.posargs
install_poetry_groups(session, "main", "test", "dev", "coverage")
session.install(f"django=={django_version}")
try:
session.run("coverage", "run", "--parallel", "-m", "pytest", *args)
finally:
if session.interactive:
session.notify("coverage", posargs=[])
@nox.session(python=PYTHON_VERSIONS)
def mypy(session: nox.Session) -> None:
"""Type-check using mypy."""
args = session.posargs or ["supergood_reads", "tests"]
install_poetry_groups(session, "main", "dev", "test", "mypy")
session.run("mypy", *args)
@nox.session(python=PYTHON_VERSIONS[0])
def safety(session: nox.Session) -> None:
"""Scan dependencies for insecure packages."""
install_poetry_groups(session, "safety")
session.run(
"bash",
"-c",
"poetry export --format=requirements.txt | safety check --full-report --stdin",
external=True,
)
@nox.session(python=PYTHON_VERSIONS[0])
def coverage(session: nox.Session) -> None:
"""Produce the coverage report.
Combines the results from all test runs from all versions of python. This is because
some logic branches may only apply to certain versions of python - we want to avoid
false negative coverage failures when those branches aren't covered by pytest runs
from other python versions.
"""
args = session.posargs or ["report"]
install_poetry_groups(session, "coverage")
if not session.posargs and any(Path().glob(".coverage.*")):
session.run("coverage", "combine")
session.run("coverage", *args)