-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
noxfile.py
146 lines (107 loc) · 3.4 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# SPDX-FileCopyrightText: 2022 Hynek Schlawack <[email protected]>
#
# SPDX-License-Identifier: MIT
from __future__ import annotations
import os
import pathlib
import shutil
import sys
import nox
if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib
nox.options.sessions = [
"pre_commit",
"tests",
"mypy_api",
"pyright_api",
"mypy_pkg",
]
nox.options.reuse_existing_virtualenvs = True
nox.options.error_on_external_run = True
nox.needs_version = ">=2024.3.2"
nox.options.default_venv_backend = "uv|virtualenv"
pyp = tomllib.loads(pathlib.Path("pyproject.toml").read_text())
ALL_SUPPORTED = [
pv.rsplit(" ")[-1]
for pv in pyp["project"]["classifiers"]
if pv.startswith("Programming Language :: Python :: ")
]
@nox.session
def pre_commit(session: nox.Session) -> None:
session.install("pre-commit-uv")
session.run("pre-commit", "run", "--all-files")
@nox.session(python=ALL_SUPPORTED)
def mypy_api(session: nox.Session) -> None:
session.install(".[typing]", "structlog", "prometheus-client")
session.run("mypy", "tests/typing")
@nox.session(python=ALL_SUPPORTED)
def pyright_api(session: nox.Session) -> None:
session.install(".[typing]", "pyright", "structlog", "prometheus-client")
session.run("pyright", "tests/typing")
@nox.session
def mypy_pkg(session: nox.Session) -> None:
session.install(".[typing]", "structlog", "prometheus-client")
session.run("mypy", "src", "tests/typing", "noxfile.py")
def _get_pkg(posargs: list[str]) -> tuple[str, list[str]]:
"""
Allow `--installpkg path/to/wheel.whl` to be passed.
"""
posargs = list(posargs)
try:
i = posargs.index("--installpkg")
pkg = posargs[i + 1]
del posargs[i : i + 2]
except ValueError:
pkg = "."
return pkg + "[tests]", posargs
@nox.session(python=ALL_SUPPORTED)
@nox.parametrize(
"opt_deps", [[], ["structlog", "prometheus-client"], ["trio"]]
)
def tests(session: nox.Session, opt_deps: list[str]) -> None:
pkg, posargs = _get_pkg(session.posargs)
session.install(pkg, "coverage[toml]", *opt_deps)
session.run("coverage", "run", "-m", "pytest", *posargs)
if os.environ.get("CI") != "true":
session.notify("coverage_report")
@nox.session
def coverage_report(session: nox.Session) -> None:
session.install("coverage[toml]")
session.run("coverage", "combine")
session.run("coverage", "report")
@nox.session
def docs(session: nox.Session) -> None:
shutil.rmtree("docs/_build", ignore_errors=True)
if session.posargs and session.posargs[0] == "watch":
session.install("-e", ".[docs]", "watchfiles")
session.run(
"watchfiles",
"--ignore-paths",
"docs/_build",
"python -Im sphinx "
"-T -E "
"-W --keep-going "
"-b html "
"-d docs/_build/doctrees "
"-D language=en "
"-n "
"docs "
"docs/_build/html",
)
return
session.install(".[docs]")
cmds = session.posargs or ["html", "doctest"]
for cmd in cmds:
session.run(
"python", "-Im", "sphinx",
"-T", "-E",
"-W", "--keep-going",
"-b", cmd,
"-d", "docs/_build/doctrees",
"-D", "language=en",
"-n",
"docs",
"docs/_build/html",
) # fmt: skip