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