-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnoxfile.py
125 lines (98 loc) · 2.41 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
from __future__ import annotations
import re
from functools import cache, partial
from itertools import chain
from typing import Any
import nox
DJANGO_PYTHONS = {
"4.2": [
"3.9",
"3.10",
"3.11",
"3.12",
],
"5.0": [
"3.10",
"3.11",
"3.12",
],
"5.1": [
"3.10",
"3.11",
"3.12",
],
}
@cache
def load_dev_dependencies() -> list[str]:
project: dict[str, Any] = nox.project.load_toml("pyproject.toml")["project"]
optional_dependencies: dict[str, list[str]] = project["optional-dependencies"]
return optional_dependencies["dev"]
def match_dev_dependencies(*patterns: str) -> list[str]:
dev_dependencies = load_dev_dependencies()
return list(
chain.from_iterable(
filter(partial(re.match, pattern), dev_dependencies) for pattern in patterns
),
)
nox.options.sessions = ["ruff", "mypy", "pytest"]
@nox.session(tags=["build"])
@nox.parametrize(
"python",
[
"3.9",
"3.10",
"3.11",
"3.12",
],
)
def build(session: nox.Session) -> None:
session.install("build")
session.run("python", "-m", "build")
session.run("rm", "-rf", "dist", external=True)
@nox.session(tags=["lint"])
@nox.parametrize(
"command",
[
"check",
"format",
],
)
def ruff(session: nox.Session, command: str) -> None:
session.install(
*match_dev_dependencies(
r"^ruff ~=",
),
)
extra_options = session.posargs or []
session.run("ruff", command, *extra_options, ".")
@nox.session(tags=["lint"])
def mypy(session: nox.Session) -> None:
session.install(
*match_dev_dependencies(
r"^django\-stubs\[compatible-mypy\] ~=",
),
"-e",
".",
)
extra_options = session.posargs or ["--ignore-missing-imports"]
session.run("mypy", *extra_options, ".")
@nox.session(tags=["test"])
@nox.parametrize(
("django", "python"),
[
(django, python)
for django, pythons in DJANGO_PYTHONS.items()
for python in pythons
],
)
def pytest(session: nox.Session, django: str) -> None:
session.install(
*match_dev_dependencies(
r"^pytest(-[\w\-]+)? ~=",
),
f"django == {django}.*",
"-e",
".",
)
extra_options = session.posargs or []
session.run("pytest", *extra_options)