-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
noxfile.py
215 lines (162 loc) · 5.8 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
# SPDX-FileCopyrightText: 2012 Hynek Schlawack <[email protected]>
#
# SPDX-License-Identifier: MIT
from __future__ import annotations
import os
import re
import shutil
import sys
from pathlib import Path
import nox
DEFAULT_PYTHON = Path(".python-version-default").read_text().strip()
nox.options.sessions = ["pre_commit", "tests", "docs", "mypy"]
nox.options.reuse_existing_virtualenvs = True
nox.options.error_on_external_run = True
nox.needs_version = ">=2024.3.2"
nox.options.default_venv_backend = "uv|virtualenv"
MATCH_PYTHON = re.compile(r"\s+python\: \"(\d\.\d\d)\"").match
# Avoid dependency on a YAML lib using a questionable hack.
for line in Path(".readthedocs.yaml").read_text().splitlines():
if m := MATCH_PYTHON(line):
DOCS_PYTHON = m.group(1)
break
@nox.session
def pre_commit(session: nox.Session) -> None:
session.install("pre-commit")
session.run("pre-commit", "run", "--all-files")
@nox.session(python=["pypy3.10", "3.8", "3.9", "3.10", "3.11", "3.12"])
def tests(session: nox.Session) -> None:
session.install(".[tests]")
# Ensure that rich doesn't add format sequences.
env = {"TERM": "dumb"}
session.run("coverage", "run", "-m", "pytest", *session.posargs, env=env)
session.run("coverage", "run", "-m", "doc2dash", "--version")
if os.environ.get("CI") != "true":
session.notify("coverage_report")
@nox.session
def coverage_report(session: nox.Session) -> None:
session.install("coverage[toml]")
session.run("coverage", "combine")
session.run("coverage", "report")
@nox.session(python=DEFAULT_PYTHON)
def mypy(session: nox.Session) -> None:
session.install(".[typing]", "nox")
session.run("mypy", "src", "docs/update-rtd-versions.py", "noxfile.py")
@nox.session
def rebuild_sample_docs(session: nox.Session) -> None:
session.install(".", "sphinx")
session.chdir(
Path("tests") / "parsers" / "intersphinx" / "example-sphinx-docs"
)
# Awkward name to avoid "_build" / "build" from .gitignore.
session.run("sphinx-build", "-M", "html", "source", "built_docs")
# Clean up stuff we don't need.
built = Path("built_docs")
html = built / "html"
shutil.rmtree(built / "doctrees")
shutil.rmtree(html / "_sources")
shutil.rmtree(html / "_static")
os.remove(html / ".buildinfo")
os.remove(html / "searchindex.js")
@nox.session(python=DOCS_PYTHON)
def docs(session: nox.Session) -> None:
# Needs to be separate when using hashes.
session.install("-r", "requirements/docs.txt")
session.install("-e", ".")
if session.posargs:
session.run("mkdocs", *session.posargs)
else:
session.run("mkdocs", "build", "--clean", "--strict")
@nox.session(python=DOCS_PYTHON)
def pin_docs(session: nox.Session) -> None:
session.install("pip-tools>=6.8.0")
session.run(
"pip-compile",
"--upgrade",
"--allow-unsafe", # otherwise install fails due to setuptools
"--extra", "docs",
"--index-url", "https://pypi.org/simple",
"--generate-hashes",
"--output-file", "requirements/docs.txt",
"pyproject.toml",
) # fmt: skip
@nox.session
def update_rtd_versions(session: nox.Session) -> None:
session.install("urllib3")
session.run("python", "docs/update-rtd-versions.py", "doc2dash")
@nox.session
def oxidize(session: nox.Session) -> None:
"""
Build a doc2dash binary with PyOxidizer.
"""
env = os.environ.copy()
env["PIP_REQUIRE_VIRTUALENV"] = "0"
# standalone_static doesn't work on macOS and gives us musl builds on
# Linux. Since you get one binary on both, dynamic standalone ~should be
# fine~.
if sys.platform == "win32":
flavor = "standalone_static"
else:
flavor = "standalone"
session.install("pyoxidizer")
session.run("pyoxidizer", "-V")
session.run(
"pyoxidizer",
"build",
"--release",
"--var", "flavor", flavor,
"--var", "platform", sys.platform,
env=env,
) # fmt: skip
@nox.session
def pin_for_pyoxidizer(session: nox.Session) -> None:
"""
Pin the Python dependencies that are used for vendoring by PyOxidizer.
"""
session.install("pip-tools>=6.8.0")
session.run(
"pip-compile",
"--upgrade",
"--index-url", "https://pypi.org/simple",
"--generate-hashes",
"--resolver", "backtracking",
"--output-file", f"requirements/pyoxidizer-{sys.platform}.txt",
"pyproject.toml",
) # fmt: skip
@nox.session
def download_and_package_binaries(session: nox.Session) -> None:
"""
Download latest binaries and package them up for release upload.
"""
bins = Path("binaries")
shutil.rmtree(bins, ignore_errors=True)
bins.mkdir()
tag = session.run(
"git", "describe", "--abbrev=0", "--tags", external=True, silent=True
).strip() # type: ignore[union-attr]
print("Downloading for git tag", tag)
run_id = session.run(
"gh", "run", "list",
"--workflow", "Build binaries using pyOxidizer",
"--branch", tag,
"--json", "databaseId",
"--jq", ".[0].databaseId",
external=True,
silent=True,
).strip() # type: ignore[union-attr] # fmt: skip
with session.chdir(bins):
session.run("gh", "run", "download", run_id, external=True)
for arch_path in Path("binaries").glob("*"):
(triple_path,) = tuple(arch_path.glob("*"))
with session.chdir(triple_path / "release/install"):
d = Path("doc2dash")
if d.exists(): # i.e. not Windows
d.chmod(0o755)
session.run(
"zip",
f"../../../../doc2dash.{triple_path.name}.zip",
"COPYING.txt",
"doc2dash",
"doc2dash.exe",
external=True,
)