doxtr-cli 0.1.0__tar.gz → 0.2.0__tar.gz

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.
Files changed (30) hide show
  1. {doxtr_cli-0.1.0 → doxtr_cli-0.2.0}/PKG-INFO +19 -3
  2. {doxtr_cli-0.1.0 → doxtr_cli-0.2.0}/README.md +18 -2
  3. {doxtr_cli-0.1.0 → doxtr_cli-0.2.0}/doxtr_cli/__init__.py +13 -3
  4. {doxtr_cli-0.1.0 → doxtr_cli-0.2.0}/doxtr_cli/builders.py +265 -26
  5. {doxtr_cli-0.1.0 → doxtr_cli-0.2.0}/doxtr_cli/cli.py +127 -0
  6. {doxtr_cli-0.1.0 → doxtr_cli-0.2.0}/doxtr_cli/config.py +81 -0
  7. doxtr_cli-0.2.0/doxtr_cli/preview.py +603 -0
  8. {doxtr_cli-0.1.0 → doxtr_cli-0.2.0}/doxtr_cli/prompts.py +3 -0
  9. doxtr_cli-0.2.0/doxtr_cli/screenshot.py +713 -0
  10. {doxtr_cli-0.1.0 → doxtr_cli-0.2.0}/doxtr_cli/server.py +4 -0
  11. {doxtr_cli-0.1.0 → doxtr_cli-0.2.0}/doxtr_cli.egg-info/PKG-INFO +19 -3
  12. {doxtr_cli-0.1.0 → doxtr_cli-0.2.0}/doxtr_cli.egg-info/SOURCES.txt +4 -0
  13. {doxtr_cli-0.1.0 → doxtr_cli-0.2.0}/tests/test_config.py +27 -0
  14. doxtr_cli-0.2.0/tests/test_preview.py +260 -0
  15. {doxtr_cli-0.1.0 → doxtr_cli-0.2.0}/tests/test_release_and_test.py +62 -3
  16. doxtr_cli-0.2.0/tests/test_screenshot.py +478 -0
  17. {doxtr_cli-0.1.0 → doxtr_cli-0.2.0}/tests/test_serve.py +15 -0
  18. {doxtr_cli-0.1.0 → doxtr_cli-0.2.0}/LICENSE +0 -0
  19. {doxtr_cli-0.1.0 → doxtr_cli-0.2.0}/doxtr_cli/__main__.py +0 -0
  20. {doxtr_cli-0.1.0 → doxtr_cli-0.2.0}/doxtr_cli/confluence.py +0 -0
  21. {doxtr_cli-0.1.0 → doxtr_cli-0.2.0}/doxtr_cli/errors.py +0 -0
  22. {doxtr_cli-0.1.0 → doxtr_cli-0.2.0}/doxtr_cli/git_meta.py +0 -0
  23. {doxtr_cli-0.1.0 → doxtr_cli-0.2.0}/doxtr_cli.egg-info/dependency_links.txt +0 -0
  24. {doxtr_cli-0.1.0 → doxtr_cli-0.2.0}/doxtr_cli.egg-info/entry_points.txt +0 -0
  25. {doxtr_cli-0.1.0 → doxtr_cli-0.2.0}/doxtr_cli.egg-info/requires.txt +0 -0
  26. {doxtr_cli-0.1.0 → doxtr_cli-0.2.0}/doxtr_cli.egg-info/top_level.txt +0 -0
  27. {doxtr_cli-0.1.0 → doxtr_cli-0.2.0}/pyproject.toml +0 -0
  28. {doxtr_cli-0.1.0 → doxtr_cli-0.2.0}/setup.cfg +0 -0
  29. {doxtr_cli-0.1.0 → doxtr_cli-0.2.0}/tests/test_git_meta.py +0 -0
  30. {doxtr_cli-0.1.0 → doxtr_cli-0.2.0}/tests/test_prompts.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: doxtr-cli
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Unified CLI tool for Doxtr documentation release, test staging, and local/container preview serving.
5
5
  Author: Jens Frey
6
6
  Project-URL: Homepage, https://github.com/doxtr/doxtr-cli
@@ -44,8 +44,9 @@ Command-line tool (`doxtr`) for building, staging, publishing, and previewing Sp
44
44
 
45
45
  ## Commands
46
46
 
