-
Notifications
You must be signed in to change notification settings - Fork 20
/
noxfile.py
188 lines (157 loc) · 4.76 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
import os
import nox
# nox options
nox.options.reuse_existing_virtualenvs = True
nox.options.force_venv_backend = "uv|virtualenv"
nox.needs_version = ">=2024.4.15"
# Environment variables to control CI behaviour for nox sessions
PYBOP_SCHEDULED = int(os.environ.get("PYBOP_SCHEDULED", 0))
PYBAMM_VERSION = os.environ.get("PYBAMM_VERSION", None)
@nox.session
def unit(session):
session.install("-e", ".[all,dev]", silent=False)
if PYBOP_SCHEDULED:
session.run("pip", "install", f"pybamm=={PYBAMM_VERSION}", silent=False)
session.run("pytest", "--unit")
@nox.session
def coverage(session):
session.install("-e", ".[all,dev]", silent=False)
session.install("pip")
if PYBOP_SCHEDULED:
session.run("pip", "install", f"pybamm=={PYBAMM_VERSION}", silent=False)
session.run("pytest", "--unit", "--cov", "--cov-append", "--cov-report=xml")
session.run(
"pytest",
"--integration",
"--cov",
"--cov-append",
"--cov-report=xml",
)
session.run(
"pytest", "--plots", "--cov", "--cov-append", "--cov-report=xml", "-n", "0"
)
@nox.session
def plots(session):
"""Run the tests that generate plots."""
session.install("-e", ".[plot,dev]", silent=False)
session.install("pip")
session.run("pytest", "--plots", "-n", "0")
@nox.session
def integration(session):
"""Run the integration tests."""
session.install("-e", ".[all,dev]", silent=False)
session.run("pytest", "--integration")
@nox.session
def examples(session):
"""Run the examples and notebooks"""
session.install("-e", ".[all,dev]", silent=False)
session.run("pytest", "--examples")
notebooks(session)
@nox.session
def notebooks(session):
"""Run the Jupyter notebooks."""
session.install("openpyxl", "ipywidgets")
session.install("-e", ".[all,dev]", silent=False)
if PYBOP_SCHEDULED:
session.run("pip", "install", f"pybamm=={PYBAMM_VERSION}", silent=False)
session.run(
"pytest",
"--notebooks",
"--nbmake",
"--nbmake-timeout=1000",
"examples/",
)
@nox.session(name="notebooks-overwrite")
def notebooks_overwrite(session):
"""Run the Jupyter notebooks."""
session.install("openpyxl", "ipywidgets")
session.install("-e", ".[all,dev]", silent=False)
if PYBOP_SCHEDULED:
session.run("pip", "install", f"pybamm=={PYBAMM_VERSION}", silent=False)
session.run(
"pytest",
"--notebooks",
"--nbmake",
"--overwrite",
"--nbmake-timeout=1000",
"examples/",
)
@nox.session(name="tests")
def run_tests(session):
"""Run all or a user-defined set of tests."""
session.install("-e", ".[all,dev]", silent=False)
if PYBOP_SCHEDULED:
session.run("pip", "install", f"pybamm=={PYBAMM_VERSION}", silent=False)
specific_tests = session.posargs if session.posargs else []
session.run(
"pytest",
"--unit",
"--integration",
"--nbmake",
"--examples",
"-n",
"auto",
*specific_tests,
)
@nox.session(name="doctest")
def run_doc_tests(session):
"""
Checks if the documentation can be built, runs any doctests (currently not
used).
"""
session.install("-e", ".[plot,docs,dev]", silent=False)
session.run("pytest", "--docs", "-n", "0")
@nox.session(name="pre-commit")
def lint(session):
"""
Check all files against the defined pre-commit hooks.
Credit: PyBaMM Team
"""
session.install("pre-commit", silent=False)
session.run("pre-commit", "run", "--all-files")
@nox.session(name="quick", reuse_venv=True)
def run_quick(session):
"""
Run integration tests, unit tests, and doctests sequentially
Credit: PyBaMM Team
"""
run_tests(session)
run_doc_tests(session)
@nox.session
def benchmarks(session):
"""Run the benchmarks."""
session.install("-e", ".[all,dev]", silent=False)
session.install("asv[virtualenv]")
session.run("asv", "run", "--show-stderr", "--python=same")
@nox.session
def docs(session):
"""
Build the documentation and load it in a browser tab, rebuilding on changes.
Credit: PyBaMM Team
"""
envbindir = session.bin
session.install("-e", ".[all,docs]", silent=False)
session.chdir("docs")
# Local development
if session.interactive:
session.run(
"sphinx-autobuild",
"-j",
"auto",
"--open-browser",
"-qT",
".",
f"{envbindir}/../tmp/html",
)
# Runs in CI only, treating warnings as errors
else:
session.run(
"sphinx-build",
"-j",
"auto",
"-b",
"html",
"--keep-going",
".",
"_build/html",
)