-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnoxfile.py
More file actions
196 lines (165 loc) · 5.51 KB
/
noxfile.py
File metadata and controls
196 lines (165 loc) · 5.51 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
"""
Development tasks.
"""
import shlex
import shutil
from pathlib import Path
import nox
ALL_PYTHON_VERSIONS = (
"3.8",
"3.9",
"3.10",
"3.11",
"3.12",
"pypy3.9",
"pypy3.10",
)
DEFAULT_PYTHON_VERSION = "3.12"
ROOT_DIR = Path(__file__).parent
REQUIREMENTS_DIR = Path(__file__).parent / "requirements"
DEFAULT_TARGETS = (ROOT_DIR / "src", ROOT_DIR / "tests")
DEFAULT_TEST_TARGETS = (*DEFAULT_TARGETS, ROOT_DIR / "docs")
DEFAULT_LINT_TARGETS = (*DEFAULT_TARGETS, ROOT_DIR / "noxfile.py")
nox.options.reuse_existing_virtualenvs = True
nox.options.default_venv_backend = "uv"
nox.options.error_on_external_run = True
nox.options.sessions = (
"check-imports",
"lint",
"mypy",
"test",
"coverage",
"docs",
"build",
)
@nox.session(python=ALL_PYTHON_VERSIONS, tags=["check"])
def mypy(session: nox.Session) -> None:
"""
Run the mypy type checker
"""
session.install("-r", str(REQUIREMENTS_DIR / "lint.txt"))
session.install("-r", str(REQUIREMENTS_DIR / "test.txt"))
session.install("-e", str(ROOT_DIR))
session.run("mypy", *(session.posargs or DEFAULT_TARGETS))
@nox.session(
python=DEFAULT_PYTHON_VERSION,
tags=["lint", "check"],
name="check-imports",
)
def check_imports(session: nox.Session) -> None:
"""
Check import sort order
"""
session.install("-r", str(REQUIREMENTS_DIR / "lint.txt"))
session.run("isort", *(session.posargs or DEFAULT_LINT_TARGETS), "--check")
@nox.session(python=DEFAULT_PYTHON_VERSION, tags=["lint", "check"])
def lint(session: nox.Session) -> None:
"""
Run the ruff linter
"""
session.install("-r", str(REQUIREMENTS_DIR / "lint.txt"))
session.run("ruff", "check", *(session.posargs or DEFAULT_LINT_TARGETS))
@nox.session(python=DEFAULT_PYTHON_VERSION)
def fmt(session: nox.Session) -> None:
"""
Format the code
"""
session.install("-r", str(REQUIREMENTS_DIR / "lint.txt"))
session.run("isort", *(session.posargs or DEFAULT_LINT_TARGETS))
session.run("ruff", "format", *(session.posargs or DEFAULT_LINT_TARGETS))
@nox.session(python=ALL_PYTHON_VERSIONS, tags=["check"])
def test(session: nox.Session) -> None:
"""
Run all the tests.
"""
session.install("-r", str(REQUIREMENTS_DIR / "test.txt"))
session.install("-e", str(ROOT_DIR))
session.run(
"pytest",
"--showlocals",
"--cov=statsd",
"--no-cov-on-fail",
f"--junit-xml=junit.{session.name}.xml",
"--cov-report=",
*(session.posargs or DEFAULT_TEST_TARGETS),
env={"COVERAGE_FILE": f"coverage.{session.name}"},
)
@nox.session(python=DEFAULT_PYTHON_VERSION, tags=["check"])
def coverage(session: nox.Session) -> None:
"""
Generate coverage reports.
"""
session.install("-r", str(REQUIREMENTS_DIR / "test.txt"))
session.install("-e", str(ROOT_DIR))
session.run("coverage", "combine", "--keep", *ROOT_DIR.glob("coverage.*"))
session.run("coverage", "report")
session.run("coverage", "html")
session.run("coverage", "xml")
@nox.session(python=DEFAULT_PYTHON_VERSION, tags=["build"])
def docs(session: nox.Session) -> None:
session.install("-r", str(REQUIREMENTS_DIR / "docs.txt"))
session.install("-e", str(ROOT_DIR))
shutil.rmtree(ROOT_DIR / "docs/build", ignore_errors=True)
session.run(
"sphinx-build",
"-v",
"-W",
"-b=html",
"docs/source",
"docs/build",
)
@nox.session(python=DEFAULT_PYTHON_VERSION, tags=["build"])
def build(session: nox.Session) -> None:
session.install("-r", str(REQUIREMENTS_DIR / "build.txt"))
shutil.rmtree(ROOT_DIR / "dist", ignore_errors=True)
session.run("python", "-m", "build", *session.posargs)
@nox.session(python=DEFAULT_PYTHON_VERSION)
def upload(session: nox.Session) -> None:
session.install("-r", str(REQUIREMENTS_DIR / "build.txt"))
session.run("twine", "check", "dist/*")
session.run("twine", "upload", "dist/*")
@nox.session(python=DEFAULT_PYTHON_VERSION)
def deps(session: nox.Session) -> None:
"""
Ensure requirement files are up to date.
This can be used to update dependencies, all positional arguments will be
passed to `uv pip compile ...`.
"""
session.install("uv")
for x in REQUIREMENTS_DIR.glob("*.in"):
session.run(
"uv",
"pip",
"compile",
"--quiet",
x.resolve(),
"--output-file",
x.with_suffix(".txt"),
*session.posargs,
env={
"UV_CUSTOM_COMPILE_COMMAND": "nox -e deps",
},
)
@nox.session(python=DEFAULT_PYTHON_VERSION)
def clean(session: nox.Session) -> None:
"""
Remove all artifacts and caches.
"""
for x in [
'find src tests -type f -name "*.pyc" -delete',
'find src tests -type f -name "*.pyo" -delete',
'find src tests -type f -name "*.pyd" -delete',
'find src tests -type d -name "__pycache__" -delete',
'find src tests -type f -name "*.c" -delete',
'find src tests -type f -name "*.so" -delete',
'find . src tests -type f -path "*.egg-info*" -delete',
"rm -rf .pytest_cache",
"rm -rf .mypy_cache",
'find . -type f -name "junit*.xml" -delete',
"rm -rf htmlcov",
'find . -type f -name "coverage*.xml" -delete',
'find . -type f -name "coverage*" -delete',
'find . -type f -name "flake8.*" -delete',
"rm -rf dist build docs/build",
]:
session.run(*shlex.split(x), external=True)