Repository navigation
Expand file tree
/
Copy pathsetup.bat
More file actions
103 lines (95 loc) · 4.24 KB
/
Copy pathsetup.bat
File metadata and controls
103 lines (95 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
@echo off
REM HELIX one-click setup for Windows - double-click me.
REM Creates an isolated .venv next to this script, installs HELIX with
REM the GUI extra into it, smoke-tests the install, and offers to
REM launch. Idempotent: re-running reuses the .venv and updates the
REM install (use it after "git pull").
REM
REM C++ PIC/field-map kernels are OPTIONAL: without MSVC Build Tools
REM the install still succeeds on a pure-Python fallback (the GUI notes
REM this at startup; PIC runs are ~20x slower).
REM
REM Non-interactive use: when CI is defined (GitHub Actions does this)
REM the launch prompt and the closing pause are skipped, so the script
REM is scriptable end-to-end. setup.sh has the same behaviour via its
REM TTY check.
REM
REM Style notes for maintainers: no %ERRORLEVEL% inside parenthesized
REM blocks (it expands at parse time there - use && / || or goto), and
REM status tests use "NEQ 0", never "if errorlevel 1" (hard crashes
REM exit with NEGATIVE codes that a >=1 test misses).
setlocal
cd /d "%~dp0"
if not exist "%~dp0pyproject.toml" (
echo ERROR: run this from a full HELIX checkout - pyproject.toml not found.
goto :fail
)
REM ---- long-path pre-flight (torch's deep dist-info vs MAX_PATH) ----
set "_P=%~dp0"
if not "%_P:~90,1%"=="" (
echo WARNING: this folder path is quite long. Windows' 260-character
echo MAX_PATH limit can break the install of torch. If the install
echo fails with WinError 206, either move HELIX to a shorter path
echo ^(e.g. C:\HELIX^) or enable Win32 long paths in Group Policy /
echo the registry ^(see the manual's Windows notes^).
echo.
)
REM ---- 1. find a Python 3.10+ --------------------------------------
REM (the versions torch publishes wheels for first, newest first, as setup.sh
REM does: "py -3" alone takes the newest installed, which can be too new)
set "_PY="
for %%V in (3.13 3.12 3.11 3.10) do if not defined _PY py -%%V -c "import sys" >nul 2>nul && set "_PY=py -%%V"
if not defined _PY py -3 -c "import sys; raise SystemExit(0 if sys.version_info >= (3,10) else 1)" >nul 2>nul && set "_PY=py -3"
if not defined _PY python -c "import sys; raise SystemExit(0 if sys.version_info >= (3,10) else 1)" >nul 2>nul && set "_PY=python"
if not defined _PY (
echo ERROR: HELIX needs Python 3.10 or newer and none was found.
echo Install it from https://www.python.org ^(tick "Add to PATH"^)
echo and double-click this file again.
goto :fail
)
echo Using interpreter: %_PY%
REM ---- 2. create / reuse the .venv and install ---------------------
if exist "%~dp0.venv\Scripts\python.exe" goto :have_venv
echo Creating virtual environment in .venv\ ...
%_PY% -m venv "%~dp0.venv"
if %ERRORLEVEL% NEQ 0 (
echo ERROR: could not create the virtual environment.
goto :fail
)
goto :venv_ready
:have_venv
echo Reusing existing .venv\
:venv_ready
set "_VPY=%~dp0.venv\Scripts\python.exe"
"%_VPY%" -m pip install --upgrade pip --quiet
"%_VPY%" -m pip install -e ".[gui]"
if %ERRORLEVEL% NEQ 0 (
echo.
echo ERROR: install failed. Common Windows causes:
echo - WinError 206: path too long, see the warning above
echo - no internet access / proxy blocking pypi.org
echo - a Python newer than torch supports: install Python 3.12 or 3.13
goto :fail
)
REM ---- 3. smoke test ----------------------------------------------
echo.
"%_VPY%" -c "import importlib.util, linac_gen, PyQt6; b = importlib.util.find_spec('linac_gen._pic_kernels') is not None; print('C++ kernels: built (fast PIC path active).' if b else 'C++ kernels: not built - pure-Python fallback (~20x slower PIC). To build them, install MSVC Build Tools and re-run setup.bat (see manual: Installation, Build prerequisites).'); print(f'Smoke test OK: linac_gen {linac_gen.__version__} with PyQt6.')"
if %ERRORLEVEL% NEQ 0 (
echo ERROR: the installed environment failed its smoke test.
goto :fail
)
REM ---- 4. done -----------------------------------------------------
echo.
echo Setup complete. Launch the GUI any time by double-clicking run_gui.bat
echo (it auto-detects the .venv created here).
if defined CI goto :done
set /p _ANS="Launch it now? [y/N] "
if /i "%_ANS%"=="y" start "" "%_VPY%" -m linac_gen_gui.interphase
:done
echo.
if not defined CI pause
exit /b 0
:fail
echo.
if not defined CI pause
exit /b 1