47
- - `doxtr release`: Production build (light PDF, dark PDF, HTML site, bundled PDF download artifacts + SHA-256 `artifacts.json` manifest, and Confluence release publish + PDF attachments). Protected by a strict interactive confirmation gate requiring literal `yes` + Enter (or `--dry-run`).
48
- - `doxtr test`: Staging build with rich Git metadata stamping (`<ver>+g<sha>.<branch>[-dirty] (<utc>)`), optional PDF watermark (`--watermark`), announcement-banner HTML output (`build/html-test`), bundled test PDF downloads, and isolated `[confluence.test]` targeting.
47
+ - `doxtr release`: Production build (light PDF, dark PDF, optional EPUB3, HTML site, bundled PDF download artifacts + SHA-256 `artifacts.json` manifest, and Confluence release publish + PDF attachments). Protected by a strict interactive confirmation gate requiring literal `yes` + Enter (or `--dry-run`).
48
+ - `doxtr test`: Staging build with rich Git metadata stamping (`<ver>+g<sha>.<branch>[-dirty] (<utc>)`), scheme-aware `doxtr_draft` PDF watermark (`--watermark`), announcement-banner HTML output (`build/html-test`), optional validated EPUB3 (`build/epub-test`), bundled test PDF downloads, and isolated `[confluence.test]` targeting.
49
+ - `doxtr preview`: Theme preview generator producing draft-stamped light/dark PDFs (with margin-stamp verification and optional busy-page PNG rasterization), XML-validated EPUB3, and light/dark HTML & EPUB viewport screenshots captured via `DoxtrPreviewServer` and headless Chromium CDP.
49
50
  - `doxtr serve`: Serves built documentation or live theme previews via either Reactor's `nginx` (`default.template`) or a pure-Python multi-version `ThreadingHTTPServer` supporting `/versions.json`, `/?scheme=dark|light`, `--theme`, and `--watch` incremental rebuilds.
50
51
  - `doxtr info`: Displays resolved `doxtr.toml` configuration and current Git metadata (supports `--json`).
51
52
 
@@ -77,6 +78,21 @@ light_filename = "doxtr-light.pdf"
77
78
  dark_filename = "doxtr-dark.pdf"
78
79
  copy_to_html_downloads = true
79
80
 
81
+ [epub]
82
+ enabled = false
83
+ theme = ""
84
+ filename = "doxtr.epub"
85
+ validate_xml = true
86
+
87
+ [preview]
88
+ page = "index"
89
+ pdf_markers = []
90
+ html_viewport_width = 1440
91
+ html_viewport_height = 1800
92
+ epub_viewport_width = 820
93
+ epub_viewport_height = 1180
94
+ device_scale_factor = 2.0
95
+
80
96
  [confluence.release]
81
97
  enabled = true
82
98
  space_key = "DOCS"
@@ -4,8 +4,9 @@ Command-line tool (`doxtr`) for building, staging, publishing, and previewing Sp
4
4
 
5
5
  ## Commands
6
6
 
7
- - `doxtr release`: Production build (light PDF, dark PDF, HTML site, bundled PDF download artifacts + SHA-256 `artifacts.json` manifest, and Confluence release publish + PDF attachments). Protected by a strict interactive confirmation gate requiring literal `yes` + Enter (or `--dry-run`).
8
- - `doxtr test`: Staging build with rich Git metadata stamping (`<ver>+g<sha>.<branch>[-dirty] (<utc>)`), optional PDF watermark (`--watermark`), announcement-banner HTML output (`build/html-test`), bundled test PDF downloads, and isolated `[confluence.test]` targeting.
7
+ - `doxtr release`: Production build (light PDF, dark PDF, optional EPUB3, HTML site, bundled PDF download artifacts + SHA-256 `artifacts.json` manifest, and Confluence release publish + PDF attachments). Protected by a strict interactive confirmation gate requiring literal `yes` + Enter (or `--dry-run`).
8
+ - `doxtr test`: Staging build with rich Git metadata stamping (`<ver>+g<sha>.<branch>[-dirty] (<utc>)`), scheme-aware `doxtr_draft` PDF watermark (`--watermark`), announcement-banner HTML output (`build/html-test`), optional validated EPUB3 (`build/epub-test`), bundled test PDF downloads, and isolated `[confluence.test]` targeting.
9
+ - `doxtr preview`: Theme preview generator producing draft-stamped light/dark PDFs (with margin-stamp verification and optional busy-page PNG rasterization), XML-validated EPUB3, and light/dark HTML & EPUB viewport screenshots captured via `DoxtrPreviewServer` and headless Chromium CDP.
9
10
  - `doxtr serve`: Serves built documentation or live theme previews via either Reactor's `nginx` (`default.template`) or a pure-Python multi-version `ThreadingHTTPServer` supporting `/versions.json`, `/?scheme=dark|light`, `--theme`, and `--watch` incremental rebuilds.
