#!/usr/bin/env python3 """ Simple build script for standalone executable """ import os import shutil import sys from pathlib import Path def main(): print("Building Ping River Monitor Executable") print("=" * 50) # Check if PyInstaller is installed try: import PyInstaller print("[OK] PyInstaller available") except ImportError: print("[INFO] Installing PyInstaller...") os.system("uv add --dev pyinstaller") # Clean previous builds if os.path.exists("dist"): shutil.rmtree("dist") print("[CLEAN] Removed old dist directory") if os.path.exists("build"): shutil.rmtree("build") print("[CLEAN] Removed old build directory") # Build command with all necessary options cmd = [ "uv", "run", "pyinstaller", "--onefile", "--console", "--name=ping-river-monitor", "--add-data=.env;.", "--add-data=sql;sql", "--add-data=README.md;.", "--add-data=POSTGRESQL_SETUP.md;.", "--add-data=SQLITE_MIGRATION.md;.", "--hidden-import=psycopg2", "--hidden-import=sqlalchemy.dialects.postgresql", "--hidden-import=sqlalchemy.dialects.sqlite", "--hidden-import=dotenv", "--hidden-import=pydantic", "--hidden-import=fastapi", "--hidden-import=uvicorn", "--hidden-import=schedule", "--hidden-import=pandas", "--clean", "--noconfirm", "run.py", ] print("[BUILD] Running PyInstaller...") print("[CMD] " + " ".join(cmd)) result = os.system(" ".join(cmd)) if result == 0: print("[SUCCESS] Executable built successfully!") # Copy .env file to dist if it exists if os.path.exists(".env") and os.path.exists("dist"): shutil.copy2(".env", "dist/.env") print("[COPY] .env file copied to dist/") # Create batch files for easy usage batch_files = { "start.bat": """@echo off echo Starting Ping River Monitor... ping-river-monitor.exe pause """, "start-api.bat": """@echo off echo Starting Web API... ping-river-monitor.exe --web-api pause """, "test.bat": """@echo off echo Running test... ping-river-monitor.exe --test pause """, } for filename, content in batch_files.items(): if os.path.exists("dist"): with open(f"dist/{filename}", "w") as f: f.write(content) print(f"[CREATE] {filename}") print("\n" + "=" * 50) print("BUILD COMPLETE!") print(f"Executable: dist/ping-river-monitor.exe") print("Batch files: start.bat, start-api.bat, test.bat") print("Don't forget to edit .env file before using!") return True else: print("[ERROR] Build failed!") return False if __name__ == "__main__": success = main() sys.exit(0 if success else 1)