-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
noxfile.py
206 lines (160 loc) · 5.07 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
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
197
198
199
200
201
202
203
204
205
206
"""Nox configuration."""
from __future__ import annotations
import os
import shutil
from pathlib import Path
import nox
GH_ACTIONS_ENV_VAR = "GITHUB_ACTIONS"
FORCE_COLOR = "FORCE_COLOR"
nox.options.sessions = [
"tests",
"xdoctest",
"deps",
"mypy",
"docs-build",
"api",
]
nox.needs_version = ">=2024.4.15"
nox.options.default_venv_backend = "uv"
package = "citric"
python_versions = [
"3.13",
"3.12",
"3.11",
"3.10",
"3.9",
"3.8",
]
pypy_versions = ["pypy3.10"]
all_python_versions = python_versions + pypy_versions
locations = "src", "tests", "noxfile.py", "docs/conf.py"
def _run_tests(session: nox.Session, *args: str) -> None:
env = {"COVERAGE_CORE": "sysmon"}
try:
session.run("coverage", "run", "-m", "pytest", *args, env=env)
finally:
if session.interactive:
session.notify("coverage", posargs=[])
@nox.session(python=python_versions, tags=["test"])
@nox.parametrize("constraints", ["highest", "lowest-direct"])
def tests(session: nox.Session, constraints: str) -> None:
"""Execute pytest tests and compute coverage."""
install_args = ["citric[tests] @ ."]
if constraints == "lowest-direct":
install_args.extend(["-c", "requirements/requirements-lowest-direct.txt"])
session.install(*install_args)
_run_tests(session, "-m", "not integration_test", *session.posargs)
@nox.session(tags=["test"])
def integration(session: nox.Session) -> None:
"""Execute integration tests and compute coverage."""
session.install("citric[tests] @ .")
_run_tests(session, "-m", "integration_test", *session.posargs)
@nox.session(tags=["test"])
def xdoctest(session: nox.Session) -> None:
"""Run examples with xdoctest."""
if session.posargs:
args = [package, *session.posargs]
else:
args = [f"--modname={package}", "--command=all"]
if FORCE_COLOR in os.environ:
args.append("--colored=1")
session.install("citric @ .")
session.install("xdoctest[colors]")
session.run("python", "-m", "xdoctest", *args)
@nox.session()
def coverage(session: nox.Session) -> None:
"""Upload coverage data."""
args = session.posargs or ["report"]
session.install("coverage[toml]")
if not session.posargs and any(Path().glob(".coverage.*")):
session.run("coverage", "combine", "--debug=pathmap")
session.run("coverage", *args)
@nox.session(name="deps", python=python_versions)
def dependencies(session: nox.Session) -> None:
"""Check issues with dependencies."""
install_env = {}
if session.python == "3.14":
install_env["PYO3_USE_ABI3_FORWARD_COMPATIBILITY"] = "1"
session.install("citric[dev] @ .", env=install_env)
session.install("deptry")
session.run("deptry", "src", "tests", "docs")
@nox.session(python=python_versions, tags=["lint"])
def mypy(session: nox.Session) -> None:
"""Type-check using mypy."""
args = session.posargs or locations
session.install("citric[typing] @ .")
session.run("mypy", *args)
@nox.session(name="docs-build")
def docs_build(session: nox.Session) -> None:
"""Build the documentation."""
args = session.posargs or ["docs", "build"]
if not session.posargs and FORCE_COLOR in os.environ:
args.insert(0, "--color")
session.install("citric[docs] @ .")
build_dir = Path("build")
if build_dir.exists():
shutil.rmtree(build_dir)
session.run("sphinx-build", *args)
@nox.session(name="docs-serve")
def docs_serve(session: nox.Session) -> None:
"""Build the documentation."""
args = session.posargs or [
"--open-browser",
"--watch",
".",
"--ignore",
"**/.nox/*",
"--ignore",
"**/.mypy_cache/*",
"docs",
"build",
]
session.install("citric[docs] @ .", "sphinx-autobuild")
build_dir = Path("build")
if build_dir.exists():
shutil.rmtree(build_dir)
session.run("sphinx-autobuild", *args)
@nox.session(name="api")
def api_changes(session: nox.Session) -> None:
"""Check for API changes."""
args = [
"griffe",
"check",
"citric",
"-s=src",
]
if GH_ACTIONS_ENV_VAR in os.environ:
args.append("-f=github")
if session.posargs:
args.append(f"-a={session.posargs[0]}")
session.run(*args, external=True)
@nox.session()
def notebook(session: nox.Session) -> None:
"""Start a Jupyter notebook."""
session.install(
"boto3",
"duckdb",
"duckdb-engine",
"faker",
"jupysql",
"jupyterlab",
"pandas",
"pyarrow",
"sqlalchemy",
"-e",
".",
)
session.run(
"jupyter",
"lab",
env={
"AWS_ENDPOINT_URL": "http://localhost:9000",
"AWS_ACCESS_KEY_ID": "minioadmin",
"AWS_SECRET_ACCESS_KEY": "minioadmin",
},
)
@nox.session(name="generate-tags", tags=["status"])
def tags(session: nox.Session) -> None:
"""Print tags."""
session.install("requests", "requests-cache")
session.run("python", "scripts/docker_tags.py")