10
11
  - `doxtr info`: Displays resolved `doxtr.toml` configuration and current Git metadata (supports `--json`).
11
12
 
@@ -37,6 +38,21 @@ light_filename = "doxtr-light.pdf"
37
38
  dark_filename = "doxtr-dark.pdf"
38
39
  copy_to_html_downloads = true
39
40
 
41
+ [epub]
42
+ enabled = false
43
+ theme = ""
44
+ filename = "doxtr.epub"
45
+ validate_xml = true
46
+
47
+ [preview]
48
+ page = "index"
49
+ pdf_markers = []
50
+ html_viewport_width = 1440
51
+ html_viewport_height = 1800
52
+ epub_viewport_width = 820
53
+ epub_viewport_height = 1180
54
+ device_scale_factor = 2.0
55
+
40
56
  [confluence.release]
41
57
  enabled = true
42
58
  space_key = "DOCS"
@@ -2,8 +2,8 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from .builders import BuildReport, run_release, run_test
6
- from .config import DoxtrConfig, load_config
5
+ from .builders import BuildReport, build_draft_defines, run_release, run_test, verify_epub_archive
6
+ from .config import DoxtrConfig, EpubConfig, PreviewConfig, load_config
7
7
  from .errors import (
8
8
  EXIT_CONFIG_ERROR,
9
9
  EXIT_FAILURE,
@@ -17,10 +17,12 @@ from .errors import (
17
17
  MissingBinaryError,
18
18
  )
19
19
  from .git_meta import GitMetadata, collect_git_metadata, format_test_stamp
20
+ from .preview import PreviewReport, run_preview
20
21
  from .prompts import ReleaseSummary, confirm_release
22
+ from .screenshot import capture_page_screenshots, discover_chromium
21
23
  from .server import DoxtrPreviewServer
22
24
 
23
- __version__ = "0.1.0"
25
+ __version__ = "0.2.0"
24
26
 
25
27
  __all__ = [
26
28
  "__version__",
@@ -36,13 +38,21 @@ __all__ = [
36
38
  "EXIT_FAILURE",
37
39
  "EXIT_INTERRUPTED",
38
40
  "EXIT_OK",
41
+ "EpubConfig",
39
42
  "GitMetadata",
40
43
  "MissingBinaryError",
44
+ "PreviewConfig",
45
+ "PreviewReport",
41
46
  "ReleaseSummary",
47
+ "build_draft_defines",
48
+ "capture_page_screenshots",
42
49
  "collect_git_metadata",
43
50
  "confirm_release",
51
+ "discover_chromium",
44
52
  "format_test_stamp",
45
53
  "load_config",
54
+ "run_preview",
46
55
  "run_release",
47
56
  "run_test",
57
+ "verify_epub_archive",
48
58
  ]
@@ -1,15 +1,19 @@
1
- """Build pipeline orchestration for ``doxtr release`` and ``doxtr test``."""
1
+ """Build pipeline orchestration for ``doxtr release``, ``doxtr test``, and shared builders."""
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
5
  import hashlib
6
+ import inspect
6
7
  import json
8
+ import os
7
9
  import shutil
8
10
  import subprocess
9
- from collections.abc import Callable
11
+ import xml.etree.ElementTree as ET
12
+ import zipfile
13
+ from collections.abc import Callable, Mapping, Sequence
10
14
  from dataclasses import dataclass, field
11
15
  from pathlib import Path
12
- from typing import Any
16
+ from typing import Any, cast
13
17
 
14
18
  from .config import ConfluenceTargetConfig, DoxtrConfig
15
19
  from .confluence import build_confluence_sphinx_cmd, upload_confluence_attachments
@@ -48,6 +52,7 @@ class BuildReport:
48
52
  light_pdf: Path | None = None
49
53
  dark_pdf: Path | None = None
50
54
  html_dir: Path | None = None
55
+ epub_path: Path | None = None
51
56
  manifest_path: Path | None = None
52
57
  bundled_pdfs: list[Path] = field(default_factory=list)
53
58
  confluence_dir: Path | None = None
@@ -56,12 +61,22 @@ class BuildReport:
56
61
  dry_run: bool = False
57
62
 
58
63
 
59
- def default_runner(cmd: list[str], cwd: Path) -> CommandResult:
64
+ _EPUB_XML_EXTENSIONS = (".xhtml", ".svg", ".opf", ".xml", ".ncx")
65
+
66
+
67
+ def default_runner(
68
+ cmd: list[str], cwd: Path, *, env: Mapping[str, str] | None = None
69
+ ) -> CommandResult:
60
70
  """Execute *cmd* in *cwd* and raise :class:`BuildError` on failure."""
71
+ merged_env = None
72
+ if env:
73
+ merged_env = os.environ.copy()
74
+ merged_env.update(env)
61
75
  try:
62
76
  proc = subprocess.run(
63
77
  cmd,
64
78
  cwd=str(cwd),
79
+ env=merged_env,
65
80
  capture_output=True,
66
81
  text=True,
67
82
  check=False,
@@ -77,6 +92,48 @@ def default_runner(cmd: list[str], cwd: Path) -> CommandResult:
77
92
  )
78
93
 
79
94
 
95
+ def invoke_runner(
96
+ runner: CommandRunner,
97
+ cmd: list[str],
98
+ cwd: Path,
99
+ *,
100
+ env: Mapping[str, str] | None = None,
101
+ ) -> CommandResult:
102
+ """Call *runner* while passing *env* only if *runner* accepts an ``env`` keyword arg."""
103
+ accepts_env = False
104
+ if env:
105
+ try:
106
+ params = inspect.signature(runner).parameters
107
+ accepts_env = "env" in params or any(
108
+ p.kind == inspect.Parameter.VAR_KEYWORD for p in params.values()
109
+ )
110
+ except (ValueError, TypeError):
111
+ accepts_env = False
112
+ if accepts_env:
113
+ return cast(CommandResult, cast(Any, runner)(cmd, cwd, env=env))
114
+ return runner(cmd, cwd)
115
+
116
+
117
+ def build_draft_defines(
118
+ text: str,
119
+ *,
120
+ scheme: str,
121
+ date_format: str = "%Y-%m-%d",
122
+ timezone_name: str = "UTC",
123
+ font_size: str = r"\large\bfseries\sffamily",
124
+ color: str | None = None,
125
+ ) -> dict[str, str]:
126
+ """Build scheme-aware ``-D doxtr_draft.*`` overrides for ``doxtr-pdf-theme-core``."""
127
+ resolved_color = color or ("#94A3B8" if scheme == "dark" else "#64748B")
128
+ return {
129
+ "doxtr_draft.text": text,
130
+ "doxtr_draft.date_format": date_format,
131
+ "doxtr_draft.timezone": timezone_name,
132
+ "doxtr_draft.font_size": font_size,
133
+ "doxtr_draft.color": resolved_color,
134
+ }
135
+
136
+
80
137
  def require_binary(name: str, *, which_fn: WhichFn = shutil.which) -> str:
81
138
  """Ensure external executable *name* exists on ``PATH`` or raise exit code 2."""
82
139
  found = which_fn(name)
@@ -161,13 +218,16 @@ def _plan_pdf_steps(
161
218
  build_root: Path,
162
219
  sphinx_bin: str,
163
220
  make_bin: str,
164
- extra_defines: dict[str, str],
221
+ extra_defines: Mapping[str, str],
222
+ out_filename: str | None = None,
165
223
  ) -> tuple[Path, Path, list[str], list[str]]:
166
224
  dark_flag = "1" if scheme == "dark" else "0"
167
225
  latex_dir = build_root / f"latex-{scheme}"
168
226
  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
227
+ resolved_name = out_filename or (
228
+ config.pdf.dark_filename if scheme == "dark" else config.pdf.light_filename
229
+ )
230
+ final_pdf = build_root / "latex" / resolved_name
171
231
 
172
232
  sphinx_cmd = [
173
233
  sphinx_bin,
@@ -201,11 +261,13 @@ def _build_pdf_variant(
201
261
  build_root: Path,
202
262
  sphinx_bin: str,
203
263
  make_bin: str,
204
- extra_defines: dict[str, str],
264
+ extra_defines: Mapping[str, str],
205
265
  runner: CommandRunner,
206
266
  commands: list[list[str]],
267
+ env: Mapping[str, str] | None = None,
268
+ target_pdf: Path | None = None,
207
269
  ) -> Path:
208
- latex_dir, final_pdf, sphinx_cmd, make_cmd = _plan_pdf_steps(
270
+ latex_dir, default_pdf, sphinx_cmd, make_cmd = _plan_pdf_steps(
209
271
  config,
210
272
  scheme=scheme,
211
273
  build_root=build_root,
@@ -213,14 +275,15 @@ def _build_pdf_variant(
213
275
  make_bin=make_bin,
214
276
  extra_defines=extra_defines,
215
277
  )
278
+ final_pdf = target_pdf if target_pdf is not None else default_pdf
216
279
  latex_dir.mkdir(parents=True, exist_ok=True)
217
280
  final_pdf.parent.mkdir(parents=True, exist_ok=True)
218
281
 
219
282
  commands.append(sphinx_cmd)
220
- runner(sphinx_cmd, config.project_root)
283
+ invoke_runner(runner, sphinx_cmd, config.project_root, env=env)
221
284
 
222
285
  commands.append(make_cmd)
223
- runner(make_cmd, config.project_root)
286
+ invoke_runner(runner, make_cmd, config.project_root, env=env)
224
287
 
225
288
  produced_pdf = _find_built_latex_pdf(latex_dir, config.project.latex_name)
226
289
  if produced_pdf.resolve() != final_pdf.resolve():
@@ -234,7 +297,8 @@ def _plan_html_cmd(
234
297
  html_dir: Path,
235
298
  doctrees_dir: Path,
236
299
  sphinx_bin: str,
237
- extra_defines: dict[str, str],
300
+ extra_defines: Mapping[str, str],
301
+ html_theme: str | None = None,
238
302
  ) -> list[str]:
239
303
  cmd = [
240
304
  sphinx_bin,
@@ -243,14 +307,124 @@ def _plan_html_cmd(
243
307
  "-d",
244
308
  str(doctrees_dir),
245
309
  ]
246
- if config.html.theme:
247
- cmd.extend(["-D", f"html_theme={config.html.theme}"])
310
+ selected_theme = config.html.theme if html_theme is None else html_theme
311
+ if selected_theme:
312
+ cmd.extend(["-D", f"html_theme={selected_theme}"])
248
313
  for key, value in sorted(extra_defines.items()):
249
314
  cmd.extend(["-D", f"{key}={value}"])
250
315
  cmd.extend([str(config.source_path), str(html_dir)])
251
316
  return cmd
252
317
 
253
318
 
319
+ def _find_built_epub(epub_build_dir: Path, expected_name: str) -> Path:
320
+ stem_name = expected_name if expected_name.endswith(".epub") else f"{expected_name}.epub"
321
+ expected = epub_build_dir / stem_name
322
+ if expected.is_file():
323
+ return expected
324
+ candidates = sorted(epub_build_dir.glob("*.epub"))
325
+ if len(candidates) == 1:
326
+ return candidates[0]
327
+ raise BuildError(
328
+ f"Expected EPUB '{expected.name}' in {epub_build_dir}, found: {[c.name for c in candidates]}"
329
+ )
330
+
331
+
332
+ def verify_epub_archive(epub_path: Path, *, required_entries: Sequence[str] = ()) -> int:
333
+ """Validate ZIP structure, required entries, and XML well-formedness in an EPUB archive."""
334
+ if not epub_path.is_file():
335
+ raise BuildError(f"Expected EPUB archive not found: {epub_path}")
336
+ validated = 0
337
+ try:
338
+ with zipfile.ZipFile(epub_path) as zf:
339
+ names = zf.namelist()
340
+ name_set = set(names)
341
+ for req in required_entries:
342
+ if req not in name_set:
343
+ raise BuildError(f"Expected entry '{req}' not found in {epub_path}")
344
+ for name in names:
345
+ if name.endswith(_EPUB_XML_EXTENSIONS):
346
+ try:
347
+ ET.fromstring(zf.read(name))
348
+ except ET.ParseError as exc:
349
+ raise BuildError(
350
+ f"Malformed XML in EPUB entry '{name}' ({epub_path}): {exc}"
351
+ ) from exc
352
+ validated += 1
353
+ except (OSError, zipfile.BadZipFile) as exc:
354
+ raise BuildError(f"Unable to read EPUB archive {epub_path}: {exc}") from exc
355
+ return validated
356
+
357
+
358
+ def _plan_epub_cmd(
359
+ config: DoxtrConfig,
360
+ *,
361
+ epub_dir: Path,
362
+ doctrees_dir: Path,
363
+ sphinx_bin: str,
364
+ extra_defines: Mapping[str, str],
365
+ epub_theme: str | None = None,
366
+ ) -> list[str]:
367
+ selected_theme = config.epub.theme if epub_theme is None else epub_theme
368
+ cmd = [
369
+ sphinx_bin,
370
+ "-b",
371
+ "epub",
372
+ "-d",
373
+ str(doctrees_dir),
374
+ "-D",
375
+ "doxtr_color_scheme=auto",
376
+ "-D",
377
+ "doxtr_dark_mode=0",
378
+ ]
379
+ if selected_theme:
380
+ cmd.extend(["-D", f"epub_theme={selected_theme}"])
381
+ for key, value in sorted(extra_defines.items()):
382
+ cmd.extend(["-D", f"{key}={value}"])
383
+ cmd.extend([str(config.source_path), str(epub_dir)])
384
+ return cmd
385
+
386
+
387
+ def build_epub_artifact(
388
+ config: DoxtrConfig,
389
+ *,
390
+ epub_dir: Path,
391
+ doctrees_dir: Path,
392
+ sphinx_bin: str,
393
+ extra_defines: Mapping[str, str],
394
+ runner: CommandRunner,
395
+ commands: list[list[str]],
396
+ target_epub: Path | None = None,
397
+ epub_theme: str | None = None,
398
+ env: Mapping[str, str] | None = None,
399
+ validate_xml: bool | None = None,
400
+ required_entries: Sequence[str] = (),
401
+ ) -> Path:
402
+ """Build EPUB3 output with Sphinx, optionally copy to *target_epub*, and validate XML."""
403
+ epub_dir.mkdir(parents=True, exist_ok=True)
404
+ epub_cmd = _plan_epub_cmd(
405
+ config,
406
+ epub_dir=epub_dir,
407
+ doctrees_dir=doctrees_dir,
408
+ sphinx_bin=sphinx_bin,
409
+ extra_defines=extra_defines,
410
+ epub_theme=epub_theme,
411
+ )
412
+ commands.append(epub_cmd)
413
+ invoke_runner(runner, epub_cmd, config.project_root, env=env)
414
+
415
+ expected_name = config.epub.filename or f"{config.project.latex_name}.epub"
416
+ built_epub = _find_built_epub(epub_dir, expected_name)
417
+ final_epub = target_epub if target_epub is not None else epub_dir / expected_name
418
+ final_epub.parent.mkdir(parents=True, exist_ok=True)
419
+ if built_epub.resolve() != final_epub.resolve():
420
+ shutil.copy2(built_epub, final_epub)
421
+
422
+ should_validate = config.epub.validate_xml if validate_xml is None else validate_xml
423
+ if should_validate:
424
+ verify_epub_archive(final_epub, required_entries=required_entries)
425
+ return final_epub
426
+
427
+
254
428
  def _collect_planned_pdfs(
255
429
  config: DoxtrConfig, build_root: Path, *, skip_pdf: bool
256
430
  ) -> tuple[Path | None, Path | None]:
@@ -261,6 +435,27 @@ def _collect_planned_pdfs(
261
435
  return light_pdf, dark_pdf
262
436
 
263
437
 
438
+ def _collect_planned_epub(
439
+ config: DoxtrConfig, build_root: Path, *, mode: str, skip_epub: bool
440
+ ) -> Path | None:
441
+ if skip_epub or not config.epub.enabled:
442
+ return None
443
+ epub_dir = build_root / ("epub" if mode == "release" else "epub-test")
444
+ epub_name = config.epub.filename or f"{config.project.latex_name}.epub"
445
+ if not epub_name.endswith(".epub"):
446
+ epub_name = f"{epub_name}.epub"
447
+ return epub_dir / epub_name
448
+
449
+
450
+ def _merge_pdf_defines(
451
+ base: Mapping[str, str], *, scheme: str, draft_text: str | None
452
+ ) -> dict[str, str]:
453
+ merged = dict(base)
454
+ if draft_text:
455
+ merged.update(build_draft_defines(draft_text, scheme=scheme))
456
+ return merged
457
+
458
+
264
459
  def _run_pipeline(
265
460
  config: DoxtrConfig,
266
461
  *,
@@ -272,12 +467,15 @@ def _run_pipeline(
272
467
  html_dir: Path,
273
468
  confluence_target: ConfluenceTargetConfig,
274
469
  confluence_enabled: bool,
275
- pdf_defines: dict[str, str],
276
- html_defines: dict[str, str],
277
- confluence_defines: dict[str, str],
470
+ pdf_defines: Mapping[str, str],
471
+ html_defines: Mapping[str, str],
472
+ confluence_defines: Mapping[str, str],
473
+ draft_text: str | None = None,
474
+ epub_defines: Mapping[str, str] | None = None,
278
475
  dry_run: bool,
279
476
  skip_pdf: bool,
280
477
  skip_html: bool,
478
+ skip_epub: bool = False,
281
479
  runner: CommandRunner,
282
480
  output_fn: Callable[[str], None],
283
481
  which_fn: WhichFn,
@@ -288,6 +486,9 @@ def _run_pipeline(
288
486
  make_bin = "make" if dry_run or not need_pdf else require_binary("make", which_fn=which_fn)
289
487
 
290
488
  planned_light, planned_dark = _collect_planned_pdfs(config, build_root, skip_pdf=skip_pdf)
489
+ planned_epub = _collect_planned_epub(config, build_root, mode=mode, skip_epub=skip_epub)
490
+ epub_enabled = planned_epub is not None
491
+ epub_extra_defines = epub_defines if epub_defines is not None else html_defines
291
492
  commands: list[list[str]] = []
292
493
 
293
494
  if dry_run:
@@ -298,7 +499,9 @@ def _run_pipeline(
298
499
  build_root=build_root,
299
500
  sphinx_bin=sphinx_bin,
300
501
  make_bin=make_bin,
301
- extra_defines=pdf_defines,
502
+ extra_defines=_merge_pdf_defines(
503
+ pdf_defines, scheme="light", draft_text=draft_text
504
+ ),
302
505
  )
303
506
  commands.extend([s_cmd, m_cmd])
304
507
  if not skip_pdf and config.pdf.dark:
@@ -308,7 +511,7 @@ def _run_pipeline(
308
511
  build_root=build_root,
309
512
  sphinx_bin=sphinx_bin,
310
513
  make_bin=make_bin,
311
- extra_defines=pdf_defines,
514
+ extra_defines=_merge_pdf_defines(pdf_defines, scheme="dark", draft_text=draft_text),
312
515
  )
313
516
  commands.extend([s_cmd, m_cmd])
314
517
  if not skip_html:
@@ -321,6 +524,16 @@ def _run_pipeline(
321
524
  extra_defines=html_defines,
322
525
  )
323
526
  )
527
+ if planned_epub is not None:
528
+ commands.append(
529
+ _plan_epub_cmd(
530
+ config,
531
+ epub_dir=planned_epub.parent,
532
+ doctrees_dir=build_root / f"doctrees-epub-{mode}",
533
+ sphinx_bin=sphinx_bin,
534
+ extra_defines=epub_extra_defines,
535
+ )
536
+ )
324
537
  if confluence_enabled:
325
538
  commands.append(
326
539
  build_confluence_sphinx_cmd(
@@ -342,6 +555,7 @@ def _run_pipeline(
342
555
  light_pdf=planned_light,
343
556
  dark_pdf=planned_dark,
344
557
  html_dir=None if skip_html else html_dir,
558
+ epub_path=planned_epub,
345
559
  confluence_dir=build_root / f"confluence-{mode}" if confluence_enabled else None,
346
560
  commands=commands,
347
561
  dry_run=True,
@@ -358,7 +572,7 @@ def _run_pipeline(
358
572
  build_root=build_root,
359
573
  sphinx_bin=sphinx_bin,
360
574
  make_bin=make_bin,
361
- extra_defines=pdf_defines,
575
+ extra_defines=_merge_pdf_defines(pdf_defines, scheme="light", draft_text=draft_text),
362
576
  runner=runner,
363
577
  commands=commands,
364
578
  )
@@ -371,7 +585,7 @@ def _run_pipeline(
371
585
  build_root=build_root,
372
586
  sphinx_bin=sphinx_bin,
373
587
  make_bin=make_bin,
374
- extra_defines=pdf_defines,
588
+ extra_defines=_merge_pdf_defines(pdf_defines, scheme="dark", draft_text=draft_text),
375
589
  runner=runner,
376
590
  commands=commands,
377
591
  )
@@ -390,7 +604,7 @@ def _run_pipeline(
390
604
  extra_defines=html_defines,
391
605
  )
392
606
  commands.append(html_cmd)
393
- runner(html_cmd, config.project_root)
607
+ invoke_runner(runner, html_cmd, config.project_root)
394
608
  built_html_dir = html_dir
395
609
 
396
610
  if built_pdfs and config.pdf.copy_to_html_downloads:
@@ -405,6 +619,19 @@ def _run_pipeline(
405
619
  built_at=meta.utc_timestamp,
406
620
  )
407
621
 
622
+ built_epub_path: Path | None = None
623
+ if epub_enabled and planned_epub is not None:
624
+ built_epub_path = build_epub_artifact(
625
+ config,
626
+ epub_dir=planned_epub.parent,
627
+ doctrees_dir=build_root / f"doctrees-epub-{mode}",
628
+ target_epub=planned_epub,
629
+ sphinx_bin=sphinx_bin,
630
+ extra_defines=epub_extra_defines,
631
+ runner=runner,
632
+ commands=commands,
633
+ )
634
+
408
635
  confluence_dir: Path | None = None
409
636
  uploaded_attachments: list[str] = []
410
637
  if confluence_enabled:
@@ -419,7 +646,7 @@ def _run_pipeline(
419
646
  sphinx_build=sphinx_bin,
420
647
  )
421
648
  commands.append(conf_cmd)
422
- runner(conf_cmd, config.project_root)
649
+ invoke_runner(runner, conf_cmd, config.project_root)
423
650
 
424
651
  if confluence_target.attach_pdfs and built_pdfs:
425
652
  uploaded = upload_confluence_attachments(
@@ -437,6 +664,7 @@ def _run_pipeline(
437
664
  light_pdf=light_pdf,
438
665
  dark_pdf=dark_pdf,
439
666
  html_dir=built_html_dir,
667
+ epub_path=built_epub_path,
440
668
  manifest_path=manifest_path,
441
669
  bundled_pdfs=bundled_pdfs,
442
670
  confluence_dir=confluence_dir,
@@ -452,6 +680,7 @@ def run_release(
452
680
  dry_run: bool = False,
453
681
  skip_pdf: bool = False,
454
682
  skip_html: bool = False,
683
+ skip_epub: bool = False,
455
684
  skip_confluence: bool = False,
456
685
  output_dir: Path | None = None,
457
686
  runner: CommandRunner = default_runner,
@@ -469,6 +698,7 @@ def run_release(
469
698
  confluence_enabled = confluence_target.enabled and not skip_confluence
470
699
 
471
700
  planned_light, planned_dark = _collect_planned_pdfs(config, build_root, skip_pdf=skip_pdf)
701
+ planned_epub = _collect_planned_epub(config, build_root, mode="release", skip_epub=skip_epub)
472
702
  attachment_names = [p.name for p in (planned_light, planned_dark) if p is not None]
473
703
  downloads_dir = (
474
704
  html_dir / config.html.downloads_subdir
@@ -485,6 +715,7 @@ def run_release(
485
715
  light_pdf=planned_light,
486
716
  dark_pdf=planned_dark,
487
717
  html_dir=None if skip_html else html_dir,
718
+ epub_path=planned_epub,
488
719
  downloads_dir=downloads_dir,
489
720
  confluence_enabled=confluence_enabled,
490
721
  confluence_server_url=confluence_target.server_url,
@@ -518,9 +749,11 @@ def run_release(
518
749
  pdf_defines=defines,
519
750
  html_defines=defines,
520
751
  confluence_defines=defines,
752
+ epub_defines=defines,
521
753
  dry_run=dry_run,
522
754
  skip_pdf=skip_pdf,
523
755
  skip_html=skip_html,
756
+ skip_epub=skip_epub,
524
757
  runner=runner,
525
758
  output_fn=output_fn,
526
759
  which_fn=which_fn,
@@ -534,6 +767,7 @@ def run_test(
534
767
  dry_run: bool = False,
535
768
  skip_pdf: bool = False,
536
769
  skip_html: bool = False,
770
+ skip_epub: bool = False,
537
771
  skip_confluence: bool = False,
538
772
  enable_confluence: bool = False,
539
773
  watermark: str | None = None,
@@ -558,9 +792,6 @@ def run_test(
558
792
  "release": detailed_stamp,
559
793
  "version": short_version,
560
794
  }
561
- if watermark:
562
- pdf_defines["doxtr_watermark"] = watermark
563
- pdf_defines["doxtr_draft.text"] = watermark
564
795
 
565
796
  html_defines = {
566
797
  "release": detailed_stamp,
@@ -568,6 +799,11 @@ def run_test(
568
799
  "html_theme_options.announcement_banner": f"TEST VERSION ({detailed_stamp}) — For Review Only",
569
800
  }
570
801
 
802
+ epub_defines = {
803
+ "release": detailed_stamp,
804
+ "version": short_version,
805
+ }
806
+
571
807
  confluence_defines = {
572
808
  "release": detailed_stamp,
573
809
  "version": short_version,
@@ -586,9 +822,12 @@ def run_test(
586
822
  pdf_defines=pdf_defines,
587
823
  html_defines=html_defines,
588
824
  confluence_defines=confluence_defines,
825
+ draft_text=watermark,
826
+ epub_defines=epub_defines,
589
827
  dry_run=dry_run,
590
828
  skip_pdf=skip_pdf,
591
829
  skip_html=skip_html,
830
+ skip_epub=skip_epub,
592
831
  runner=runner,
593
832
  output_fn=output_fn,
594
833
  which_fn=which_fn,