-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathnoxfile.py
154 lines (125 loc) · 3.84 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
import os
import nox
# nox options
nox.options.reuse_existing_virtualenvs = True
nox.options.venv_backend = "virtualenv"
# 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)
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", "1"
)
@nox.session
def plots(session):
session.install("-e", ".[plot,dev]", silent=False)
session.run("pytest", "--plots", "-n", "0")
@nox.session
def integration(session):
session.install("-e", ".[all,dev]", silent=False)
session.run("pytest", "--integration")
@nox.session
def examples(session):
session.install("-e", ".[all,dev]", silent=False)
session.run("pytest", "--examples")
@nox.session
def notebooks(session):
"""Run the examples tests for Jupyter notebooks."""
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",
"examples/",
)
@nox.session(name="tests")
def run_tests(session):
"""Run all the tests."""
session.install("-e", ".[all,dev]", silent=False)
if PYBOP_SCHEDULED:
session.run("pip", "install", f"pybamm=={PYBAMM_VERSION}", silent=False)
session.run(
"pytest", "--unit", "--integration", "--nbmake", "--examples", "-n", "auto"
)
@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",
)