Repository navigation
Expand file tree
/
Copy pathserve-docs.bat
More file actions
101 lines (91 loc) · 2.35 KB
/
Copy pathserve-docs.bat
File metadata and controls
101 lines (91 loc) · 2.35 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
96
97
98
99
100
101
:: Windows script for serving the PyNetDesign documentation locally.
:: Rebuilds first, incrementally, so only the pages that changed are regenerated.
:: Run: `serve-docs.bat` from cmd
:: `serve-docs.bat -p 8080` to serve on another port
:: `serve-docs.bat -n` to serve what is already built
:: `serve-docs.bat -pdf` to also build the PDF, so its download link works
:: Extra Sphinx options can be passed through the SPHINXOPTS variable.
:: D. Anikiev, 2026-09-11
@echo off
setlocal
set PORT=8000
set DO_BUILD=1
set BUILD_PDF=0
set HTML_DIR=docs\build\html
:: Parse arguments
:parse_args
if "%~1" == "" goto args_done
if /i "%~1" == "-n" (
set DO_BUILD=0
shift
goto parse_args
)
if /i "%~1" == "--no-build" (
set DO_BUILD=0
shift
goto parse_args
)
if /i "%~1" == "-pdf" (
set BUILD_PDF=1
shift
goto parse_args
)
if /i "%~1" == "--pdf" (
set BUILD_PDF=1
shift
goto parse_args
)
if /i "%~1" == "-p" goto set_port
if /i "%~1" == "--port" goto set_port
if /i "%~1" == "-h" goto usage
if /i "%~1" == "--help" goto usage
echo Unknown option: %~1
echo Try serve-docs.bat --help
exit /b 1
:set_port
if "%~2" == "" (
echo Missing value for %~1
exit /b 1
)
set PORT=%~2
shift
shift
goto parse_args
:usage
echo Usage: serve-docs.bat [-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, --pdf also build the PDF, so its download link works
echo.
echo Pass extra Sphinx options through SPHINXOPTS.
exit /b 0
:args_done
:: Build when asked, and also when there is nothing to serve yet
if %DO_BUILD% equ 1 goto do_build
if not exist %HTML_DIR%\index.html (
echo No existing build found, building anyway...
goto do_build
)
goto serve
:do_build
:: Delegate to build-docs so the build logic lives in one place
if %BUILD_PDF% equ 1 (
call build-docs.bat -i -pdf
) else (
call build-docs.bat -i
)
if %ERRORLEVEL% neq 0 (
echo Build failed, not serving.
exit /b 1
)
:serve
if not exist %HTML_DIR%\index.html (
echo Documentation was not built: %HTML_DIR%\index.html is missing.
exit /b 3
)
echo ##################################################################
echo Serving documentation at http://localhost:%PORT%
echo Press Ctrl+C to stop.
pushd %HTML_DIR%
call python -m http.server %PORT%
popd