This repository has been archived by the owner on Dec 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnoxfile.py
317 lines (236 loc) · 6.33 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
"""Configure nox."""
import functools
import pathlib
import nox
PYTHON_DEFAULT_VERSION = "3.10"
PYTHON_VERSIONS = ["3.10", "3.11", "3.12"]
SOURCE_DIRECTORY = pathlib.Path("src")
DIST_DIRECTORY = pathlib.Path("dist")
DOCS_DIRECTORY = pathlib.Path("docs")
PYTHON_SCRIPT_PATHS = SOURCE_DIRECTORY.glob("**/*.py")
PYTHON_SCRIPTS = [str(SCRIPT_PATH) for SCRIPT_PATH in PYTHON_SCRIPT_PATHS]
GENERAL_SESSION_DECORATOR = functools.partial(nox.session, venv_backend="conda", reuse_venv=True)
FORMAT_SESSION_DECORATOR = functools.partial(
GENERAL_SESSION_DECORATOR, python=PYTHON_DEFAULT_VERSION, tags=["format"]
)
LINT_SESSION_DECORATOR = functools.partial(
GENERAL_SESSION_DECORATOR, python=PYTHON_VERSIONS, tags=["lint"]
)
RELEASE_SESSION_DECORATOR = functools.partial(
GENERAL_SESSION_DECORATOR, python=PYTHON_DEFAULT_VERSION, tags=["release"]
)
TEST_SESSION_DECORATOR = functools.partial(
GENERAL_SESSION_DECORATOR, python=PYTHON_VERSIONS, tags=["test"]
)
@FORMAT_SESSION_DECORATOR
def autoflake(session: nox.Session) -> None:
"""Run autoflake.
Parameters
----------
session : nox.Session
nox Session object
"""
session.install("autoflake")
session.run("autoflake", *PYTHON_SCRIPTS)
@LINT_SESSION_DECORATOR
def bandit(session: nox.Session) -> None:
"""Run bandit.
Parameters
----------
session : nox.Session
nox Session object
"""
session.install("bandit")
session.run(
"bandit",
"--recursive",
"--severity-level",
"high",
"--confidence-level",
"high",
str(SOURCE_DIRECTORY),
)
@FORMAT_SESSION_DECORATOR
def black(session: nox.Session) -> None:
"""Run black.
Parameters
----------
session : nox.Session
nox Session object
"""
session.install("black")
session.run("black", *PYTHON_SCRIPTS)
@FORMAT_SESSION_DECORATOR
def blacken_docs(session: nox.Session) -> None:
"""Run blacken-docs.
Parameters
----------
session : nox.Session
nox Session object
"""
session.install("blacken-docs")
session.run("blacken-docs", *PYTHON_SCRIPTS)
@RELEASE_SESSION_DECORATOR
def build(session: nox.Session) -> None:
"""Run build.
Parameters
----------
session : nox.Session
nox Session object
"""
session.install("build", "wheel")
session.run("python3", "-m", "build", "--outdir", f"{DIST_DIRECTORY.name}")
session.notify("twine")
@TEST_SESSION_DECORATOR
def coverage(session: nox.Session) -> None:
"""Run coverage.
Parameters
----------
session : nox.Session
nox Session object
"""
session.install("coverage[toml]")
session.run("coverage", "report")
session.run("coverage", "html")
session.run("coverage", "xml")
@FORMAT_SESSION_DECORATOR
def docformatter(session: nox.Session) -> None:
"""Run docformatter.
Parameters
----------
session : nox.Session
nox Session object
"""
session.install("docformatter[tomli]")
session.run("docformatter", *PYTHON_SCRIPTS)
@LINT_SESSION_DECORATOR
def flake8(session: nox.Session) -> None:
"""Run flake8.
Parameters
----------
session : nox.Session
nox Session object
"""
session.install("flake8")
session.run(
"flake8",
"--extend-ignore",
"E203",
"--per-file-ignores",
"__init__.py:F401",
"--max-line-length",
"99",
*PYTHON_SCRIPTS,
)
@FORMAT_SESSION_DECORATOR
def isort(session: nox.Session) -> None:
"""Run isort.
Parameters
----------
session : nox.Session
nox Session object
"""
session.install("isort")
session.run("isort", *PYTHON_SCRIPTS)
@LINT_SESSION_DECORATOR
def mypy(session: nox.Session) -> None:
"""Run mypy.
Parameters
----------
session : nox.Session
nox Session object
"""
session.install("mypy", "pydantic")
session.run("mypy")
@GENERAL_SESSION_DECORATOR(python=PYTHON_DEFAULT_VERSION)
def pre_commit(session: nox.Session) -> None:
"""Run pre-commit.
Parameters
----------
session : nox.Session
nox Session object
"""
session.install("pre-commit")
session.run(
"pre-commit",
"run",
"--color",
"always",
"--verbose",
"--all-files",
"--hook-stage",
"manual",
)
@LINT_SESSION_DECORATOR
def pylint(session: nox.Session) -> None:
"""Run pylint.
Parameters
----------
session : nox.Session
nox Session object
"""
session.install("pylint")
session.run("pylint", "--disable", "import-error", str(SOURCE_DIRECTORY))
@LINT_SESSION_DECORATOR
def pyright(session: nox.Session) -> None:
"""Run pyright.
Parameters
----------
session : nox.Session
nox Session object
"""
session.install("pyright")
session.run("pyright")
@TEST_SESSION_DECORATOR
def pytest(session: nox.Session) -> None:
"""Run pytest.
Parameters
----------
session : nox.Session
nox Session object
"""
session.install("-e", ".[test]")
session.run("coverage", "run")
session.notify("coverage")
@FORMAT_SESSION_DECORATOR
def pyupgrade(session: nox.Session) -> None:
"""Run pyupgrade.
Parameters
----------
session : nox.Session
nox Session object
"""
session.install("pyupgrade")
session.run("pyupgrade", "--py310-plus", *PYTHON_SCRIPTS)
@GENERAL_SESSION_DECORATOR(python=PYTHON_DEFAULT_VERSION)
def sphinx(session: nox.Session) -> None:
"""Run sphinx.
Parameters
----------
session : nox.Session
nox Session object
"""
session.install("-e", ".[doc]")
with session.chdir("docs"):
session.run("sphinx-build", "-b", "html", "source", "build")
@RELEASE_SESSION_DECORATOR
def twine(session: nox.Session) -> None:
"""Run twine.
Parameters
----------
session : nox.Session
nox Session object
"""
session.install("twine")
session.run("twine", "check", f"{DIST_DIRECTORY.name}/*")
session.run("twine", "upload", f"{DIST_DIRECTORY.name}/*")
@LINT_SESSION_DECORATOR
def vulture(session: nox.Session) -> None:
"""Run vulture.
Parameters
----------
session : nox.Session
nox Session object
"""
session.install("vulture")
session.run("vulture")