-
Notifications
You must be signed in to change notification settings - Fork 387
Expand file tree
/
Copy pathbuild.bat
More file actions
133 lines (117 loc) · 3.28 KB
/
build.bat
File metadata and controls
133 lines (117 loc) · 3.28 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
@echo off
REM OpenContext Build Script for Windows
REM Packages the project into a single executable using PyInstaller.
setlocal enabledelayedexpansion
echo === OpenContext Build Script ===
echo.
REM 1. Dependency Check
echo --^> Checking for python...
where py >nul 2>&1
if %errorlevel% equ 0 (
set PYTHON_CMD=py
) else (
where python >nul 2>&1
if errorlevel 1 (
echo Error: python is not found. Please install Python 3.
exit /b 1
)
set PYTHON_CMD=python
)
%PYTHON_CMD% --version
set USE_UV=false
REM 2. Check for uv and install dependencies
where uv >nul 2>&1
if %errorlevel% equ 0 (
echo --^> Using uv to install dependencies...
uv sync
if errorlevel 1 (
echo Error: uv sync failed.
exit /b 1
)
set USE_UV=true
) else (
echo --^> uv not found, using pip to install from pyproject.toml...
%PYTHON_CMD% -m pip install -e .
if errorlevel 1 (
echo Error: pip install failed.
exit /b 1
)
)
REM 3. Install PyInstaller if not present
if "!USE_UV!"=="true" (
REM Use uv run to ensure detection within the uv-managed virtual environment
uv run python -c "import PyInstaller" >nul 2>&1
if errorlevel 1 (
echo --^> PyInstaller not found ^(uv env^). Installing...
uv pip install pyinstaller
if errorlevel 1 (
echo Error: Failed to install PyInstaller with uv.
exit /b 1
)
)
) else (
%PYTHON_CMD% -c "import PyInstaller" >nul 2>&1
if errorlevel 1 (
echo --^> PyInstaller not found. Installing...
%PYTHON_CMD% -m pip install pyinstaller
if errorlevel 1 (
echo Error: Failed to install PyInstaller with pip.
exit /b 1
)
)
)
REM 4. Clean up previous builds
echo --^> Cleaning up previous build directories...
if exist dist rmdir /s /q dist
if exist build rmdir /s /q build
REM 5. Run PyInstaller build
echo --^> Starting application build with PyInstaller...
if "!USE_UV!"=="true" (
uv run pyinstaller --clean --noconfirm --log-level INFO opencontext.spec
) else (
pyinstaller --clean --noconfirm --log-level INFO opencontext.spec
)
if errorlevel 1 (
echo Error: PyInstaller build failed.
exit /b 1
)
REM 6. Verify build and package
echo --^> Verifying build output...
set EXECUTABLE_NAME=main
set ONEDIR_EXE=dist\%EXECUTABLE_NAME%\%EXECUTABLE_NAME%.exe
set BUILT_EXECUTABLE=
if exist "%ONEDIR_EXE%" (
set BUILT_EXECUTABLE=%ONEDIR_EXE%
)
if not "!BUILT_EXECUTABLE!"=="" (
echo Build successful!
echo.
echo --^> Executable is available in the 'dist\' directory.
dir dist
echo.
REM Copy config directory
if exist "config" (
echo --^> Copying 'config' directory to 'dist\'...
xcopy /E /I /Y config dist\config >nul
echo Config directory copied.
echo.
) else (
echo Warning: 'config' directory not found.
echo.
)
echo Build complete!
echo.
echo To run:
if exist "%ONEDIR_EXE%" (
echo cd dist\main ^&^& main.exe start
) else (
echo cd dist ^&^& main.exe start
)
echo.
echo Options: --port 9000 ^| --host 0.0.0.0 ^| --config config\config.yaml
echo.
) else (
echo Error: Build failed. Check the PyInstaller logs above for errors.
exit /b 1
)
endlocal