-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathprocess.sh
More file actions
executable file
·95 lines (79 loc) · 4.23 KB
/
Copy pathprocess.sh
File metadata and controls
executable file
·95 lines (79 loc) · 4.23 KB
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
#!/usr/bin/env bash
# Build book (HTML + LaTeX PDF + Typst PDF + revealjs slides) in the mlsysbook docker container, export notebooks.
set -euo pipefail
# Image tag encodes the Quarto version. Override: QUARTO_VERSION=1.10.x ./process.sh
# (or set IMAGE directly). Build it: docker build --build-arg QUARTO_VERSION=$QUARTO_VERSION -t $IMAGE -f docker/linux/Dockerfile .
QUARTO_VERSION="${QUARTO_VERSION:-1.9.38}"
IMAGE="${IMAGE:-mlsysbook-linux:quarto-${QUARTO_VERSION}}"
PDF_NAME="Traitement-d-images-satellites-avec-Python.pdf"
# Auto version stamped on the PDF title page (subtitle). Major fixed at 1,
# minor = git commit count (monotonic, no upkeep). Overridable: BOOK_VERSION=1.2 ./process.sh
BOOK_VERSION="${BOOK_VERSION:-1.$(git rev-list --count HEAD 2>/dev/null || echo 0)}"
# Chapters exported to ipynb (+marimo) and stashed under notebooks/
CHAPTERS=(
00-PriseEnMainPython
01-ImportationManipulationImages
02-RehaussementVisualisationImages
03-TransformationSpectrales
04-TransformationSpatiales
05-ClassificationsSupervisees
)
# Aux pages: export and stash under notebooks/ (not marimo-converted)
AUX=(index 00-auteurs references)
# Run a command inside the build container (repo mounted at /workspace).
# --user maps container output to the host user (no more root-owned docs/pdf).
# HOME=/tmp gives quarto/jupyter/matplotlib a writable config dir (image HOME
# is /root, unwritable for a non-root uid).
q() { docker run --rm --user "$(id -u):$(id -g)" -e HOME=/tmp -v "$PWD":/workspace "$IMAGE" "$@"; }
mkdir -p docs pdf notebooks marimo typst-out
# 0. Consolidated exercises chapter (08-Exercices.qmd) — DERIVED from each
# chapter's « Exercices » block. Regenerate before rendering so it stays in
# sync; it is listed in _quarto.yml. Stdlib only, runs on the host.
#python3 make_exercices.py
# 1. HTML site (landing-page subtitle carries the version alongside the edition)
q quarto render --cache --to html \
-M subtitle="Première édition · Version ${BOOK_VERSION}" --output-dir ./docs
# 2. PDF -> publish into docs for the download link
q quarto render --profile production --cache --no-clean --to pdf \
-M subtitle="Version ${BOOK_VERSION}" --output-dir ./pdf
cp -f "./pdf/$PDF_NAME" ./docs/
# 2b. Typst PDF (experimental, orange-book layout) -> typst-out/.
# Not published to docs (LaTeX PDF stays canonical); non-fatal so an
# experimental-format failure never aborts the HTML/PDF build.
q quarto render --profile typst --to orange-book-typst --cache --no-clean \
-M subtitle="Version ${BOOK_VERSION}" --output-dir ./typst-out \
|| echo "WARN: typst render failed (experimental format); continuing"
# 2c. Teaching slides (revealjs) -> docs/slides/ (own project: slides/_quarto.yml).
# Non-fatal: a slide-deck error must not abort the book build.
q quarto render slides --to revealjs --cache \
|| echo "WARN: slides render failed; continuing"
# The landing page must be a normal HTML page, not a deck. The `--to revealjs`
# above force-overrides index.qmd's own `format: html`, so re-render it to HTML
# afterwards (this pass wins). Clear its _files first to drop orphan revealjs libs.
rm -rf docs/slides/index_files
q quarto render slides/index.qmd --to html --cache \
|| echo "WARN: slides index (html) render failed; continuing"
# 3. DOCX (optional)
# mkdir -p docx
# q quarto render --cache --no-clean --to docx --output-dir ./docx
# mv -f "./docx/${PDF_NAME%.pdf}.docx" .
# Detect marimo in the container once (present after adding it to
# docker/dependencies/requirements.txt and rebuilding the image).
HAVE_MARIMO=0
q bash -lc 'command -v marimo >/dev/null 2>&1' && HAVE_MARIMO=1 || true
[ "$HAVE_MARIMO" = 1 ] || echo "WARN: marimo not in image; skipping marimo export (rebuild image to enable)"
# 4. Export chapters -> ipynb (+marimo if available), stash under notebooks/
for ch in "${CHAPTERS[@]}"; do
q quarto convert "$ch.qmd"
q python3 clean_notebooks.py "$ch.ipynb"
[ "$HAVE_MARIMO" = 1 ] && q marimo convert "$ch.ipynb" -o "./marimo/$ch.py"
mv -f "$ch.ipynb" ./notebooks/
done
# 5. Aux pages: export and stash under notebooks/
for ch in "${AUX[@]}"; do
q quarto convert "$ch.qmd"
q python3 clean_notebooks.py "$ch.ipynb"
mv -f "$ch.ipynb" ./notebooks/
done
# 6. Publish (manual)
# git add . && git commit -m 'new content' && git push