-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathdoc-test.bat
More file actions
150 lines (129 loc) · 4.24 KB
/
doc-test.bat
File metadata and controls
150 lines (129 loc) · 4.24 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
@echo off
setlocal
:: edits
:: call with python version and optional mode: new (default) or refresh
if "%1"=="" (
echo Usage: build.bat PYTHON_VERSION new^|refresh
exit /b 1
)
if /i not "%2"=="new" if /i not "%2"=="refresh" (
echo Usage: build.bat PYTHON_VERSION new^|refresh
echo Invalid second argument mode: "%2"
echo Must be 'new' or 'refresh'.
exit /b 1
)
:: --- Configuration ---
set "PYTHON_VERSION=%1"
set "MODE=%2"
set "PROJECT_NAME=aggregate"
:: set "PROJECT_REPO=https://github.com/mynl/%PROJECT_NAME%.git"
set "PROJECT_REPO=c:\S\TELOS\Python\aggregate_project"
set "BUILD_DIR=C:\tmp\%PROJECT_NAME%_rtd_build_%1"
set "VENV_DIR=%BUILD_DIR%\venv"
set "HTML_OUTPUT_DIR=%BUILD_DIR%\html"
set "PORT=9800"
:: --- Prepare Environment and Clone Repository ---
if /i "%MODE%"=="new" (
echo Cleaning previous build directory...
pushd C:\tmp
rmdir /s /q "%BUILD_DIR%" >nul 2>&1
mkdir "%BUILD_DIR%"
echo Cloning repository...
git clone --depth 1 "%PROJECT_REPO%" "%BUILD_DIR%"
if %ERRORLEVEL% NEQ 0 (
echo Git clone failed. Exiting.
exit /b %ERRORLEVEL%
)
) else (
echo Reusing existing build directory at "%BUILD_DIR%"
)
pushd "%BUILD_DIR%"
:: --- Fetch latest changes ---
echo Fetching latest changes...
git fetch origin --force --prune --prune-tags --depth 50 refs/heads/master:refs/remotes/origin/master
if %ERRORLEVEL% NEQ 0 (
echo Git fetch failed. Exiting.
exit /b %ERRORLEVEL%
)
:: --- Checkout master branch ---
echo Checking out master branch...
git checkout --force origin/master
if %ERRORLEVEL% NEQ 0 (
echo Git checkout failed. Exiting.
exit /b %ERRORLEVEL%
)
:: --- Setup Virtual Environment ---
if /i "%MODE%"=="new" (
echo Creating virtual environment for Python %PYTHON_VERSION%...
uv venv "%VENV_DIR%" --python %PYTHON_VERSION%
if %ERRORLEVEL% NEQ 0 (
echo Failed to create virtual environment. Exiting.
exit /b %ERRORLEVEL%
)
)
if not exist "%VENV_DIR%\Scripts\activate.bat" (
echo Virtual environment not found at "%VENV_DIR%".
echo Please run with 'new' mode first to create it.
exit /b 1
)
call "%VENV_DIR%\Scripts\activate.bat"
if %ERRORLEVEL% NEQ 0 (
echo Failed to activate virtual environment. Exiting.
exit /b %ERRORLEVEL%
)
if /i "%MODE%"=="new" (
:: --- Install Dependencies ---
echo Upgrading setuptools...
uv pip install --upgrade setuptools
if %ERRORLEVEL% NEQ 0 (
echo Failed to upgrade setuptools. Exiting.
exit /b %ERRORLEVEL%
)
echo Installing Sphinx...
uv pip install --upgrade sphinx
if %ERRORLEVEL% NEQ 0 (
echo Failed to install Sphinx. Exiting.
exit /b %ERRORLEVEL%
)
echo Installing project dependencies from pyproject.toml...
uv pip install --upgrade --no-cache-dir .[dev]
if %ERRORLEVEL% NEQ 0 (
echo Failed to install project dependencies. Exiting.
exit /b %ERRORLEVEL%
)
)
:: --- Build HTML Documentation ---
echo Building HTML documentation...
python -m sphinx -T -b html -d _build\doctrees -D language=en docs "%HTML_OUTPUT_DIR%"
if %ERRORLEVEL% NEQ 0 (
echo HTML build failed. Exiting.
exit /b %ERRORLEVEL%
)
echo.
echo HTML documentation built successfully in "%HTML_OUTPUT_DIR%"
echo run cd "%HTML_OUTPUT_DIR%" ^&^& python -m http.server %PORT%
echo to serve the documentation.
:: --- Launch Web Server and Open Docs ---
rem echo Launching a simple web server for the documentation...
rem start /b cmd /c "cd /d "%HTML_OUTPUT_DIR%" && python -m http.server %PORT%"
rem echo Opening documentation in your default browser...
rem start "" "http://localhost:%PORT%"
:: --- Optional: Build LaTeX/PDF (commented out) ---
:: echo Building LaTeX/PDF documentation...
:: python -m sphinx -T -b latex -d _build\doctrees -D language=en docs "%BUILD_DIR%\pdf"
:: if %ERRORLEVEL% NEQ 0 (
:: echo LaTeX build failed. Exiting.
:: exit /b %ERRORLEVEL%
:: )
::
:: echo Running latexmk to generate PDF...
:: cd "%BUILD_DIR%\pdf"
:: latexmk -r latexmkrc -pdf -f -dvi- -ps- -jobname=archivum-project -interaction=nonstopmode
:: if %ERRORLEVEL% NEQ 0 (
:: echo PDF generation failed. Exiting.
:: exit /b %ERRORLEVEL%
:: )
:: cd "%BUILD_DIR%"
::
:: echo PDF documentation built successfully in "%BUILD_DIR%\pdf"
endlocal