-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnoxfile.py
222 lines (205 loc) · 6.18 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
import os
import tempfile
import nox
# Separating Black away from the rest of the sessions
nox.options.sessions = "lint", "safety", "tests"
code_locations = "datagateway_api", "test", "util", "noxfile.py"
def install_with_constraints(session, *args, **kwargs):
# Auto file deletion is turned off to prevent a PermissionError experienced on
# Windows
with tempfile.NamedTemporaryFile(delete=False) as requirements:
session.run(
"poetry",
"export",
"--dev",
"--format=requirements.txt",
"--without-hashes",
f"--output={requirements.name}",
external=True,
)
session.install(f"--constraint={requirements.name}", *args, **kwargs)
try:
# Due to delete=False, the file must be deleted manually
requirements.close()
os.unlink(requirements.name)
except IOError:
session.log("Error: The temporary requirements file could not be closed")
@nox.session(reuse_venv=True)
def black(session):
args = session.posargs or code_locations
install_with_constraints(session, "black")
session.run("black", *args, external=True)
@nox.session(reuse_venv=True)
def lint(session):
args = session.posargs or code_locations
install_with_constraints(
session,
"flake8",
"flake8-bandit",
"flake8-black",
"flake8-broken-line",
"flake8-bugbear",
"flake8-builtins",
"flake8-commas",
"flake8-comprehensions",
"flake8-import-order",
"flake8-logging-format",
"pep8-naming",
)
session.run("flake8", *args)
@nox.session(reuse_venv=True)
def safety(session):
install_with_constraints(session, "safety")
with tempfile.NamedTemporaryFile(delete=False) as requirements:
session.run(
"poetry",
"export",
"--dev",
"--format=requirements.txt",
"--without-hashes",
f"--output={requirements.name}",
external=True,
)
# Ignore vulnerabilities as the patched versions of dependencies that they
# relate to don't support Python 3.6 which is still required for production
session.run(
"safety",
"check",
f"--file={requirements.name}",
"--full-report",
"--ignore",
"50916",
"--ignore",
"51457",
"--ignore",
"51668",
"--ignore",
"52322",
"--ignore",
"52518",
"--ignore",
"53325",
"--ignore",
"53326",
"--ignore",
"54456",
"--ignore",
"55261",
"--ignore",
"58910",
"--ignore",
"58755",
"--ignore",
"59062",
"--ignore",
"59473",
"--ignore",
"60223",
"--ignore",
"60224",
"--ignore",
"60225",
"--ignore",
"60350",
"--ignore",
"60789",
"--ignore",
"60841",
"--ignore",
"61416",
"--ignore",
"62019",
"--ignore",
"62151",
"--ignore",
"62451",
"--ignore",
"62452",
"--ignore",
"62556",
"--ignore",
"63687",
"--ignore",
"64121",
"--ignore",
"64227",
"--ignore",
"65212",
"--ignore",
"64484",
"--ignore",
"65278",
"--ignore",
"65510",
"--ignore",
"65647",
"--ignore",
"66704",
"--ignore",
"66777",
"--ignore",
"67892",
"--ignore",
"70612",
"--ignore",
"70624",
"--ignore",
"70790",
"--ignore",
"70982",
"--ignore",
"70993",
"--ignore",
"71064",
"--ignore",
"71083",
"--ignore",
"71219",
"--ignore",
"71590",
"--ignore",
"71591",
"--ignore",
"71594",
"--ignore",
"71595",
"--ignore",
"71680",
"--ignore",
"71681",
"--ignore",
"71684",
"--ignore",
"72132",
"--ignore",
"72731",
"--ignore",
"72981",
)
try:
# Due to delete=False, the file must be deleted manually
requirements.close()
os.unlink(requirements.name)
except IOError:
session.log("Error: The temporary requirements file could not be closed")
@nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10"], reuse_venv=True)
def unit_tests(session):
args = session.posargs
# Explicitly installing/downgrading setuptools is done to fix poetry install on 3.8+
# as per https://github.com/pypa/setuptools/issues/4483#issuecomment-2236327987.
# A cleaner fix would be to upgrade the packaging library to 22.0+ (as per
# https://github.com/pypa/setuptools/issues/4483#issuecomment-2236339726) but this
# cannot be done on this repo until support for Python 3.6 is dropped
if session.python in ["3.8", "3.9", "3.10"]:
session.run("pip", "install", "--upgrade", "setuptools==70.0.0")
session.run("poetry", "install", external=True)
session.run("pytest", "test/unit", *args)
@nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10"], reuse_venv=True)
def integration_tests(session):
args = session.posargs
# Explicit downgrade of setuptools also performed here. See explanation in
# `unit_tests()`
if session.python in ["3.8", "3.9", "3.10"]:
session.run("pip", "install", "--upgrade", "setuptools==70.0.0")
session.run("poetry", "install", external=True)
session.run("pytest", "test/integration", *args)