compiler.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # -*- coding: utf-8 -*-
  2. """
  3. A.L.I.G. - Advanced Laser Imaging Generator
  4. ===========================================
  5. Compiler script for ALIG Qt version 0.99b
  6. Author: Alexandre "MoMo"
  7. Only works for windows, as it uses PyInstaller to create a standalone executable.
  8. """
  9. import os
  10. import sys
  11. import subprocess
  12. import shutil
  13. # --- CONFIGURATION ---
  14. VERSION = "0.99b"
  15. EXE_NAME = f"ALIG_v{VERSION}"
  16. MAIN_SCRIPT = "main_qt.py"
  17. # Use absolute paths to prevent "File Not Found" errors
  18. BASE_DIR = os.path.dirname(os.path.abspath(__file__))
  19. ICON_PATH = os.path.join(BASE_DIR, "assets", "logo_alig.ico")
  20. def run_compilation():
  21. # 1. Cleaning old builds to avoid conflicts
  22. print("Cleaning old build and dist folders...")
  23. for folder in ['build', 'dist']:
  24. full_path = os.path.join(BASE_DIR, folder)
  25. if os.path.exists(full_path):
  26. try:
  27. shutil.rmtree(full_path)
  28. except Exception as e:
  29. print(f"Warning: Could not delete {folder}. Ensure the folder or EXE is not open.")
  30. # 2. Icon verification
  31. if not os.path.exists(ICON_PATH):
  32. print(f"ERROR: Icon not found at: {ICON_PATH}")
  33. print("Verify that the 'assets' folder is in the same directory as this script.")
  34. return
  35. # 3. Parameters construction
  36. # Note: os.pathsep is used for portability (; on Windows)
  37. params = [
  38. 'pyinstaller',
  39. '--name', EXE_NAME,
  40. '--onefile',
  41. '--clean',
  42. '--noconfirm',
  43. '--windowed',
  44. '--add-data', f'{os.path.join(BASE_DIR, "assets")}{os.pathsep}assets',
  45. '--hidden-import', 'PIL.Image',
  46. '--icon', ICON_PATH,
  47. MAIN_SCRIPT
  48. ]
  49. # 4. Execution
  50. try:
  51. print(f"Starting ALIG {VERSION} compilation...")
  52. # Force execution in the script directory
  53. subprocess.check_call(params, cwd=BASE_DIR)
  54. print("\n" + "="*30)
  55. print(f"SUCCESS: The executable is available in the 'dist' folder.")
  56. print(f"File: {EXE_NAME}.exe")
  57. print("="*30)
  58. except subprocess.CalledProcessError as e:
  59. print(f"PyInstaller Error: {e}")
  60. except Exception as e:
  61. print(f"Unexpected Error: {e}")
  62. if __name__ == "__main__":
  63. # RECOMMENDATION: If using Synology Drive, copy the project to Desktop before running.
  64. run_compilation()