|
1
|
|
|
# noxfile.py |
|
2
|
|
|
"""Configure nox sessions.""" |
|
3
|
|
|
|
|
4
|
|
|
# standard library |
|
5
|
|
|
import shutil |
|
6
|
|
|
import tempfile |
|
7
|
|
|
from pathlib import Path |
|
8
|
|
|
|
|
9
|
|
|
# third pary packages |
|
10
|
|
|
import nox |
|
11
|
|
|
|
|
12
|
|
|
# local packages |
|
13
|
|
|
|
|
14
|
|
|
# define default sessions: |
|
15
|
|
|
nox.options.sessions = ( |
|
16
|
|
|
"pre-commit", |
|
17
|
|
|
"lint", |
|
18
|
|
|
"pylint", |
|
19
|
|
|
"tests", |
|
20
|
|
|
"xdoctest", |
|
21
|
|
|
"safety", |
|
22
|
|
|
"docs_rebuild", |
|
23
|
|
|
) |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
def install_with_constraints(session, *args, **kwargs): |
|
27
|
|
|
"""Install packages constrained by Poetry's lock file.""" |
|
28
|
|
|
with tempfile.NamedTemporaryFile() as requirements: |
|
29
|
|
|
session.run( |
|
30
|
|
|
"poetry", |
|
31
|
|
|
"export", |
|
32
|
|
|
"--dev", |
|
33
|
|
|
"--format=requirements.txt", |
|
34
|
|
|
"--without-hashes", # requ for working with pip resolver |
|
35
|
|
|
f"--output={requirements.name}", |
|
36
|
|
|
external=True, |
|
37
|
|
|
) |
|
38
|
|
|
session.install(f"--constraint={requirements.name}", *args, **kwargs) |
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
@nox.session(python="3.10") |
|
42
|
|
|
def tests(session): |
|
43
|
|
|
"""Run test suite.""" |
|
44
|
|
|
args = session.posargs or [ |
|
45
|
|
|
"--cov", |
|
46
|
|
|
"-m", |
|
47
|
|
|
"not e2e and not con and not slow", |
|
48
|
|
|
# append exlcuded markers as "and not ..." |
|
49
|
|
|
] |
|
50
|
|
|
session.run("poetry", "install", "--no-dev", external=True) |
|
51
|
|
|
install_with_constraints( |
|
52
|
|
|
session, |
|
53
|
|
|
"coverage[toml]", |
|
54
|
|
|
"pytest", |
|
55
|
|
|
"pytest-cov", |
|
56
|
|
|
"pytest-mock", |
|
57
|
|
|
) |
|
58
|
|
|
session.run("pytest", *args) |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
# locations to run linting and formatting on: |
|
62
|
|
|
locations = "src", "tests", "noxfile.py", "docs/conf.py" |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
@nox.session(python="3.10") |
|
66
|
|
|
def lint(session): |
|
67
|
|
|
"""Lint using flake8.""" |
|
68
|
|
|
args = session.posargs or locations |
|
69
|
|
|
install_with_constraints( |
|
70
|
|
|
session, |
|
71
|
|
|
"darglint", |
|
72
|
|
|
"flake8", |
|
73
|
|
|
"flake8-bandit", |
|
74
|
|
|
"flake8-black", |
|
75
|
|
|
"flake8-bugbear", |
|
76
|
|
|
"flake8-docstrings", |
|
77
|
|
|
"flake8-isort", |
|
78
|
|
|
"flake8-rst-docstrings", |
|
79
|
|
|
"pep8-naming", |
|
80
|
|
|
"pre-commit", |
|
81
|
|
|
"pre-commit-hooks", |
|
82
|
|
|
"pyupgrade", |
|
83
|
|
|
) |
|
84
|
|
|
session.run("flake8", *args) |
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
@nox.session(python="3.10") |
|
88
|
|
|
def pylint(session): |
|
89
|
|
|
"""Lint using pylint.""" |
|
90
|
|
|
args = session.posargs or locations |
|
91
|
|
|
session.run("poetry", "install", "--no-dev", external=True) |
|
92
|
|
|
install_with_constraints( |
|
93
|
|
|
session, |
|
94
|
|
|
"pytest", |
|
95
|
|
|
"requests", |
|
96
|
|
|
"nox", |
|
97
|
|
|
"pylint", |
|
98
|
|
|
) |
|
99
|
|
|
session.run("pylint", "--output-format=colorized", "--recursive=y", *args) |
|
100
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
@nox.session(python="3.10") |
|
103
|
|
|
def black(session): |
|
104
|
|
|
"""Reformat code using black.""" |
|
105
|
|
|
args = session.posargs or locations |
|
106
|
|
|
install_with_constraints(session, "black") |
|
107
|
|
|
session.run("black", *args) |
|
108
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
@nox.session(python="3.10") |
|
111
|
|
|
def xdoctest(session): |
|
112
|
|
|
"""Run examples with xdoctest.""" |
|
113
|
|
|
args = session.posargs or ["all"] |
|
114
|
|
|
session.run("poetry", "install", "--no-dev", external=True) |
|
115
|
|
|
install_with_constraints(session, "xdoctest", "pygments") |
|
116
|
|
|
session.run("python", "-m", "xdoctest", "fogdb", *args) |
|
117
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
@nox.session(python="3.10") |
|
120
|
|
|
def docs(session): |
|
121
|
|
|
"""Build the documentation.""" |
|
122
|
|
|
session.run("poetry", "install", "--no-dev", external=True) |
|
123
|
|
|
install_with_constraints( |
|
124
|
|
|
session, |
|
125
|
|
|
"sphinx", |
|
126
|
|
|
"sphinx-click", |
|
127
|
|
|
"furo", |
|
128
|
|
|
"sphinx-paramlinks", |
|
129
|
|
|
"sphinx-rtd-theme", |
|
130
|
|
|
"pytest", |
|
131
|
|
|
) |
|
132
|
|
|
session.run("sphinx-build", "docs", "docs/_build") |
|
133
|
|
|
|
|
134
|
|
|
|
|
135
|
|
|
@nox.session(python="3.10") |
|
136
|
|
|
def docs_live(session): |
|
137
|
|
|
"""Build and serve the documentation with live reloading on changes.""" |
|
138
|
|
|
args = session.posargs or ["--open-browser", "docs", "docs/_build"] |
|
139
|
|
|
session.run("poetry", "install", "--no-dev", external=True) |
|
140
|
|
|
install_with_constraints( |
|
141
|
|
|
session, |
|
142
|
|
|
"sphinx", |
|
143
|
|
|
"sphinx-autobuild", |
|
144
|
|
|
"sphinx-click", |
|
145
|
|
|
"furo", |
|
146
|
|
|
"sphinx-paramlinks", |
|
147
|
|
|
"sphinx-rtd-theme", |
|
148
|
|
|
"pytest", |
|
149
|
|
|
) |
|
150
|
|
|
|
|
151
|
|
|
build_dir = Path("docs", "_build") |
|
152
|
|
|
if build_dir.exists(): |
|
153
|
|
|
shutil.rmtree(build_dir) |
|
154
|
|
|
|
|
155
|
|
|
session.run("sphinx-autobuild", *args) |
|
156
|
|
|
|
|
157
|
|
|
|
|
158
|
|
|
@nox.session(python="3.10") |
|
159
|
|
|
def docs_rebuild(session): |
|
160
|
|
|
"""Rebuild the entire sphinx documentation.""" |
|
161
|
|
|
session.run("poetry", "install", "--no-dev", external=True) |
|
162
|
|
|
install_with_constraints( |
|
163
|
|
|
session, |
|
164
|
|
|
"sphinx", |
|
165
|
|
|
"sphinx-click", |
|
166
|
|
|
"furo", |
|
167
|
|
|
"sphinx-paramlinks", |
|
168
|
|
|
"sphinx-rtd-theme", |
|
169
|
|
|
"pytest", |
|
170
|
|
|
) |
|
171
|
|
|
build_dir = Path("docs", "_build") |
|
172
|
|
|
if build_dir.exists(): |
|
173
|
|
|
shutil.rmtree(build_dir) |
|
174
|
|
|
|
|
175
|
|
|
session.run("sphinx-build", "docs", "docs/_build") |
|
176
|
|
|
|
|
177
|
|
|
|
|
178
|
|
|
@nox.session(python="3.10") |
|
179
|
|
|
def coverage(session): |
|
180
|
|
|
"""Produce coverage report.""" |
|
181
|
|
|
install_with_constraints(session, "coverage[toml]", "codecov") |
|
182
|
|
|
session.run("coverage", "xml", "--fail-under=0") |
|
183
|
|
|
|
|
184
|
|
|
|
|
185
|
|
|
@nox.session(python="3.10") |
|
186
|
|
|
def codecov(session): |
|
187
|
|
|
"""Produce coverage report and try uploading to codecov.""" |
|
188
|
|
|
install_with_constraints(session, "coverage[toml]", "codecov") |
|
189
|
|
|
session.run("coverage", "xml", "--fail-under=0") |
|
190
|
|
|
session.run("codecov", *session.posargs) |
|
191
|
|
|
|
|
192
|
|
|
|
|
193
|
|
|
@nox.session(name="pre-commit", python="3.10") |
|
194
|
|
|
def precommit(session): |
|
195
|
|
|
"""Lint using pre-commit.""" |
|
196
|
|
|
args = session.posargs or ["run", "--all-files", "--show-diff-on-failure"] |
|
197
|
|
|
session.run("poetry", "install", "--no-dev", external=True) |
|
198
|
|
|
install_with_constraints( |
|
199
|
|
|
session, |
|
200
|
|
|
"darglint", |
|
201
|
|
|
"black", |
|
202
|
|
|
"flake8", |
|
203
|
|
|
"flake8-bandit", |
|
204
|
|
|
"flake8-black", |
|
205
|
|
|
"flake8-bugbear", |
|
206
|
|
|
"flake8-docstrings", |
|
207
|
|
|
"flake8-isort", |
|
208
|
|
|
"flake8-rst-docstrings", |
|
209
|
|
|
"pep8-naming", |
|
210
|
|
|
"pre-commit", |
|
211
|
|
|
"pre-commit-hooks", |
|
212
|
|
|
"pyupgrade", |
|
213
|
|
|
"pytest", |
|
214
|
|
|
"requests", |
|
215
|
|
|
"nox", |
|
216
|
|
|
"pylint", |
|
217
|
|
|
) |
|
218
|
|
|
session.run("pre-commit", *args) |
|
219
|
|
|
|
|
220
|
|
|
|
|
221
|
|
|
@nox.session(python="3.10") |
|
222
|
|
|
def safety(session): |
|
223
|
|
|
"""Scan dependencies for insecure packages using safety.""" |
|
224
|
|
|
with tempfile.NamedTemporaryFile() as requirements: |
|
225
|
|
|
session.run( |
|
226
|
|
|
"poetry", |
|
227
|
|
|
"export", |
|
228
|
|
|
"--dev", |
|
229
|
|
|
"--format=requirements.txt", |
|
230
|
|
|
"--without-hashes", |
|
231
|
|
|
f"--output={requirements.name}", |
|
232
|
|
|
external=True, |
|
233
|
|
|
) |
|
234
|
|
|
session.install("safety") |
|
235
|
|
|
session.run("safety", "check", f"--file={requirements.name}", "--full-report") |
|
236
|
|
|
|