-
Notifications
You must be signed in to change notification settings - Fork 23
/
noxfile.py
156 lines (125 loc) · 5.46 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
from pathlib import Path
import platform
import shutil
import nox
def find_uv() -> tuple[bool, str]:
# Inspired by:
# https://github.com/wntrblm/nox/blob/08813c3c6b0d2171c280bbfcf219d089a16d1ac2/nox/virtualenv.py#L42
uv = shutil.which("uv")
if uv is not None:
return True, uv
return False, "uv"
HAS_UV, UV = find_uv()
@nox.session(venv_backend="mamba|conda", python="3.11", reuse_venv=True)
def dev(session):
"""Set up a development environment."""
session.conda_install("graphviz", channel="conda-forge")
if platform.system() == "Windows":
session.conda_install("pygraphviz", channel="conda-forge")
if HAS_UV:
session.run(UV, "pip", "install", "-r", "requirements/dev.txt", external=True)
else:
session.install("-r", "requirements/dev.txt")
conda_cmd = session.virtualenv.conda_cmd
env_path = Path(session.virtualenv.location).relative_to(Path.cwd())
session.log(f"Activate with: {conda_cmd} activate {env_path}")
@nox.session(venv_backend="uv|virtualenv", python="3.11", reuse_venv=True)
def lint(session):
session.env.pop("CONDA_PREFIX", None) # uv errors if both venv and conda env are active
session.install("-r", "requirements/lint.txt")
session.run("ruff", "format", "--check")
session.run("ruff", "check")
@nox.session(venv_backend="mamba|conda", python="3.11", reuse_venv=True)
def typecheck(session):
session.conda_install("graphviz", channel="conda-forge")
if platform.system() == "Windows":
session.conda_install("pygraphviz", channel="conda-forge")
if HAS_UV:
session.run(UV, "pip", "install", "-r", "requirements/typecheck.txt", external=True)
else:
session.install("-r", "requirements/typecheck.txt")
session.run("mypy", "--install-types", "--non-interactive")
class CoverageCleaner:
"""Global coverage cleaner to clean up coverage artifacts once per nox invocation."""
def __init__(self):
self.been_run = False
def clean(self, session):
if not self.been_run:
session.log("Cleaning up coverage artifacts.")
self.been_run = True
Path(".coverage").unlink(missing_ok=True)
Path("coverage.xml").unlink(missing_ok=True)
shutil.rmtree("htmlcov", ignore_errors=True)
coverage_cleaner = CoverageCleaner()
@nox.session(
venv_backend="mamba|conda",
python=["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"],
reuse_venv=True,
)
def tests(session):
session.conda_install("graphviz", channel="conda-forge")
if platform.system() == "Windows":
session.conda_install("pygraphviz", channel="conda-forge")
if HAS_UV:
session.run(UV, "pip", "install", "-r", "requirements/tests.txt", external=True)
else:
session.install("-r", "requirements/tests.txt")
coverage_cleaner.clean(session)
session.run("pytest", "-vv")
@nox.session(venv_backend="uv|virtualenv", reuse_venv=True)
def build(session):
session.env.pop("CONDA_PREFIX", None) # uv errors if both venv and conda env are active
session.install("build")
session.run("python", "-m", "build")
@nox.session(venv_backend="mamba|conda", python="3.12", reuse_venv=False)
@nox.parametrize("extras", ["", "[attrs]"])
def test_wheel(session, extras):
session.conda_install("graphviz", channel="conda-forge")
if platform.system() == "Windows":
session.conda_install("pygraphviz", channel="conda-forge")
wheel_path = next(Path("dist").glob("*.whl")).resolve()
if HAS_UV:
session.run(UV, "pip", "install", f"erdantic{extras} @ {wheel_path}", external=True)
else:
session.install(str(wheel_path) + extras)
session.run("python", "-m", "erdantic", "--version")
session.run(
"python", "-c", "import erdantic; import erdantic.examples; print(erdantic.list_plugins())"
)
@nox.session(venv_backend="mamba|conda", python="3.12", reuse_venv=False)
def test_sdist(session):
session.conda_install("graphviz", channel="conda-forge")
if platform.system() == "Windows":
session.conda_install("pygraphviz", channel="conda-forge")
sdist_path = next(Path("dist").glob("*.tar.gz")).resolve()
if HAS_UV:
session.run(UV, "pip", "install", f"erdantic @ {sdist_path}", external=True)
else:
session.install(sdist_path)
session.run("python", "-m", "erdantic", "--version")
session.run(
"python", "-c", "import erdantic; import erdantic.examples; print(erdantic.list_plugins())"
)
def _docs_base(session):
session.conda_install("graphviz", channel="conda-forge")
if platform.system() == "Windows":
session.conda_install("pygraphviz", channel="conda-forge")
if HAS_UV:
session.run(UV, "pip", "install", "-r", "requirements/docs.txt", external=True)
else:
session.install("-r", "requirements/docs.txt")
examples_dir = Path("docs/docs/examples").resolve()
examples_dir.mkdir(exist_ok=True)
for notebook_path in sorted(Path("docs/notebooks").glob("*.ipynb")):
out_path = examples_dir / notebook_path.name
session.run("jupyter", "execute", f"--output={out_path}", notebook_path)
@nox.session(venv_backend="mamba|conda", python="3.11", reuse_venv=True)
def docs(session):
_docs_base(session)
with session.chdir("docs"):
session.run("mkdocs", "build")
@nox.session(venv_backend="mamba|conda", python="3.11", reuse_venv=True)
def docs_serve(session):
_docs_base(session)
with session.chdir("docs"):
session.run("mkdocs", "serve")