forked from pybamm-team/PyBaMM
-
Notifications
You must be signed in to change notification settings - Fork 1
/
noxfile.py
204 lines (172 loc) · 6.06 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
import nox
import os
import sys
from pathlib import Path
# Options to modify nox behaviour
nox.options.reuse_existing_virtualenvs = True
if sys.platform != "win32":
nox.options.sessions = ["pre-commit", "pybamm-requires", "unit"]
else:
nox.options.sessions = ["pre-commit", "unit"]
homedir = os.getenv("HOME")
PYBAMM_ENV = {
"SUNDIALS_INST": f"{homedir}/.local",
"LD_LIBRARY_PATH": f"{homedir}/.local/lib",
}
VENV_DIR = Path("./venv").resolve()
def set_environment_variables(env_dict, session):
"""
Sets environment variables for a nox session object.
Parameters
-----------
session : nox.Session
The session to set the environment variables for.
env_dict : dict
A dictionary of environment variable names and values.
"""
for key, value in env_dict.items():
session.env[key] = value
@nox.session(name="pybamm-requires")
def run_pybamm_requires(session):
"""Download, compile, and install the build-time requirements for Linux and macOS: the SuiteSparse and SUNDIALS libraries."""
set_environment_variables(PYBAMM_ENV, session=session)
if sys.platform != "win32":
session.install("wget", "cmake", silent=False)
session.run("python", "scripts/install_KLU_Sundials.py")
if not os.path.exists("./pybind11"):
session.run(
"git",
"clone",
"https://github.com/pybind/pybind11.git",
"pybind11/",
external=True,
)
else:
session.error("nox -s pybamm-requires is only available on Linux & macOS.")
@nox.session(name="coverage")
def run_coverage(session):
"""Run the coverage tests and generate an XML report."""
set_environment_variables(PYBAMM_ENV, session=session)
session.install("coverage", silent=False)
if sys.platform != "win32":
session.install("-e", ".[all,odes,jax]", silent=False)
else:
session.install("-e", ".[all]", silent=False)
session.run("coverage", "run", "run-tests.py", "--nosub")
session.run("coverage", "combine")
session.run("coverage", "xml")
@nox.session(name="integration")
def run_integration(session):
"""Run the integration tests."""
set_environment_variables(PYBAMM_ENV, session=session)
if sys.platform != "win32":
session.install("-e", ".[all,odes,jax]", silent=False)
else:
session.install("-e", ".[all]", silent=False)
session.run("python", "run-tests.py", "--integration")
@nox.session(name="doctests")
def run_doctests(session):
"""Run the doctests and generate the output(s) in the docs/build/ directory."""
session.install("-e", ".[all,docs]", silent=False)
session.run("python", "run-tests.py", "--doctest")
@nox.session(name="unit")
def run_unit(session):
"""Run the unit tests."""
set_environment_variables(PYBAMM_ENV, session=session)
if sys.platform != "win32":
session.install("-e", ".[all,odes,jax]", silent=False)
else:
session.install("-e", ".[all]", silent=False)
session.run("python", "run-tests.py", "--unit")
@nox.session(name="examples")
def run_examples(session):
"""Run the examples tests for Jupyter notebooks."""
set_environment_variables(PYBAMM_ENV, session=session)
session.install("-e", ".[all,dev]", silent=False)
notebooks_to_test = session.posargs if session.posargs else []
session.run("pytest", "--nbmake", *notebooks_to_test, external=True)
@nox.session(name="scripts")
def run_scripts(session):
"""Run the scripts tests for Python scripts."""
set_environment_variables(PYBAMM_ENV, session=session)
session.install("-e", ".[all]", silent=False)
session.run("python", "run-tests.py", "--scripts")
@nox.session(name="dev")
def set_dev(session):
"""Install PyBaMM in editable mode."""
set_environment_variables(PYBAMM_ENV, session=session)
session.install("virtualenv", "cmake")
session.run("virtualenv", os.fsdecode(VENV_DIR), silent=True)
python = os.fsdecode(VENV_DIR.joinpath("bin/python"))
session.run(
python,
"-m",
"pip",
"install",
"--upgrade",
"pip",
"setuptools",
"wheel",
external=True,
)
if sys.platform == "linux":
session.run(
python,
"-m",
"pip",
"install",
"-e",
".[all,dev,jax,odes]",
external=True,
)
else:
session.run(python, "-m", "pip", "install", "-e", ".[all,dev]", external=True)
@nox.session(name="tests")
def run_tests(session):
"""Run the unit tests and integration tests sequentially."""
set_environment_variables(PYBAMM_ENV, session=session)
if sys.platform != "win32":
session.install("-e", ".[all,odes,jax]", silent=False)
else:
session.install("-e", ".[all]", silent=False)
session.run("python", "run-tests.py", "--all")
@nox.session(name="docs")
def build_docs(session):
"""Build the documentation and load it in a browser tab, rebuilding on changes."""
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",
"-W",
"--keep-going",
".",
f"{envbindir}/../tmp/html",
)
@nox.session(name="pre-commit")
def lint(session):
"""Check all files against the defined pre-commit hooks."""
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"""
run_tests(session)
run_doctests(session)