forked from ansible/ansible-documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
noxfile.py
76 lines (58 loc) · 1.9 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
import os
from pathlib import Path
import nox
LINT_FILES = ("hacking/pr_labeler/label.py", "noxfile.py")
PINNED = os.environ.get("PINNED", "true").lower() in {"1", "true"}
nox.options.sessions = ("lint",)
def install(session: nox.Session, *args, req: str, **kwargs):
if PINNED:
kwargs.setdefault("env", {})["PIP_CONSTRAINT"] = f"tests/{req}.txt"
session.install("-r", f"tests/{req}.in", *args, **kwargs)
@nox.session
def static(session: nox.Session):
"""
Run static checkers
"""
install(session, req="static")
session.run("ruff", *session.posargs, *LINT_FILES)
@nox.session
def formatters(session: nox.Session):
"""
Reformat code
"""
install(session, req="formatters")
session.run("isort", *session.posargs, *LINT_FILES)
session.run("black", *session.posargs, *LINT_FILES)
@nox.session
def formatters_check(session: nox.Session):
"""
Check code formatting without making changes
"""
install(session, req="formatters")
session.run("isort", "--check", *session.posargs, *LINT_FILES)
session.run("black", "--check", *session.posargs, *LINT_FILES)
@nox.session
def typing(session: nox.Session):
install(session, req="typing")
session.run("mypy", *session.posargs, *LINT_FILES)
@nox.session
def lint(session: nox.Session):
session.notify("static")
session.notify("formatters")
requirements_files = list(
{path.name.replace(".in", "") for path in Path("tests").glob("*in")}
- {"constraints", "constraints-base"}
)
@nox.session(name="pip-compile", python=["3.10"])
@nox.parametrize(["req"], requirements_files, requirements_files)
def pip_compile(session: nox.Session, req: str):
# .pip-tools.toml was introduced in v7
session.install("pip-tools >= 7")
# fmt: off
session.run(
"pip-compile",
"--upgrade",
"--output-file", f"tests/{req}.txt",
f"tests/{req}.in",
)
# fmt: on