forked from saltstack/salt
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdocs.py
310 lines (289 loc) · 8.25 KB
/
docs.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
"""
These commands are used to generate Salt's manpages.
"""
# pylint: disable=resource-leakage,broad-except,3rd-party-module-not-gated
from __future__ import annotations
import logging
import os
import pathlib
import shutil
import sys
from ptscripts import Context, command_group
from ptscripts.models import VirtualEnvPipConfig
import tools.utils
log = logging.getLogger(__name__)
# Define the command group
docs = command_group(
name="docs",
help="Manpages tools",
description=__doc__,
venv_config=VirtualEnvPipConfig(
requirements_files=[
tools.utils.REPO_ROOT / "requirements" / "base.txt",
tools.utils.REPO_ROOT / "requirements" / "zeromq.txt",
tools.utils.REPO_ROOT
/ "requirements"
/ "static"
/ "ci"
/ "py{}.{}".format(*sys.version_info)
/ "docs.txt",
],
install_args=[
"--constraint",
str(
tools.utils.REPO_ROOT
/ "requirements"
/ "static"
/ "pkg"
/ "py{}.{}".format(*sys.version_info)
/ "linux.txt"
),
],
),
)
@docs.command(
name="man",
arguments={
"no_clean": {
"help": "Don't cleanup prior to building",
},
"no_color": {
"help": "Disable colored output.",
},
},
)
def man(ctx: Context, no_clean: bool = False, no_color: bool = False):
if no_clean is False:
ctx.run("make", "clean", cwd="doc/", check=True)
opts = [
"-W",
"-j",
"auto",
"--keep-going",
]
if no_color is False:
opts.append("--color")
ctx.run(
"make",
"man",
f"SPHINXOPTS={' '.join(opts)}",
cwd="doc/",
check=True,
)
for root, dirs, files in os.walk("doc/_build/man"):
for file in files:
shutil.copy(os.path.join(root, file), os.path.join("doc/man", file))
@docs.command(
name="html",
arguments={
"no_clean": {
"help": "Don't cleanup prior to building",
},
"no_color": {
"help": "Disable colored output.",
},
"archive": {
"help": "Compress the generated documentation into the provided archive.",
},
},
)
def html(
ctx: Context,
no_clean: bool = False,
no_color: bool = False,
archive: pathlib.Path = os.environ.get("ARCHIVE_FILENAME"), # type: ignore[assignment]
):
if no_clean is False:
ctx.run("make", "clean", cwd="doc/", check=True)
opts = [
"-W",
"-j",
"auto",
"--keep-going",
]
if no_color is False:
opts.append("--color")
ctx.run(
"make",
"html",
f"SPHINXOPTS={' '.join(opts)}",
cwd="doc/",
check=True,
)
github_output = os.environ.get("GITHUB_OUTPUT")
if archive is not None:
ctx.info(f"Compressing the generated documentation to '{archive}'...")
ctx.run("tar", "caf", str(archive.resolve()), ".", cwd="doc/_build/html")
if github_output is not None:
with open(github_output, "a", encoding="utf-8") as wfh:
wfh.write(
"has-artifacts=true\n"
f"artifact-name={archive.resolve().name}\n"
f"artifact-path={archive.resolve()}\n"
)
elif github_output is not None:
artifact = tools.utils.REPO_ROOT / "doc" / "_build" / "html"
if "LATEST_RELEASE" in os.environ:
artifact_name = f"salt-{os.environ['LATEST_RELEASE']}-docs-html"
else:
artifact_name = "salt-docs-html"
with open(github_output, "a", encoding="utf-8") as wfh:
wfh.write(
"has-artifacts=true\n"
f"artifact-name={artifact_name}\n"
f"artifact-path={artifact.resolve()}\n"
)
@docs.command(
name="epub",
arguments={
"no_clean": {
"help": "Don't cleanup prior to building",
},
"no_color": {
"help": "Disable colored output.",
},
},
)
def epub(ctx: Context, no_clean: bool = False, no_color: bool = False):
if no_clean is False:
ctx.run("make", "clean", cwd="doc/", check=True)
opts = [
"-j",
"auto",
"--keep-going",
]
if no_color is False:
opts.append("--color")
ctx.run(
"make",
"epub",
f"SPHINXOPTS={' '.join(opts)}",
cwd="doc/",
check=True,
)
artifact = tools.utils.REPO_ROOT / "doc" / "_build" / "epub" / "Salt.epub"
if "LATEST_RELEASE" in os.environ:
shutil.move(
artifact, artifact.parent / f"Salt-{os.environ['LATEST_RELEASE']}.epub"
)
artifact = artifact.parent / f"Salt-{os.environ['LATEST_RELEASE']}.epub"
github_output = os.environ.get("GITHUB_OUTPUT")
if github_output is not None:
with open(github_output, "a", encoding="utf-8") as wfh:
wfh.write(
"has-artifacts=true\n"
f"artifact-name={artifact.resolve().name}\n"
f"artifact-path={artifact.resolve()}\n"
)
@docs.command(
name="pdf",
arguments={
"no_clean": {
"help": "Don't cleanup prior to building",
},
"no_color": {
"help": "Disable colored output.",
},
},
)
def pdf(ctx: Context, no_clean: bool = False, no_color: bool = False):
if not shutil.which("inkscape"):
ctx.warn("No inkscape binary found")
ctx.exit(1)
if no_clean is False:
ctx.run("make", "clean", cwd="doc/", check=True)
opts = [
"-W",
"-j",
"auto",
"--keep-going",
]
if no_color is False:
opts.append("--color")
ctx.run(
"make",
"pdf",
f"SPHINXOPTS={' '.join(opts)}",
cwd="doc/",
check=True,
)
artifact = tools.utils.REPO_ROOT / "doc" / "_build" / "latex" / "Salt.pdf"
if "LATEST_RELEASE" in os.environ:
shutil.move(
artifact, artifact.parent / f"Salt-{os.environ['LATEST_RELEASE']}.pdf"
)
artifact = artifact.parent / f"Salt-{os.environ['LATEST_RELEASE']}.pdf"
github_output = os.environ.get("GITHUB_OUTPUT")
if github_output is not None:
with open(github_output, "a", encoding="utf-8") as wfh:
wfh.write(
"has-artifacts=true\n"
f"artifact-name={artifact.resolve().name}\n"
f"artifact-path={artifact.resolve()}\n"
)
@docs.command(
name="linkcheck",
arguments={
"no_clean": {
"help": "Don't cleanup prior to building",
},
"no_color": {
"help": "Disable colored output.",
},
},
)
def linkcheck(ctx: Context, no_clean: bool = False, no_color: bool = False):
if no_clean is False:
ctx.run("make", "clean", cwd="doc/", check=True)
opts = [
"-W",
"-j",
"auto",
"--keep-going",
]
if no_color is False:
opts.append("--color")
ctx.run(
"make",
"linkcheck",
f"SPHINXOPTS={' '.join(opts)}",
cwd="doc/",
check=True,
)
github_output = os.environ.get("GITHUB_OUTPUT")
if github_output is not None:
with open(github_output, "a", encoding="utf-8") as wfh:
wfh.write("has-artifacts=false\n")
@docs.command(
name="spellcheck",
arguments={
"no_clean": {
"help": "Don't cleanup prior to building",
},
"no_color": {
"help": "Disable colored output.",
},
},
)
def spellcheck(ctx: Context, no_clean: bool = False, no_color: bool = False):
if no_clean is False:
ctx.run("make", "clean", cwd="doc/", check=True)
opts = [
"-W",
"-j",
"auto",
"--keep-going",
]
if no_color is False:
opts.append("--color")
ctx.run(
"make",
"spelling",
f"SPHINXOPTS={' '.join(opts)}",
cwd="doc/",
check=True,
)
github_output = os.environ.get("GITHUB_OUTPUT")
if github_output is not None:
with open(github_output, "a", encoding="utf-8") as wfh:
wfh.write("has-artifacts=false\n")