Repository navigation
Expand file tree
/
Copy pathsetup.bat
More file actions
165 lines (133 loc) · 4.37 KB
/
Copy pathsetup.bat
File metadata and controls
165 lines (133 loc) · 4.37 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
@echo off
setlocal
REM =============================================================
REM Optional argument: Python version for uv branch (default 3.13)
REM Usage: setup.bat [3.13]
REM =============================================================
set "PY_VER=%~1"
if "%PY_VER%"=="" set "PY_VER=3.13"
REM =============================================================
REM Configuration
REM =============================================================
REM Working directory for this project inside %TEMP%
set "WORK_DIR=%TEMP%\CMM"
REM Detect source repo:
REM - If we are inside a git repo: use that repo as source.
REM - Otherwise: clone from GitHub.
git rev-parse --show-toplevel >nul 2>&1
if errorlevel 1 (
echo Not in a git repository, using GitHub as source.
set "SOURCE_REPO=https://github.com/casact/capital-modeling"
) else (
for /f "delims=" %%G in ('git rev-parse --show-toplevel') do set "SOURCE_REPO=%%G"
echo Using local git repository as source: "%SOURCE_REPO%"
)
REM =============================================================
REM Prepare temporary working directory
REM =============================================================
if exist "%WORK_DIR%" (
echo Removing existing work directory "%WORK_DIR%" ...
rmdir /s /q "%WORK_DIR%"
)
echo Cloning "%SOURCE_REPO%" into "%WORK_DIR%" ...
git clone "%SOURCE_REPO%" "%WORK_DIR%"
if errorlevel 1 (
echo Git clone failed. Aborting.
goto :EOF
)
cd /d "%WORK_DIR%"
REM =============================================================
REM Detect uv
REM =============================================================
where uv >nul 2>&1
if not errorlevel 1 (
set "USE_UV=1"
) else (
set "USE_UV=0"
)
REM =============================================================
REM Virtual environment + deps
REM =============================================================
if "%USE_UV%"=="1" (
echo.
echo uv detected. Using uv with Python %PY_VER% ...
REM Pin project Python version
uv python pin %PY_VER%
if errorlevel 1 (
echo uv python pin %PY_VER% failed. Aborting.
goto :EOF
)
REM Create venv named "venv" using pinned / requested Python
uv venv venv --python %PY_VER%
if errorlevel 1 (
echo uv venv --python %PY_VER% failed. Aborting.
goto :EOF
)
call "venv\Scripts\activate.bat"
echo Installing dependencies with uv pip ...
uv pip install -r requirements.txt
if errorlevel 1 (
echo uv pip install failed. Aborting.
goto :EOF
)
) else (
echo.
echo uv not found. Falling back to python -m venv and pip ...
if not exist "venv" (
echo Creating virtual environment in "%WORK_DIR%\venv" ...
python -m venv venv
if errorlevel 1 (
echo python -m venv failed. Aborting.
goto :EOF
)
)
call "venv\Scripts\activate.bat"
echo Upgrading pip ...
python -m pip install --upgrade pip
echo Installing dependencies from requirements.txt ...
python -m pip install -r requirements.txt
if errorlevel 1 (
echo pip install failed. Aborting.
goto :EOF
)
)
REM =============================================================
REM Project: Full Rebuild
REM =============================================================
echo.
echo Rebuilding HTML book with Quarto...
echo.
where quarto >nul 2>&1
if errorlevel 1 (
echo.
echo Quarto is not installed or not on PATH.
echo Please install Quarto from https://quarto.org/docs/get-started/ before running this script.
echo Aborting.
goto :EOF
)
cd source
quarto render --to html
if errorlevel 1 (
echo Quarto render failed. Aborting.
goto :EOF
)
echo Quarto render successful, HTML book built.
REM =============================================================
REM Serve built site from docs and open in browser
REM =============================================================
cd /d "%WORK_DIR%\docs"
if not exist "index.html" (
echo Warning: index.html not found in %WORK_DIR%\docs
) else (
echo Output: %WORK_DIR%\docs
)
echo Starting web server on http://localhost:9955 ...
start "" python -m http.server 9955
REM Give the server a brief moment to start (optional but nice)
ping 127.0.0.1 -n 2 >nul
echo Opening index page in default browser...
start "" "http://localhost:9955/index.html"
echo.
echo Press Ctrl+C in the server window to stop the HTTP server.
echo.
endlocal