-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoxfile.py
87 lines (68 loc) · 2.16 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
"""Nox file for automation."""
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from collections.abc import Iterable
import nox
python_versions = ["3.8", "3.9", "3.10", "3.11"]
venv_params = ["--no-setuptools", "--no-wheel"]
def install(
session: nox.Session,
*,
groups: Iterable[str],
root: bool = True,
only: bool | None = None,
extras: bool = False,
) -> None:
"""Install the dependency groups using Poetry."""
if only is None:
only = not root
command = [
"poetry",
"install",
"--sync",
f'--{"only" if only else "with"}={",".join(groups)}',
]
if not root:
command.append("--no-root")
if extras:
command.append("--all-extras")
session.run_always(*command, external=True)
@nox.session(python=python_versions[-1], venv_params=venv_params)
def pre_commit(session: nox.Session) -> None:
"""Run pre-commit."""
install(session, groups=["pre-commit"], root=False)
session.run(
"pre-commit",
"run",
"--all-files",
"--show-diff-on-failure",
"--hook-stage=manual",
)
@nox.session(python=python_versions[-1], venv_params=venv_params)
def lint_files(session: nox.Session) -> None:
"""Lint and fix files."""
install(session, groups=["linting"], root=False)
session.run("ruff", "check", ".", "--fix")
@nox.session(python=python_versions[-1], venv_params=venv_params)
def format_files(session: nox.Session) -> None:
"""Format files."""
install(session, groups=["linting"], root=False)
session.run("ruff", "format")
@nox.session(python=python_versions, venv_params=venv_params)
def type_check_code(session: nox.Session) -> None:
"""Type-check code."""
install(
session,
groups=["main", "typing"],
root=True,
only=True,
extras=True,
)
# mypy --install-types
session.run("mypy")
@nox.session(python=python_versions, venv_params=venv_params)
def test_code(session: nox.Session) -> None:
"""Test code."""
install(session, groups=["main", "tests"], root=True, only=True, extras=True)
session.run("pytest")