forked from sbu-python-class/python-science
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatch-and-serve.bat
More file actions
98 lines (85 loc) · 2.59 KB
/
Copy pathwatch-and-serve.bat
File metadata and controls
98 lines (85 loc) · 2.59 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
@echo off
REM Script con hot reloading - usa watchdog para detectar cambios
echo ========================================
echo Hot Reloading del Jupyter Book
echo ========================================
echo.
REM Verificar y activar el entorno conda si es necesario
echo [1/4] Verificando entorno conda...
set "CONDA_ENV_PATH=%CD%\.conda"
set "NEEDS_ACTIVATION=0"
REM Comprobar si estamos en el entorno correcto
if defined CONDA_PREFIX (
if /I "%CONDA_PREFIX%"=="%CONDA_ENV_PATH%" (
echo [INFO] Ya estas en el entorno conda local correcto
) else (
echo [INFO] Estas en otro entorno conda, cambiando al entorno local...
set "NEEDS_ACTIVATION=1"
)
) else (
echo [INFO] Activando entorno conda local...
set "NEEDS_ACTIVATION=1"
)
if "%NEEDS_ACTIVATION%"=="1" (
call conda activate .\.conda
if %ERRORLEVEL% neq 0 (
echo ERROR: No se pudo activar el entorno conda local
pause
exit /b 1
)
echo Entorno activado correctamente.
)
echo.
REM Verificar e instalar watchdog si es necesario
echo [2/4] Verificando dependencias...
pip show watchdog >nul 2>&1
if %ERRORLEVEL% neq 0 (
echo Instalando watchdog...
pip install watchdog
echo.
)
REM Build inicial
echo [3/4] Construyendo libro inicial...
jupyter-book build content --keep-going
set "BUILD_ERROR=%ERRORLEVEL%"
if %BUILD_ERROR% neq 0 (
echo.
echo ADVERTENCIA: El build tuvo algunos errores, pero continuaremos...
)
echo.
REM Verificar que el build existe
if not exist "content\_build\html\index.html" (
echo ERROR: El build inicial fallo. No se encontro index.html
echo Revisa los errores arriba.
if "%NEEDS_ACTIVATION%"=="1" (
call conda deactivate
)
pause
exit /b 1
)
echo [4/4] Iniciando servidor y modo watch...
echo.
echo ========================================
echo COMO USAR:
echo ========================================
echo 1. El servidor esta en http://localhost:8000
echo 2. Edita archivos .md o .ipynb en content/
echo 3. Guarda los cambios (Ctrl+S)
echo 4. El libro se reconstruye automaticamente
echo 5. El navegador se RECARGA AUTOMATICAMENTE!
echo.
echo NUEVA CARACTERISTICA: Auto-reload del navegador
echo Ya no necesitas presionar F5 manualmente!
echo.
echo Presiona Ctrl+C para detener
echo.
REM Abrir navegador
echo Abriendo navegador en 3 segundos...
timeout /t 3 /nobreak > nul
start http://localhost:8000
REM Ejecutar el script de watch (v2 usa polling HTTP para mejor compatibilidad)
python watch_helper_v2.py
REM Desactivar entorno solo si lo activamos nosotros
if "%NEEDS_ACTIVATION%"=="1" (
call conda deactivate
)