-
Notifications
You must be signed in to change notification settings - Fork 0
/
noxfile.py
62 lines (46 loc) · 1.65 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
from __future__ import annotations
import os
import nox
nox.needs_version = ">=2024.10.9"
nox.options.default_venv_backend = "uv"
PYTHON_VERSIONS = ("3.9", "3.10", "3.11", "3.12", "3.13")
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#default-environment-variables
CI = True if os.getenv("CI") == "true" else False
def install(session: nox.Session) -> None:
"""Install the current project."""
session.run_install(
"uv",
"sync",
env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
silent=True,
)
@nox.session
def ruff(session: nox.Session) -> None:
"""Run ruff."""
install(session)
if CI:
# Do not modify files in CI, simply fail.
session.run("ruff", "check", ".")
session.run("ruff", "format", ".", "--check")
else:
# Fix any fixable errors if running locally.
session.run("ruff", "check", ".", "--fix")
session.run("ruff", "format", ".")
@nox.session(python=PYTHON_VERSIONS)
def mypy(session: nox.Session) -> None:
"""Run mypy."""
install(session)
session.run("mypy")
@nox.session(python=PYTHON_VERSIONS)
def pytest(session: nox.Session) -> None:
"""Run tests."""
install(session)
datafile = f".coverage.{session.python}"
session.run("coverage", "run", f"--data-file={datafile}", "-m", "pytest", "-vv", *session.posargs)
@nox.session
def coverage(session: nox.Session) -> None:
"""Generate and report coverage."""
install(session)
session.run("coverage", "combine")
session.run("coverage", "report", "-m")
session.run("coverage", "xml")