forked from microsoft/lisa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
noxfile.py
245 lines (194 loc) · 6.22 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
"""
Nox configuration file
See https://nox.thea.codes/en/stable/config.html
"""
import platform
import sys
from pathlib import Path
import nox
import toml
CURRENT_PYTHON = sys.executable or f"{sys.version_info.major}.{sys.version_info.minor}"
ON_WINDOWS = platform.system() == "Windows"
CONFIG = toml.load("pyproject.toml")
DEPENDENCIES = CONFIG["project"]["dependencies"]
OPTIONAL_DEPENDENCIES = CONFIG["project"]["optional-dependencies"]
NOX_DEPENDENCIES = ("nox", "toml")
# Global options
nox.options.stop_on_first_error = False
nox.options.error_on_missing_interpreters = False
# Require support for tags
nox.needs_version = ">=2022.8.7"
# --- Testing ---
@nox.session(python=CURRENT_PYTHON, tags=["test", "all"])
def test(session: nox.Session) -> None:
"""Run tests"""
session.install(
*DEPENDENCIES, *OPTIONAL_DEPENDENCIES["azure"], *OPTIONAL_DEPENDENCIES["test"]
)
session.run("python", "-m", "unittest", "discover")
@nox.session(python=CURRENT_PYTHON, tags=["test", "all"])
def example(session: nox.Session) -> None:
"""Run example"""
session.install("--editable", ".", "--config-settings", "editable_mode=compat")
session.run("lisa", "--debug")
@nox.session(python=CURRENT_PYTHON, tags=["all"])
def coverage(session: nox.Session) -> None:
"""Check test coverage"""
session.install(
*DEPENDENCIES,
*OPTIONAL_DEPENDENCIES["azure"],
*OPTIONAL_DEPENDENCIES["test"],
"coverage",
)
session.run("coverage", "erase")
session.run("coverage", "run", "-m", "lisa")
session.run("coverage", "run", "--append", "-m", "unittest", "discover")
session.run("coverage", "report")
# --- Formatting ---
@nox.session(python=CURRENT_PYTHON, tags=["format", "all"])
def black(session: nox.Session) -> None:
"""Run black"""
session.install(*OPTIONAL_DEPENDENCIES["black"])
session.run("black", ".")
@nox.session(python=CURRENT_PYTHON, tags=["format", "all"])
def isort(session: nox.Session) -> None:
"""Run isort"""
session.install(*OPTIONAL_DEPENDENCIES["isort"])
session.run("isort", ".")
# --- Linting ---
@nox.session(python=CURRENT_PYTHON, tags=["lint", "all"])
def flake8(session: nox.Session) -> None:
"""Run flake8"""
session.install(
*OPTIONAL_DEPENDENCIES["black"],
*OPTIONAL_DEPENDENCIES["flake8"],
*OPTIONAL_DEPENDENCIES["isort"],
)
session.run("flake8")
@nox.session(python=CURRENT_PYTHON, tags=["lint", "all"])
def pylint(session: nox.Session) -> None:
"""Run pylint"""
session.install(
*DEPENDENCIES,
*NOX_DEPENDENCIES,
*OPTIONAL_DEPENDENCIES["aws"],
*OPTIONAL_DEPENDENCIES["azure"],
*OPTIONAL_DEPENDENCIES["baremetal"],
*OPTIONAL_DEPENDENCIES["libvirt"],
*OPTIONAL_DEPENDENCIES["pylint"],
*OPTIONAL_DEPENDENCIES["typing"],
)
session.run(
"pylint",
"lisa",
"microsoft",
"examples",
"selftests",
"docs/tools",
"docs",
"noxfile.py",
)
# --- Typing ---
@nox.session(python=CURRENT_PYTHON, tags=["typing", "all"])
def mypy(session: nox.Session) -> None:
"""Run mypy"""
session.install(
*DEPENDENCIES,
*OPTIONAL_DEPENDENCIES["azure"],
*OPTIONAL_DEPENDENCIES["mypy"],
*OPTIONAL_DEPENDENCIES["typing"],
*NOX_DEPENDENCIES,
)
session.run("mypy", "-p", "lisa")
session.run("mypy", "docs", "microsoft")
session.run("mypy", "noxfile.py")
# --- Utility ---
@nox.session(python=CURRENT_PYTHON, tags=["all"])
def docs(session: nox.Session) -> None:
"""Build docs"""
session.install(
*DEPENDENCIES,
*OPTIONAL_DEPENDENCIES["docs"],
*OPTIONAL_DEPENDENCIES["azure"],
*OPTIONAL_DEPENDENCIES["aws"],
)
session.run("sphinx-build", "-Eab", "html", "docs", "docs/_build/html")
@nox.session(python=CURRENT_PYTHON)
def dev(session: nox.Session) -> None:
"""
Create virtual environment for development
Positional arguments determine which extras to install, default azure,libvirt
Example:
nox -vs dev -- libvirt
"""
# Determine which extra dependencies to install
if session.posargs:
for arg in session.posargs:
if arg not in OPTIONAL_DEPENDENCIES:
session.error(f"'{arg}' is not a valid extra dependency group")
extras = ",".join(session.posargs)
elif ON_WINDOWS:
extras = "azure"
else:
extras = "azure,libvirt"
# Determine paths
venv_path = ".venv"
if ON_WINDOWS:
venv_python = str(Path(venv_path).resolve() / "Scripts" / "python.exe")
else:
venv_python = str(Path(venv_path).resolve() / "bin" / "python")
# Install virtualenv, it's used to create the final virtual environment
session.install("virtualenv")
# Create virtual environment
session.run(
"virtualenv", "--python", str(session.python), "--prompt", "lisa", venv_path
)
# Make sure pip and setuptools are up-to-date
session.run(
venv_python,
"-m",
"pip",
"install",
"--upgrade",
"pip",
"setuptools",
external=True,
)
# Editable install of lisa and dependencies
session.run(
venv_python,
"-m",
"pip",
"install",
"--editable",
f".[{extras}]",
# Workaround for non-package directories (microsoft, examples)
"--config-settings",
"editable_mode=compat",
external=True,
)
# Install dev tools
session.run(
venv_python,
"-m",
"pip",
"install",
*OPTIONAL_DEPENDENCIES["black"],
*OPTIONAL_DEPENDENCIES["flake8"],
*OPTIONAL_DEPENDENCIES["isort"],
*OPTIONAL_DEPENDENCIES["mypy"],
*OPTIONAL_DEPENDENCIES["pylint"],
*OPTIONAL_DEPENDENCIES["typing"],
*NOX_DEPENDENCIES,
external=True,
)
# Instruct user how to activate environment
print("\nVirtual environment installed\nTo activate:\n")
if ON_WINDOWS:
print(
f" {venv_path}\\Scripts\\activate.bat\n"
" OR\n"
f" {venv_path}\\Scripts\\activate.ps1\n"
)
else:
print(f" source {venv_path}/bin/activate\n")