-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathnoxfile.py
104 lines (84 loc) · 3.21 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
import nox
from nox_poetry import session
# The versions here must be in sync with the github-workflows.
# Or at least support all version from there.
# This list can contain more versions as used by the github workflows to support
# custom local tests
PYTHON_VERSIONS = ["3.8", "3.10"]
SPHINX_VERSIONS = ["5.2.1", "4.5.0"]
DOCUTILS_VERSIONS = ["0.19", "0.17", "0.16", "0.15"]
TEST_DEPENDENCIES = [
"pytest",
"pytest-xdist",
"responses",
"lxml",
"pyparsing!=3.0.4",
"requests-mock",
]
# Some pytest-extension do not work well with pytest-benchmark, so we create our
# own list for benchmarking
BENCHMARK_DEPENDENCIES = [e for e in TEST_DEPENDENCIES if e not in ['"pytest-xdist"']]
BENCHMARK_DEPENDENCIES.append("py")
BENCHMARK_DEPENDENCIES.append("memray")
BENCHMARK_DEPENDENCIES.append("pytest-benchmark")
def is_supported(python: str, sphinx: str, docutils: str) -> bool:
return not (sphinx in ["4.5.0"] and docutils in ["0.19", "0.18"])
def run_tests(session, sphinx, docutils):
session.install(".")
session.install(*TEST_DEPENDENCIES)
session.run("pip", "install", "-r", "docs/requirements.txt", silent=True)
session.run("pip", "install", f"sphinx=={sphinx}", silent=True)
session.run("pip", "install", f"docutils=={docutils}", silent=True)
session.run("echo", "TEST FINAL PACKAGE LIST")
session.run("pip", "freeze")
session.run("make", "test", external=True)
@session(python=PYTHON_VERSIONS)
@nox.parametrize("docutils", DOCUTILS_VERSIONS) # order is important, last options needs to be given first ...
@nox.parametrize("sphinx", SPHINX_VERSIONS) # ... by GH workflow
def tests(session, sphinx, docutils):
if is_supported(session.python, sphinx, docutils):
run_tests(session, sphinx, docutils)
else:
session.skip("unsupported combination")
@session(python="3.10")
def linkcheck(session):
session.install(".")
# LinkCheck can handle rate limits since Sphinx 3.4, which is needed as
# our doc has too many links to GitHub.
session.run("pip", "install", "sphinx==3.5.4", silent=True)
session.run("pip", "install", "-r", "docs/requirements.txt", silent=True)
session.run("make", "docs-linkcheck", external=True)
@session(python="3.10")
def benchmark_time(session):
session.install(".")
session.install(*BENCHMARK_DEPENDENCIES)
session.run("pip", "install", "-r", "docs/requirements.txt", silent=True)
session.run(
"pytest",
"tests/benchmarks",
"-k",
"_time",
"--benchmark-json",
"output.json",
external=True,
)
@session(python="3.10")
def benchmark_memory(session):
session.install(".")
session.install(*BENCHMARK_DEPENDENCIES)
session.run("pip", "install", "-r", "docs/requirements.txt", silent=True)
session.run(
"pytest",
"tests/benchmarks",
"-k",
"_memory",
"--benchmark-json",
"output.json",
external=True,
)
session.run("memray", "flamegraph", "-o", "mem_out.html", "mem_out.bin")
@session(python="3.8")
def pre_commit(session):
session.run_always("poetry", "install", external=True)
session.install("pre-commit")
session.run("pre-commit", "run", "--all-files", external=True)