ppt-web / build.bat
26fwyzpz6f-max
Clean deploy without binary files
6aecb2e
Raw
History Blame Contribute Delete
6.9 kB
@echo off
chcp 65001 >nul
setlocal EnableExtensions EnableDelayedExpansion
goto :main
:fail
set "EXIT_CODE=%~1"
if not defined EXIT_CODE set "EXIT_CODE=1"
echo.
echo [ERROR] Build failed.
echo Please check build.log in the project root.
echo.
if exist "%BUILD_LOG%" (
echo Last log lines:
echo ------------------------------------------------------------
powershell -NoProfile -ExecutionPolicy Bypass -Command "if (Test-Path '%BUILD_LOG%') { Get-Content '%BUILD_LOG%' -Tail 80 }"
echo ------------------------------------------------------------
)
echo.
pause
exit /b %EXIT_CODE%
:main
cd /d "%~dp0" || goto fail
set "BUILD_LOG=%~dp0build.log"
>"%BUILD_LOG%" (
echo LandPPT build started at %date% %time%
echo Workdir: %cd%
echo ================================================
)
echo LandPPT build script started.
echo Current directory: %cd%
echo Log file: %BUILD_LOG%
echo.
set "PYTHON_CMD="
if exist ".venv\Scripts\python.exe" set "PYTHON_CMD=.venv\Scripts\python.exe"
if not defined PYTHON_CMD where python >nul 2>nul && set "PYTHON_CMD=python"
if not defined PYTHON_CMD (
echo [ERROR] Python not found.
>>"%BUILD_LOG%" echo [ERROR] Python not found.
goto fail
)
echo Checking Python...
"%PYTHON_CMD%" --version >> "%BUILD_LOG%" 2>&1
if errorlevel 1 goto fail
echo Checking pip...
"%PYTHON_CMD%" -m pip --version >> "%BUILD_LOG%" 2>&1
if errorlevel 1 (
echo pip not found, bootstrapping pip...
"!PYTHON_CMD!" -m ensurepip --upgrade >> "%BUILD_LOG%" 2>&1
if errorlevel 1 (
powershell -NoProfile -ExecutionPolicy Bypass -Command "Invoke-WebRequest -UseBasicParsing https://bootstrap.pypa.io/get-pip.py -OutFile get-pip.py" >> "%BUILD_LOG%" 2>&1
if errorlevel 1 goto fail
"!PYTHON_CMD!" get-pip.py >> "%BUILD_LOG%" 2>&1
if errorlevel 1 goto fail
del /q get-pip.py >nul 2>&1
)
)
echo Installing/checking runtime dependencies from pyproject.toml...
>>"%BUILD_LOG%" echo Installing/checking runtime dependencies from pyproject.toml...
"%PYTHON_CMD%" -m pip install --upgrade pip setuptools wheel >> "%BUILD_LOG%" 2>&1
if errorlevel 1 goto fail
"%PYTHON_CMD%" -m pip install -e . >> "%BUILD_LOG%" 2>&1
if errorlevel 1 goto fail
"%PYTHON_CMD%" -m pip install pyinstaller aiosqlite >> "%BUILD_LOG%" 2>&1
if errorlevel 1 goto fail
echo Running preflight import checks...
>>"%BUILD_LOG%" echo Running preflight import checks...
"%PYTHON_CMD%" -c "import fastapi,uvicorn,jinja2,sqlalchemy,aiosqlite,sqlite3,httpx,aiofiles,PIL,requests,dotenv,bs4,markdown,docx,PyPDF2,passlib,jose,pydantic_settings,openai,anthropic,tiktoken,aiohttp,rich,chardet,pandas; import landppt.main; print('preflight ok')" >> "%BUILD_LOG%" 2>&1
if errorlevel 1 goto fail
set "ICON_ARG=--icon=NONE"
if exist "src\landppt\web\static\images\landppt-logo.ico" set "ICON_ARG=--icon=src\landppt\web\static\images\landppt-logo.ico"
if not exist "src\landppt\web\static\images\landppt-logo.ico" if exist "src\landppt\web\static\images\favicon.ico" set "ICON_ARG=--icon=src\landppt\web\static\images\favicon.ico"
if "%ICON_ARG%"=="--icon=NONE" if exist "logo_256x256.ico" set "ICON_ARG=--icon=logo_256x256.ico"
echo Cleaning old build files...
if exist build rmdir /s /q build
if exist dist rmdir /s /q dist
echo Running PyInstaller. This may take several minutes...
>>"%BUILD_LOG%" echo Running PyInstaller...
"%PYTHON_CMD%" -m PyInstaller ^
--noconfirm ^
--clean ^
--onedir ^
--name LandPPT ^
--paths "src" ^
%ICON_ARG% ^
--add-data="src\landppt\web\templates:src\landppt\web\templates" ^
--add-data="src\landppt\web\static:src\landppt\web\static" ^
--add-data="API 配置:API 配置" ^
--collect-submodules aiosqlite ^
--collect-submodules sqlalchemy.dialects.sqlite ^
--collect-submodules uvicorn ^
--collect-submodules fastapi ^
--collect-submodules starlette ^
--collect-submodules pydantic ^
--collect-submodules pydantic_settings ^
--collect-submodules passlib ^
--collect-submodules jose ^
--collect-submodules openai ^
--collect-submodules anthropic ^
--collect-submodules google.generativeai ^
--collect-submodules PIL ^
--collect-data fastapi ^
--collect-data starlette ^
--collect-data pydantic ^
--copy-metadata aiosqlite ^
--copy-metadata sqlalchemy ^
--copy-metadata fastapi ^
--copy-metadata starlette ^
--copy-metadata uvicorn ^
--copy-metadata pydantic ^
--copy-metadata pydantic-settings ^
--copy-metadata python-dotenv ^
--hidden-import landppt.main ^
--hidden-import aiosqlite ^
--hidden-import sqlite3 ^
--hidden-import sqlalchemy.dialects.sqlite.aiosqlite ^
--hidden-import dotenv ^
--hidden-import multipart ^
--hidden-import email_validator ^
--hidden-import bs4 ^
--hidden-import markdown ^
--hidden-import docx ^
--hidden-import PyPDF2 ^
--hidden-import passlib.handlers.bcrypt ^
--hidden-import jose ^
--hidden-import pydantic_settings ^
--hidden-import openai ^
--hidden-import anthropic ^
--hidden-import tiktoken ^
--hidden-import aiohttp ^
--hidden-import rich ^
--hidden-import chardet ^
--hidden-import pandas ^
run.py >> "%BUILD_LOG%" 2>&1
if errorlevel 1 goto fail
if exist "dist\LandPPT" (
if not exist "dist\LandPPT\temp" mkdir "dist\LandPPT\temp"
>"dist\LandPPT\run_exe_debug.bat" echo @echo off
>>"dist\LandPPT\run_exe_debug.bat" echo chcp 65001 ^>nul
>>"dist\LandPPT\run_exe_debug.bat" echo cd /d "%%~dp0"
>>"dist\LandPPT\run_exe_debug.bat" echo echo Starting LandPPT.exe in debug mode...
>>"dist\LandPPT\run_exe_debug.bat" echo echo.
>>"dist\LandPPT\run_exe_debug.bat" echo LandPPT.exe
>>"dist\LandPPT\run_exe_debug.bat" echo echo.
>>"dist\LandPPT\run_exe_debug.bat" echo echo LandPPT.exe exited with code %%ERRORLEVEL%%
>>"dist\LandPPT\run_exe_debug.bat" echo if exist landppt_startup_error.log ^(
>>"dist\LandPPT\run_exe_debug.bat" echo echo.
>>"dist\LandPPT\run_exe_debug.bat" echo echo Last startup error log:
>>"dist\LandPPT\run_exe_debug.bat" echo echo ------------------------------------------------------------
>>"dist\LandPPT\run_exe_debug.bat" echo powershell -NoProfile -ExecutionPolicy Bypass -Command "Get-Content 'landppt_startup_error.log' -Tail 120"
>>"dist\LandPPT\run_exe_debug.bat" echo echo ------------------------------------------------------------
>>"dist\LandPPT\run_exe_debug.bat" echo ^)
>>"dist\LandPPT\run_exe_debug.bat" echo pause
)
echo.
echo [OK] Build finished successfully.
echo Output: dist\LandPPT\LandPPT.exe
echo Debug launcher: dist\LandPPT\run_exe_debug.bat
>>"%BUILD_LOG%" echo [OK] Build finished successfully.
>>"%BUILD_LOG%" echo Output: dist\LandPPT\LandPPT.exe
echo.
pause
exit /b 0