Repository navigation
Expand file tree
/
Copy pathserve-docs.sh
More file actions
86 lines (77 loc) · 2.52 KB
/
Copy pathserve-docs.sh
File metadata and controls
86 lines (77 loc) · 2.52 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
#!/usr/bin/env bash
# Linux/macOS script for serving the PyNetDesign documentation locally.
# Rebuilds first, incrementally, so only the pages that changed are regenerated.
# Run: ./serve-docs.sh
# ./serve-docs.sh --port 8080 serve on another port
# ./serve-docs.sh --no-build serve what is already built
# ./serve-docs.sh --pdf also build the PDF, so its download link works
# Extra Sphinx options can be passed through the SPHINXOPTS variable.
# D. Anikiev, 2026-09-11
set -u
PORT=8000
DO_BUILD=1
BUILD_PDF=0
while [ $# -gt 0 ]; do
case "$1" in
-n|--no-build)
DO_BUILD=0
shift
;;
--pdf)
BUILD_PDF=1
shift
;;
-p|--port)
if [ $# -lt 2 ]; then
echo "Missing value for $1"
exit 1
fi
PORT="$2"
shift 2
;;
-h|--help)
echo "Usage: $(basename "$0") [-p PORT] [-n] [--pdf]"
echo " -p, --port PORT port to serve on (default 8000)"
echo " -n, --no-build skip the rebuild and serve what is already there"
echo " --pdf also build the PDF, so its download link works"
echo
echo "Pass extra Sphinx options through SPHINXOPTS."
exit 0
;;
*)
echo "Unknown option: $1"
echo "Try $(basename "$0") --help"
exit 1
;;
esac
done
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
HTML_DIR="$SCRIPT_DIR/docs/build/html"
# Build when asked, and also when there is nothing to serve yet
NEED_BUILD="$DO_BUILD"
if [ "$NEED_BUILD" -eq 0 ] && [ ! -f "$HTML_DIR/index.html" ]; then
echo "No existing build found, building anyway..."
NEED_BUILD=1
fi
if [ "$NEED_BUILD" -eq 1 ]; then
# Delegate to build-docs so the build logic lives in one place
BUILD_ARGS="--incremental"
if [ "$BUILD_PDF" -eq 1 ]; then
BUILD_ARGS="$BUILD_ARGS --pdf"
fi
# shellcheck disable=SC2086
"$SCRIPT_DIR/build-docs.sh" $BUILD_ARGS
if [ $? -ne 0 ]; then
echo "Build failed, not serving."
exit 1
fi
fi
if [ ! -f "$HTML_DIR/index.html" ]; then
echo "Documentation was not built: $HTML_DIR/index.html is missing."
exit 3
fi
echo "##################################################################"
echo "Serving documentation at http://localhost:$PORT"
echo "Press Ctrl+C to stop."
cd "$HTML_DIR" || exit 4
python -m http.server "$PORT"