-
Notifications
You must be signed in to change notification settings - Fork 499
/
noxfile.py
214 lines (172 loc) · 5.74 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
import subprocess
from pathlib import Path
from sys import platform
import hashlib
import nox # type: ignore
import glob
nox.options.reuse_existing_virtualenvs = True
nox.options.sessions = ["tests", "lint", "docs"]
python = ["3.12"]
prettier_command = [
"npx",
"--parser",
"typescript",
"--config",
".prettierrc.js",
"gdbgui/src/js/**/*",
]
doc_dependencies = [".", "mkdocs", "mkdocs-material"]
lint_dependencies = [
"black==22.10.0",
"vulture",
"flake8",
"mypy==1.6.1",
"check-manifest",
]
vulture_whitelist = ".vulture_whitelist.py"
files_to_lint = ["gdbgui", "tests"] + [str(p) for p in Path(".").glob("*.py")]
files_to_lint.remove(vulture_whitelist)
publish_deps = ["setuptools", "wheel", "twine"]
@nox.session(reuse_venv=True)
def python_tests(session):
session.install(".", "pytest", "pytest-cov")
tests = session.posargs or ["tests"]
session.run(
"pytest", "--cov=gdbgui", "--cov-config", ".coveragerc", "--cov-report=", *tests
)
session.notify("cover")
@nox.session(reuse_venv=True)
def js_tests(session):
session.run("yarn", "install", external=True)
session.run("yarn", "test", external=True)
session.run("yarn", "build", external=True)
@nox.session(reuse_venv=True, python=python)
def tests(session):
python_tests(session)
js_tests(session)
@nox.session(reuse_venv=True)
def cover(session):
"""Coverage analysis"""
session.install("coverage")
session.run(
"coverage",
"report",
"--show-missing",
"--omit=gdbgui/SSLify.py",
"--fail-under=20",
)
session.run("coverage", "erase")
@nox.session()
def vulture(session):
"""Find dead code"""
session.install("vulture")
session.run(
"vulture",
"--ignore-decorators",
"@app.*,@socketio.*,@nox.*,@blueprint.*",
*files_to_lint,
vulture_whitelist,
*session.posargs,
)
@nox.session()
def lint(session):
session.install(".", *lint_dependencies)
session.run("black", "--check", *files_to_lint)
session.run("flake8", *files_to_lint)
session.run("mypy", *files_to_lint)
vulture(session)
session.run(
"check-manifest", "--ignore", "gdbgui/static/js/*", "--ignore", "*pycache*"
)
session.run("python", "setup.py", "check", "--metadata", "--strict")
session.run(*prettier_command, "--check", external=True)
@nox.session(reuse_venv=True)
def autoformat(session):
session.install(*lint_dependencies)
session.run("black", *files_to_lint)
session.run(*prettier_command, "--write", external=True)
@nox.session(reuse_venv=True)
def docs(session):
session.install(*doc_dependencies)
session.run("mkdocs", "build")
@nox.session(reuse_venv=True)
def develop(session):
session.install("-e", ".")
session.run("yarn", "install", external=True)
print("Watching JavaScript file and Python files for changes")
with subprocess.Popen(["yarn", "start"]):
session.run("python", "-m", "gdbgui")
@nox.session(reuse_venv=True)
def serve(session):
session.install("-e", ".")
session.run("python", "-m", "gdbgui", *session.posargs)
@nox.session(reuse_venv=True)
def build(session):
"""Build python distribution (sdist and wheels)"""
session.install(*publish_deps)
session.run("rm", "-rf", "dist", "build", external=True)
session.run("yarn", external=True)
session.run("yarn", "build", external=True)
session.run("python", "setup.py", "--quiet", "sdist", "bdist_wheel")
session.run("twine", "check", "dist/*")
for built_package in glob.glob("dist/*"):
# ensure we can install the built distributions
session.run("pip", "install", "--force-reinstall", built_package)
@nox.session(reuse_venv=True)
def publish(session):
session.install(*publish_deps)
build(session)
print("REMINDER: Has the changelog been updated?")
session.run("python", "-m", "twine", "upload", "dist/*")
publish_docs(session)
@nox.session(reuse_venv=True)
def watch_docs(session):
session.install(*doc_dependencies)
session.run("mkdocs", "serve")
@nox.session(reuse_venv=True)
def publish_docs(session):
session.install(*doc_dependencies)
session.run("mkdocs", "gh-deploy")
@nox.session(reuse_venv=True, python="3.12")
def build_executables_current_platform(session):
session.run("yarn", "install", external=True)
session.run("yarn", "build", external=True)
session.install(".", "PyInstaller==6.1")
session.run("python", "make_executable.py")
session.notify("build_pex")
@nox.session(reuse_venv=True)
def build_executables_mac(session):
if not platform.startswith("darwin"):
raise Exception(f"Unexpected platform {platform}")
session.notify("build_executables_current_platform")
@nox.session(reuse_venv=True)
def build_executables_linux(session):
if not platform.startswith("linux"):
raise Exception(f"Unexpected platform {platform}")
session.notify("build_executables_current_platform")
@nox.session(reuse_venv=True)
def build_executable_windows(session):
if not platform.startswith("win32"):
raise Exception(f"Unexpected platform {platform}")
session.notify("build_executables_current_platform")
@nox.session
def build_pex(session):
"""Builds a pex of gdbgui"""
# NOTE: frontend must be built before running this
session.install("pex")
pex_path = Path("build/executable/gdbgui.pex")
session.run(
"pex",
".",
"--console-script",
"gdbgui",
"--output-file",
str(pex_path),
"--sh-boot",
"--validate-entry-point",
external=True,
)
checksum = hashlib.md5(pex_path.read_bytes()).hexdigest()
with open(f"{pex_path}.md5", "w+") as f:
f.write(checksum + "\n")