doxtr-cli 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- doxtr_cli/__init__.py +48 -0
- doxtr_cli/__main__.py +8 -0
- doxtr_cli/builders.py +596 -0
- doxtr_cli/cli.py +301 -0
- doxtr_cli/config.py +330 -0
- doxtr_cli/confluence.py +166 -0
- doxtr_cli/errors.py +49 -0
- doxtr_cli/git_meta.py +118 -0
- doxtr_cli/prompts.py +89 -0
- doxtr_cli/server.py +800 -0
- doxtr_cli-0.1.0.dist-info/METADATA +110 -0
- doxtr_cli-0.1.0.dist-info/RECORD +16 -0
- doxtr_cli-0.1.0.dist-info/WHEEL +5 -0
- doxtr_cli-0.1.0.dist-info/entry_points.txt +2 -0
- doxtr_cli-0.1.0.dist-info/licenses/LICENSE +21 -0
- doxtr_cli-0.1.0.dist-info/top_level.txt +1 -0
doxtr_cli/__init__.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""Doxtr CLI package."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from .builders import BuildReport, run_release, run_test
|
|
6
|
+
from .config import DoxtrConfig, load_config
|
|
7
|
+
from .errors import (
|
|
8
|
+
EXIT_CONFIG_ERROR,
|
|
9
|
+
EXIT_FAILURE,
|
|
10
|
+
EXIT_INTERRUPTED,
|
|
11
|
+
EXIT_OK,
|
|
12
|
+
BuildError,
|
|
13
|
+
ConfigError,
|
|
14
|
+
ConfirmationDeclinedError,
|
|
15
|
+
ConfluenceError,
|
|
16
|
+
DoxtrError,
|
|
17
|
+
MissingBinaryError,
|
|
18
|
+
)
|
|
19
|
+
from .git_meta import GitMetadata, collect_git_metadata, format_test_stamp
|
|
20
|
+
from .prompts import ReleaseSummary, confirm_release
|
|
21
|
+
from .server import DoxtrPreviewServer
|
|
22
|
+
|
|
23
|
+
__version__ = "0.1.0"
|
|
24
|
+
|
|
25
|
+
__all__ = [
|
|
26
|
+
"__version__",
|
|
27
|
+
"BuildError",
|
|
28
|
+
"BuildReport",
|
|
29
|
+
"ConfigError",
|
|
30
|
+
"ConfirmationDeclinedError",
|
|
31
|
+
"ConfluenceError",
|
|
32
|
+
"DoxtrConfig",
|
|
33
|
+
"DoxtrError",
|
|
34
|
+
"DoxtrPreviewServer",
|
|
35
|
+
"EXIT_CONFIG_ERROR",
|
|
36
|
+
"EXIT_FAILURE",
|
|
37
|
+
"EXIT_INTERRUPTED",
|
|
38
|
+
"EXIT_OK",
|
|
39
|
+
"GitMetadata",
|
|
40
|
+
"MissingBinaryError",
|
|
41
|
+
"ReleaseSummary",
|
|
42
|
+
"collect_git_metadata",
|
|
43
|
+
"confirm_release",
|
|
44
|
+
"format_test_stamp",
|
|
45
|
+
"load_config",
|
|
46
|
+
"run_release",
|
|
47
|
+
"run_test",
|
|
48
|
+
]
|
doxtr_cli/__main__.py
ADDED
doxtr_cli/builders.py
ADDED
|
@@ -0,0 +1,596 @@
|
|
|
1
|
+
"""Build pipeline orchestration for ``doxtr release`` and ``doxtr test``."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
import shutil
|
|
8
|
+
import subprocess
|
|
9
|
+
from collections.abc import Callable
|
|
10
|
+
from dataclasses import dataclass, field
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
from .config import ConfluenceTargetConfig, DoxtrConfig
|
|
15
|
+
from .confluence import build_confluence_sphinx_cmd, upload_confluence_attachments
|
|
16
|
+
from .errors import BuildError, MissingBinaryError
|
|
17
|
+
from .git_meta import (
|
|
18
|
+
GitMetadata,
|
|
19
|
+
collect_git_metadata,
|
|
20
|
+
format_test_stamp,
|
|
21
|
+
resolve_release_version,
|
|
22
|
+
resolve_test_short_version,
|
|
23
|
+
)
|
|
24
|
+
from .prompts import ReleaseSummary, confirm_release
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass(frozen=True)
|
|
28
|
+
class CommandResult:
|
|
29
|
+
"""Captured result from executing a build subprocess."""
|
|
30
|
+
|
|
31
|
+
cmd: list[str]
|
|
32
|
+
returncode: int
|
|
33
|
+
stdout: str = ""
|
|
34
|
+
stderr: str = ""
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
CommandRunner = Callable[[list[str], Path], CommandResult]
|
|
38
|
+
WhichFn = Callable[[str], str | None]
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@dataclass
|
|
42
|
+
class BuildReport:
|
|
43
|
+
"""Structured outcome returned by ``run_release`` and ``run_test``."""
|
|
44
|
+
|
|
45
|
+
mode: str
|
|
46
|
+
version: str
|
|
47
|
+
stamp: str
|
|
48
|
+
light_pdf: Path | None = None
|
|
49
|
+
dark_pdf: Path | None = None
|
|
50
|
+
html_dir: Path | None = None
|
|
51
|
+
manifest_path: Path | None = None
|
|
52
|
+
bundled_pdfs: list[Path] = field(default_factory=list)
|
|
53
|
+
confluence_dir: Path | None = None
|
|
54
|
+
uploaded_attachments: list[str] = field(default_factory=list)
|
|
55
|
+
commands: list[list[str]] = field(default_factory=list)
|
|
56
|
+
dry_run: bool = False
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def default_runner(cmd: list[str], cwd: Path) -> CommandResult:
|
|
60
|
+
"""Execute *cmd* in *cwd* and raise :class:`BuildError` on failure."""
|
|
61
|
+
try:
|
|
62
|
+
proc = subprocess.run(
|
|
63
|
+
cmd,
|
|
64
|
+
cwd=str(cwd),
|
|
65
|
+
capture_output=True,
|
|
66
|
+
text=True,
|
|
67
|
+
check=False,
|
|
68
|
+
)
|
|
69
|
+
except OSError as exc:
|
|
70
|
+
raise BuildError(f"Failed executing command {' '.join(cmd)}: {exc}") from exc
|
|
71
|
+
|
|
72
|
+
if proc.returncode != 0:
|
|
73
|
+
detail = proc.stderr.strip() or proc.stdout.strip() or f"exit code {proc.returncode}"
|
|
74
|
+
raise BuildError(f"Command failed ({proc.returncode}): {' '.join(cmd)}\n{detail}")
|
|
75
|
+
return CommandResult(
|
|
76
|
+
cmd=cmd, returncode=proc.returncode, stdout=proc.stdout, stderr=proc.stderr
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def require_binary(name: str, *, which_fn: WhichFn = shutil.which) -> str:
|
|
81
|
+
"""Ensure external executable *name* exists on ``PATH`` or raise exit code 2."""
|
|
82
|
+
found = which_fn(name)
|
|
83
|
+
if not found:
|
|
84
|
+
raise MissingBinaryError(f"Required executable '{name}' not found on PATH.")
|
|
85
|
+
return found
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def sha256_file(path: Path) -> str:
|
|
89
|
+
"""Return lowercase hexadecimal SHA-256 digest of *path*."""
|
|
90
|
+
digest = hashlib.sha256()
|
|
91
|
+
with path.open("rb") as fh:
|
|
92
|
+
for chunk in iter(lambda: fh.read(65536), b""):
|
|
93
|
+
digest.update(chunk)
|
|
94
|
+
return digest.hexdigest()
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def bundle_pdf_downloads(
|
|
98
|
+
html_dir: Path,
|
|
99
|
+
downloads_subdir: str,
|
|
100
|
+
pdfs: list[tuple[str, Path]],
|
|
101
|
+
*,
|
|
102
|
+
project_name: str,
|
|
103
|
+
mode: str,
|
|
104
|
+
version: str,
|
|
105
|
+
commit_sha: str,
|
|
106
|
+
built_at: str,
|
|
107
|
+
) -> tuple[list[Path], Path]:
|
|
108
|
+
"""Copy PDF artifacts into *html_dir*/*downloads_subdir* and write ``artifacts.json``."""
|
|
109
|
+
target_dir = html_dir / downloads_subdir if downloads_subdir else html_dir
|
|
110
|
+
target_dir.mkdir(parents=True, exist_ok=True)
|
|
111
|
+
|
|
112
|
+
bundled: list[Path] = []
|
|
113
|
+
manifest_files: list[dict[str, Any]] = []
|
|
114
|
+
for variant, src_pdf in pdfs:
|
|
115
|
+
if not src_pdf.is_file():
|
|
116
|
+
raise BuildError(f"Expected built PDF for '{variant}' not found: {src_pdf}")
|
|
117
|
+
dest_pdf = target_dir / src_pdf.name
|
|
118
|
+
if src_pdf.resolve() != dest_pdf.resolve():
|
|
119
|
+
shutil.copy2(src_pdf, dest_pdf)
|
|
120
|
+
bundled.append(dest_pdf)
|
|
121
|
+
rel_path = dest_pdf.relative_to(html_dir).as_posix()
|
|
122
|
+
manifest_files.append(
|
|
123
|
+
{
|
|
124
|
+
"variant": variant,
|
|
125
|
+
"filename": dest_pdf.name,
|
|
126
|
+
"path": rel_path,
|
|
127
|
+
"size_bytes": dest_pdf.stat().st_size,
|
|
128
|
+
"sha256": sha256_file(dest_pdf),
|
|
129
|
+
}
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
manifest_path = target_dir / "artifacts.json"
|
|
133
|
+
manifest_payload = {
|
|
134
|
+
"project": project_name,
|
|
135
|
+
"mode": mode,
|
|
136
|
+
"version": version,
|
|
137
|
+
"commit_sha": commit_sha,
|
|
138
|
+
"built_at": built_at,
|
|
139
|
+
"files": manifest_files,
|
|
140
|
+
}
|
|
141
|
+
manifest_path.write_text(json.dumps(manifest_payload, indent=2) + "\n", encoding="utf-8")
|
|
142
|
+
return bundled, manifest_path
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _find_built_latex_pdf(latex_build_dir: Path, latex_name: str) -> Path:
|
|
146
|
+
expected = latex_build_dir / f"{latex_name}.pdf"
|
|
147
|
+
if expected.is_file():
|
|
148
|
+
return expected
|
|
149
|
+
candidates = sorted(latex_build_dir.glob("*.pdf"))
|
|
150
|
+
if len(candidates) == 1:
|
|
151
|
+
return candidates[0]
|
|
152
|
+
raise BuildError(
|
|
153
|
+
f"Expected PDF '{expected.name}' in {latex_build_dir}, found: {[c.name for c in candidates]}"
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def _plan_pdf_steps(
|
|
158
|
+
config: DoxtrConfig,
|
|
159
|
+
*,
|
|
160
|
+
scheme: str,
|
|
161
|
+
build_root: Path,
|
|
162
|
+
sphinx_bin: str,
|
|
163
|
+
make_bin: str,
|
|
164
|
+
extra_defines: dict[str, str],
|
|
165
|
+
) -> tuple[Path, Path, list[str], list[str]]:
|
|
166
|
+
dark_flag = "1" if scheme == "dark" else "0"
|
|
167
|
+
latex_dir = build_root / f"latex-{scheme}"
|
|
168
|
+
doctrees_dir = build_root / f"doctrees-latex-{scheme}"
|
|
169
|
+
out_filename = config.pdf.dark_filename if scheme == "dark" else config.pdf.light_filename
|
|
170
|
+
final_pdf = build_root / "latex" / out_filename
|
|
171
|
+
|
|
172
|
+
sphinx_cmd = [
|
|
173
|
+
sphinx_bin,
|
|
174
|
+
"-b",
|
|
175
|
+
"latex",
|
|
176
|
+
"-d",
|
|
177
|
+
str(doctrees_dir),
|
|
178
|
+
"-D",
|
|
179
|
+
f"doxtr_color_scheme={scheme}",
|
|
180
|
+
"-D",
|
|
181
|
+
f"doxtr_dark_mode={dark_flag}",
|
|
182
|
+
]
|
|
183
|
+
for key, value in sorted(extra_defines.items()):
|
|
184
|
+
sphinx_cmd.extend(["-D", f"{key}={value}"])
|
|
185
|
+
sphinx_cmd.extend([str(config.source_path), str(latex_dir)])
|
|
186
|
+
|
|
187
|
+
make_cmd = [
|
|
188
|
+
make_bin,
|
|
189
|
+
"-C",
|
|
190
|
+
str(latex_dir),
|
|
191
|
+
"all-pdf",
|
|
192
|
+
"LATEXOPTS=-interaction=nonstopmode",
|
|
193
|
+
]
|
|
194
|
+
return latex_dir, final_pdf, sphinx_cmd, make_cmd
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def _build_pdf_variant(
|
|
198
|
+
config: DoxtrConfig,
|
|
199
|
+
*,
|
|
200
|
+
scheme: str,
|
|
201
|
+
build_root: Path,
|
|
202
|
+
sphinx_bin: str,
|
|
203
|
+
make_bin: str,
|
|
204
|
+
extra_defines: dict[str, str],
|
|
205
|
+
runner: CommandRunner,
|
|
206
|
+
commands: list[list[str]],
|
|
207
|
+
) -> Path:
|
|
208
|
+
latex_dir, final_pdf, sphinx_cmd, make_cmd = _plan_pdf_steps(
|
|
209
|
+
config,
|
|
210
|
+
scheme=scheme,
|
|
211
|
+
build_root=build_root,
|
|
212
|
+
sphinx_bin=sphinx_bin,
|
|
213
|
+
make_bin=make_bin,
|
|
214
|
+
extra_defines=extra_defines,
|
|
215
|
+
)
|
|
216
|
+
latex_dir.mkdir(parents=True, exist_ok=True)
|
|
217
|
+
final_pdf.parent.mkdir(parents=True, exist_ok=True)
|
|
218
|
+
|
|
219
|
+
commands.append(sphinx_cmd)
|
|
220
|
+
runner(sphinx_cmd, config.project_root)
|
|
221
|
+
|
|
222
|
+
commands.append(make_cmd)
|
|
223
|
+
runner(make_cmd, config.project_root)
|
|
224
|
+
|
|
225
|
+
produced_pdf = _find_built_latex_pdf(latex_dir, config.project.latex_name)
|
|
226
|
+
if produced_pdf.resolve() != final_pdf.resolve():
|
|
227
|
+
shutil.copy2(produced_pdf, final_pdf)
|
|
228
|
+
return final_pdf
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def _plan_html_cmd(
|
|
232
|
+
config: DoxtrConfig,
|
|
233
|
+
*,
|
|
234
|
+
html_dir: Path,
|
|
235
|
+
doctrees_dir: Path,
|
|
236
|
+
sphinx_bin: str,
|
|
237
|
+
extra_defines: dict[str, str],
|
|
238
|
+
) -> list[str]:
|
|
239
|
+
cmd = [
|
|
240
|
+
sphinx_bin,
|
|
241
|
+
"-b",
|
|
242
|
+
"html",
|
|
243
|
+
"-d",
|
|
244
|
+
str(doctrees_dir),
|
|
245
|
+
]
|
|
246
|
+
if config.html.theme:
|
|
247
|
+
cmd.extend(["-D", f"html_theme={config.html.theme}"])
|
|
248
|
+
for key, value in sorted(extra_defines.items()):
|
|
249
|
+
cmd.extend(["-D", f"{key}={value}"])
|
|
250
|
+
cmd.extend([str(config.source_path), str(html_dir)])
|
|
251
|
+
return cmd
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def _collect_planned_pdfs(
|
|
255
|
+
config: DoxtrConfig, build_root: Path, *, skip_pdf: bool
|
|
256
|
+
) -> tuple[Path | None, Path | None]:
|
|
257
|
+
if skip_pdf:
|
|
258
|
+
return None, None
|
|
259
|
+
light_pdf = build_root / "latex" / config.pdf.light_filename if config.pdf.light else None
|
|
260
|
+
dark_pdf = build_root / "latex" / config.pdf.dark_filename if config.pdf.dark else None
|
|
261
|
+
return light_pdf, dark_pdf
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def _run_pipeline(
|
|
265
|
+
config: DoxtrConfig,
|
|
266
|
+
*,
|
|
267
|
+
mode: str,
|
|
268
|
+
meta: GitMetadata,
|
|
269
|
+
version: str,
|
|
270
|
+
stamp: str,
|
|
271
|
+
build_root: Path,
|
|
272
|
+
html_dir: Path,
|
|
273
|
+
confluence_target: ConfluenceTargetConfig,
|
|
274
|
+
confluence_enabled: bool,
|
|
275
|
+
pdf_defines: dict[str, str],
|
|
276
|
+
html_defines: dict[str, str],
|
|
277
|
+
confluence_defines: dict[str, str],
|
|
278
|
+
dry_run: bool,
|
|
279
|
+
skip_pdf: bool,
|
|
280
|
+
skip_html: bool,
|
|
281
|
+
runner: CommandRunner,
|
|
282
|
+
output_fn: Callable[[str], None],
|
|
283
|
+
which_fn: WhichFn,
|
|
284
|
+
http_session: Any | None,
|
|
285
|
+
) -> BuildReport:
|
|
286
|
+
sphinx_bin = "sphinx-build" if dry_run else require_binary("sphinx-build", which_fn=which_fn)
|
|
287
|
+
need_pdf = not skip_pdf and (config.pdf.light or config.pdf.dark)
|
|
288
|
+
make_bin = "make" if dry_run or not need_pdf else require_binary("make", which_fn=which_fn)
|
|
289
|
+
|
|
290
|
+
planned_light, planned_dark = _collect_planned_pdfs(config, build_root, skip_pdf=skip_pdf)
|
|
291
|
+
commands: list[list[str]] = []
|
|
292
|
+
|
|
293
|
+
if dry_run:
|
|
294
|
+
if not skip_pdf and config.pdf.light:
|
|
295
|
+
_, _, s_cmd, m_cmd = _plan_pdf_steps(
|
|
296
|
+
config,
|
|
297
|
+
scheme="light",
|
|
298
|
+
build_root=build_root,
|
|
299
|
+
sphinx_bin=sphinx_bin,
|
|
300
|
+
make_bin=make_bin,
|
|
301
|
+
extra_defines=pdf_defines,
|
|
302
|
+
)
|
|
303
|
+
commands.extend([s_cmd, m_cmd])
|
|
304
|
+
if not skip_pdf and config.pdf.dark:
|
|
305
|
+
_, _, s_cmd, m_cmd = _plan_pdf_steps(
|
|
306
|
+
config,
|
|
307
|
+
scheme="dark",
|
|
308
|
+
build_root=build_root,
|
|
309
|
+
sphinx_bin=sphinx_bin,
|
|
310
|
+
make_bin=make_bin,
|
|
311
|
+
extra_defines=pdf_defines,
|
|
312
|
+
)
|
|
313
|
+
commands.extend([s_cmd, m_cmd])
|
|
314
|
+
if not skip_html:
|
|
315
|
+
commands.append(
|
|
316
|
+
_plan_html_cmd(
|
|
317
|
+
config,
|
|
318
|
+
html_dir=html_dir,
|
|
319
|
+
doctrees_dir=build_root / f"doctrees-html-{mode}",
|
|
320
|
+
sphinx_bin=sphinx_bin,
|
|
321
|
+
extra_defines=html_defines,
|
|
322
|
+
)
|
|
323
|
+
)
|
|
324
|
+
if confluence_enabled:
|
|
325
|
+
commands.append(
|
|
326
|
+
build_confluence_sphinx_cmd(
|
|
327
|
+
config.source_path,
|
|
328
|
+
build_root / f"confluence-{mode}",
|
|
329
|
+
build_root / f"doctrees-confluence-{mode}",
|
|
330
|
+
confluence_target,
|
|
331
|
+
extra_defines=confluence_defines,
|
|
332
|
+
sphinx_build=sphinx_bin,
|
|
333
|
+
)
|
|
334
|
+
)
|
|
335
|
+
output_fn(f"[dry-run] Planned {len(commands)} step(s) for '{mode}' ({stamp}):")
|
|
336
|
+
for idx, cmd in enumerate(commands, start=1):
|
|
337
|
+
output_fn(f" {idx}. {' '.join(cmd)}")
|
|
338
|
+
return BuildReport(
|
|
339
|
+
mode=mode,
|
|
340
|
+
version=version,
|
|
341
|
+
stamp=stamp,
|
|
342
|
+
light_pdf=planned_light,
|
|
343
|
+
dark_pdf=planned_dark,
|
|
344
|
+
html_dir=None if skip_html else html_dir,
|
|
345
|
+
confluence_dir=build_root / f"confluence-{mode}" if confluence_enabled else None,
|
|
346
|
+
commands=commands,
|
|
347
|
+
dry_run=True,
|
|
348
|
+
)
|
|
349
|
+
|
|
350
|
+
built_pdfs: list[tuple[str, Path]] = []
|
|
351
|
+
light_pdf: Path | None = None
|
|
352
|
+
dark_pdf: Path | None = None
|
|
353
|
+
|
|
354
|
+
if not skip_pdf and config.pdf.light:
|
|
355
|
+
light_pdf = _build_pdf_variant(
|
|
356
|
+
config,
|
|
357
|
+
scheme="light",
|
|
358
|
+
build_root=build_root,
|
|
359
|
+
sphinx_bin=sphinx_bin,
|
|
360
|
+
make_bin=make_bin,
|
|
361
|
+
extra_defines=pdf_defines,
|
|
362
|
+
runner=runner,
|
|
363
|
+
commands=commands,
|
|
364
|
+
)
|
|
365
|
+
built_pdfs.append(("light", light_pdf))
|
|
366
|
+
|
|
367
|
+
if not skip_pdf and config.pdf.dark:
|
|
368
|
+
dark_pdf = _build_pdf_variant(
|
|
369
|
+
config,
|
|
370
|
+
scheme="dark",
|
|
371
|
+
build_root=build_root,
|
|
372
|
+
sphinx_bin=sphinx_bin,
|
|
373
|
+
make_bin=make_bin,
|
|
374
|
+
extra_defines=pdf_defines,
|
|
375
|
+
runner=runner,
|
|
376
|
+
commands=commands,
|
|
377
|
+
)
|
|
378
|
+
built_pdfs.append(("dark", dark_pdf))
|
|
379
|
+
|
|
380
|
+
built_html_dir: Path | None = None
|
|
381
|
+
bundled_pdfs: list[Path] = []
|
|
382
|
+
manifest_path: Path | None = None
|
|
383
|
+
if not skip_html:
|
|
384
|
+
html_dir.mkdir(parents=True, exist_ok=True)
|
|
385
|
+
html_cmd = _plan_html_cmd(
|
|
386
|
+
config,
|
|
387
|
+
html_dir=html_dir,
|
|
388
|
+
doctrees_dir=build_root / f"doctrees-html-{mode}",
|
|
389
|
+
sphinx_bin=sphinx_bin,
|
|
390
|
+
extra_defines=html_defines,
|
|
391
|
+
)
|
|
392
|
+
commands.append(html_cmd)
|
|
393
|
+
runner(html_cmd, config.project_root)
|
|
394
|
+
built_html_dir = html_dir
|
|
395
|
+
|
|
396
|
+
if built_pdfs and config.pdf.copy_to_html_downloads:
|
|
397
|
+
bundled_pdfs, manifest_path = bundle_pdf_downloads(
|
|
398
|
+
html_dir,
|
|
399
|
+
config.html.downloads_subdir,
|
|
400
|
+
built_pdfs,
|
|
401
|
+
project_name=config.project.name,
|
|
402
|
+
mode=mode,
|
|
403
|
+
version=version,
|
|
404
|
+
commit_sha=meta.commit_sha,
|
|
405
|
+
built_at=meta.utc_timestamp,
|
|
406
|
+
)
|
|
407
|
+
|
|
408
|
+
confluence_dir: Path | None = None
|
|
409
|
+
uploaded_attachments: list[str] = []
|
|
410
|
+
if confluence_enabled:
|
|
411
|
+
confluence_dir = build_root / f"confluence-{mode}"
|
|
412
|
+
confluence_dir.mkdir(parents=True, exist_ok=True)
|
|
413
|
+
conf_cmd = build_confluence_sphinx_cmd(
|
|
414
|
+
config.source_path,
|
|
415
|
+
confluence_dir,
|
|
416
|
+
build_root / f"doctrees-confluence-{mode}",
|
|
417
|
+
confluence_target,
|
|
418
|
+
extra_defines=confluence_defines,
|
|
419
|
+
sphinx_build=sphinx_bin,
|
|
420
|
+
)
|
|
421
|
+
commands.append(conf_cmd)
|
|
422
|
+
runner(conf_cmd, config.project_root)
|
|
423
|
+
|
|
424
|
+
if confluence_target.attach_pdfs and built_pdfs:
|
|
425
|
+
uploaded = upload_confluence_attachments(
|
|
426
|
+
confluence_target,
|
|
427
|
+
[p for _, p in built_pdfs],
|
|
428
|
+
session=http_session,
|
|
429
|
+
default_page_title=config.project.name,
|
|
430
|
+
)
|
|
431
|
+
uploaded_attachments = [item["file"] for item in uploaded]
|
|
432
|
+
|
|
433
|
+
return BuildReport(
|
|
434
|
+
mode=mode,
|
|
435
|
+
version=version,
|
|
436
|
+
stamp=stamp,
|
|
437
|
+
light_pdf=light_pdf,
|
|
438
|
+
dark_pdf=dark_pdf,
|
|
439
|
+
html_dir=built_html_dir,
|
|
440
|
+
manifest_path=manifest_path,
|
|
441
|
+
bundled_pdfs=bundled_pdfs,
|
|
442
|
+
confluence_dir=confluence_dir,
|
|
443
|
+
uploaded_attachments=uploaded_attachments,
|
|
444
|
+
commands=commands,
|
|
445
|
+
dry_run=False,
|
|
446
|
+
)
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
def run_release(
|
|
450
|
+
config: DoxtrConfig,
|
|
451
|
+
*,
|
|
452
|
+
dry_run: bool = False,
|
|
453
|
+
skip_pdf: bool = False,
|
|
454
|
+
skip_html: bool = False,
|
|
455
|
+
skip_confluence: bool = False,
|
|
456
|
+
output_dir: Path | None = None,
|
|
457
|
+
runner: CommandRunner = default_runner,
|
|
458
|
+
input_fn: Callable[[str], str] = input,
|
|
459
|
+
output_fn: Callable[[str], None] = print,
|
|
460
|
+
which_fn: WhichFn = shutil.which,
|
|
461
|
+
http_session: Any | None = None,
|
|
462
|
+
) -> BuildReport:
|
|
463
|
+
"""Execute the gated ``doxtr release`` production build & publish pipeline."""
|
|
464
|
+
meta = collect_git_metadata(config.project_root)
|
|
465
|
+
version = resolve_release_version(meta, fallback=config.project.version)
|
|
466
|
+
build_root = output_dir.resolve() if output_dir is not None else config.build_path
|
|
467
|
+
html_dir = build_root / "html"
|
|
468
|
+
confluence_target = config.confluence.release
|
|
469
|
+
confluence_enabled = confluence_target.enabled and not skip_confluence
|
|
470
|
+
|
|
471
|
+
planned_light, planned_dark = _collect_planned_pdfs(config, build_root, skip_pdf=skip_pdf)
|
|
472
|
+
attachment_names = [p.name for p in (planned_light, planned_dark) if p is not None]
|
|
473
|
+
downloads_dir = (
|
|
474
|
+
html_dir / config.html.downloads_subdir
|
|
475
|
+
if not skip_html and config.pdf.copy_to_html_downloads and attachment_names
|
|
476
|
+
else None
|
|
477
|
+
)
|
|
478
|
+
|
|
479
|
+
summary = ReleaseSummary(
|
|
480
|
+
project_name=config.project.name,
|
|
481
|
+
version=version,
|
|
482
|
+
commit_sha=meta.commit_sha,
|
|
483
|
+
branch=meta.branch,
|
|
484
|
+
dirty=meta.dirty,
|
|
485
|
+
light_pdf=planned_light,
|
|
486
|
+
dark_pdf=planned_dark,
|
|
487
|
+
html_dir=None if skip_html else html_dir,
|
|
488
|
+
downloads_dir=downloads_dir,
|
|
489
|
+
confluence_enabled=confluence_enabled,
|
|
490
|
+
confluence_server_url=confluence_target.server_url,
|
|
491
|
+
confluence_space_key=confluence_target.space_key,
|
|
492
|
+
confluence_parent_page=confluence_target.parent_page,
|
|
493
|
+
confluence_attachments=attachment_names if confluence_target.attach_pdfs else [],
|
|
494
|
+
)
|
|
495
|
+
|
|
496
|
+
if dry_run:
|
|
497
|
+
output_fn(
|
|
498
|
+
summary_text := (
|
|
499
|
+
f"[dry-run] Release Summary for {summary.project_name} v{summary.version}\n"
|
|
500
|
+
+ ("WARNING: dirty workspace\n" if summary.dirty else "")
|
|
501
|
+
).rstrip()
|
|
502
|
+
)
|
|
503
|
+
_ = summary_text
|
|
504
|
+
else:
|
|
505
|
+
confirm_release(summary, input_fn=input_fn, output_fn=output_fn)
|
|
506
|
+
|
|
507
|
+
defines = {"release": version, "version": version}
|
|
508
|
+
return _run_pipeline(
|
|
509
|
+
config,
|
|
510
|
+
mode="release",
|
|
511
|
+
meta=meta,
|
|
512
|
+
version=version,
|
|
513
|
+
stamp=version,
|
|
514
|
+
build_root=build_root,
|
|
515
|
+
html_dir=html_dir,
|
|
516
|
+
confluence_target=confluence_target,
|
|
517
|
+
confluence_enabled=confluence_enabled,
|
|
518
|
+
pdf_defines=defines,
|
|
519
|
+
html_defines=defines,
|
|
520
|
+
confluence_defines=defines,
|
|
521
|
+
dry_run=dry_run,
|
|
522
|
+
skip_pdf=skip_pdf,
|
|
523
|
+
skip_html=skip_html,
|
|
524
|
+
runner=runner,
|
|
525
|
+
output_fn=output_fn,
|
|
526
|
+
which_fn=which_fn,
|
|
527
|
+
http_session=http_session,
|
|
528
|
+
)
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
def run_test(
|
|
532
|
+
config: DoxtrConfig,
|
|
533
|
+
*,
|
|
534
|
+
dry_run: bool = False,
|
|
535
|
+
skip_pdf: bool = False,
|
|
536
|
+
skip_html: bool = False,
|
|
537
|
+
skip_confluence: bool = False,
|
|
538
|
+
enable_confluence: bool = False,
|
|
539
|
+
watermark: str | None = None,
|
|
540
|
+
output_dir: Path | None = None,
|
|
541
|
+
runner: CommandRunner = default_runner,
|
|
542
|
+
output_fn: Callable[[str], None] = print,
|
|
543
|
+
which_fn: WhichFn = shutil.which,
|
|
544
|
+
http_session: Any | None = None,
|
|
545
|
+
) -> BuildReport:
|
|
546
|
+
"""Execute the safe staging ``doxtr test`` workflow targeting ``[confluence.test]`` only."""
|
|
547
|
+
meta = collect_git_metadata(config.project_root)
|
|
548
|
+
base_version = resolve_release_version(meta, fallback=config.project.version)
|
|
549
|
+
detailed_stamp = format_test_stamp(meta, base_version=base_version)
|
|
550
|
+
short_version = resolve_test_short_version(meta)
|
|
551
|
+
|
|
552
|
+
build_root = output_dir.resolve() if output_dir is not None else config.build_path
|
|
553
|
+
html_dir = build_root / "html-test"
|
|
554
|
+
confluence_target = config.confluence.test
|
|
555
|
+
confluence_enabled = (enable_confluence or confluence_target.enabled) and not skip_confluence
|
|
556
|
+
|
|
557
|
+
pdf_defines = {
|
|
558
|
+
"release": detailed_stamp,
|
|
559
|
+
"version": short_version,
|
|
560
|
+
}
|
|
561
|
+
if watermark:
|
|
562
|
+
pdf_defines["doxtr_watermark"] = watermark
|
|
563
|
+
pdf_defines["doxtr_draft.text"] = watermark
|
|
564
|
+
|
|
565
|
+
html_defines = {
|
|
566
|
+
"release": detailed_stamp,
|
|
567
|
+
"version": short_version,
|
|
568
|
+
"html_theme_options.announcement_banner": f"TEST VERSION ({detailed_stamp}) — For Review Only",
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
confluence_defines = {
|
|
572
|
+
"release": detailed_stamp,
|
|
573
|
+
"version": short_version,
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
return _run_pipeline(
|
|
577
|
+
config,
|
|
578
|
+
mode="test",
|
|
579
|
+
meta=meta,
|
|
580
|
+
version=short_version,
|
|
581
|
+
stamp=detailed_stamp,
|
|
582
|
+
build_root=build_root,
|
|
583
|
+
html_dir=html_dir,
|
|
584
|
+
confluence_target=confluence_target,
|
|
585
|
+
confluence_enabled=confluence_enabled,
|
|
586
|
+
pdf_defines=pdf_defines,
|
|
587
|
+
html_defines=html_defines,
|
|
588
|
+
confluence_defines=confluence_defines,
|
|
589
|
+
dry_run=dry_run,
|
|
590
|
+
skip_pdf=skip_pdf,
|
|
591
|
+
skip_html=skip_html,
|
|
592
|
+
runner=runner,
|
|
593
|
+
output_fn=output_fn,
|
|
594
|
+
which_fn=which_fn,
|
|
595
|
+
http_session=http_session,
|
|
596
|
+
)
|