-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch.bat
More file actions
116 lines (99 loc) · 3.45 KB
/
launch.bat
File metadata and controls
116 lines (99 loc) · 3.45 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
@echo off
setlocal ENABLEDELAYEDEXPANSION
REM === Config ===
set "VENV_DIR=.venv"
set "REQS=requirements.txt"
REM === Args ===
REM --no-activate -> skip activation at the end
set "AUTO_ACTIVATE=1"
if /i "%~1"=="--no-activate" set "AUTO_ACTIVATE=0"
REM === Move to this script's directory ===
cd /d "%~dp0"
REM === Locate Python (try 'py' then 'python') ===
set "PY="
where py >nul 2>&1 && set "PY=py"
if not defined PY (
where python >nul 2>&1 && set "PY=python"
)
if not defined PY (
echo [ERROR] Python not found. Install Python 3.x and ensure it's on PATH.
exit /b 1
)
REM === Create venv if missing ===
if not exist "%VENV_DIR%\Scripts\python.exe" (
echo [INFO] Creating virtual environment in "%VENV_DIR%" ...
%PY% -3 -m venv "%VENV_DIR%" 2>nul || %PY% -m venv "%VENV_DIR%"
if errorlevel 1 (
echo [ERROR] Failed to create virtual environment.
exit /b 1
)
) else (
echo [INFO] Using existing virtual environment: "%VENV_DIR%"
)
REM === Use venv's Python directly (no activation needed for installs) ===
set "VPY=%VENV_DIR%\Scripts\python.exe"
REM === Upgrade pip ===
echo [INFO] Upgrading pip ...
"%VPY%" -m pip install --upgrade pip
if errorlevel 1 (
echo [WARN] pip upgrade reported an error. Continuing...
)
REM === Install requirements or fallback to xlwings ===
if exist "%REQS%" (
echo [INFO] Installing packages from "%REQS%" ...
"%VPY%" -m pip install -r "%REQS%"
) else (
echo [INFO] "%REQS%" not found. Installing 'xlwings' only ...
"%VPY%" -m pip install xlwings
)
REM === Ensure spaCy is installed in the venv ===
set "SPACY_READY=1"
"%VPY%" -c "import importlib.util, sys; sys.exit(0 if importlib.util.find_spec('spacy') else 1)"
if errorlevel 1 (
echo [INFO] Installing spaCy package ...
"%VPY%" -m pip install spacy
if errorlevel 1 (
echo [WARN] Failed to install spaCy. Skipping spaCy model downloads.
set "SPACY_READY=0"
)
)
REM === Ensure spaCy Polish models are available (skip if already installed) ===
if "%SPACY_READY%"=="1" (
for %%M in (pl_core_news_sm pl_core_news_md pl_core_news_lg) do (
"%VPY%" -c "import importlib.util, sys; sys.exit(0 if importlib.util.find_spec('%%M') else 1)"
if errorlevel 1 (
echo [INFO] Installing spaCy model: %%M ...
"%VPY%" -m spacy download %%M
if errorlevel 1 (
echo [WARN] Failed to install spaCy model %%M. You can retry with:
echo "%VPY%" -m spacy download %%M
)
) else (
echo [INFO] spaCy model %%M already installed. Skipping.
)
)
) else (
echo [WARN] spaCy not available; skipping model downloads.
)
REM === ... everything above stays the same up to the echo line ===
echo.
REM Decide whether to activate
if "%AUTO_ACTIVATE%"=="1" goto :do_activate
echo [DONE] Environment ready.
echo To activate later in this shell, run:
echo %VENV_DIR%\Scripts\activate
echo.
endlocal
goto :eof
:do_activate
REM Build absolute path to the activate script using the script's folder
set "ACT=%~dp0%VENV_DIR%\Scripts\activate.bat"
if not exist "%ACT%" (
echo [ERROR] Activate script not found: "%ACT%"
echo [HINT] Check VENV_DIR or that the venv was created successfully.
endlocal
goto :eof
)
echo [INFO] Activating virtual environment in this shell...
REM IMPORTANT: endlocal first, then call activation so env changes persist
endlocal & call "%ACT%" & echo [DONE] Activated "%VENV_DIR%". & goto :eof