File size: 1,754 Bytes
a02272f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279ebac
a02272f
 
 
 
 
 
 
 
 
 
 
279ebac
a02272f
 
 
 
 
 
 
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
import os
import subprocess
import sys
from pathlib import Path

def package():
    print("--- Brain CLI Packaging Tool ---")
    
    # 1. Resolve paths
    # We assume this script is in <root>/scripts/
    script_dir = Path(__file__).resolve().parent
    root_dir = script_dir.parent
    entry_point = root_dir / "run.py"
    
    print(f"Project Root: {root_dir}")
    print(f"Entry Point:  {entry_point}")
    
    # 2. Verify entry point exists
    if not entry_point.exists():
        print(f"ERROR: Cannot find '{entry_point}'")
        print("Please ensure you are running this from the project root or the scripts folder.")
        return

    # 3. Clean previous builds
    dist_dir = root_dir / "dist"
    build_dir = root_dir / "build"
    spec_file = root_dir / "brain.spec"
    
    # 4. Define PyInstaller command
    # --onefile: Single EXE
    # --paths: Add root to python path so 'import brain' works
    # --add-data: Include templates
    
    separator = ";" if os.name == "nt" else ":"
    
    cmd = [
        "pyinstaller",
        "--onefile",
        "--name", "ever-brain",
        "--paths", str(root_dir),
        "--add-data", f"brain/templates{separator}brain/templates",
        "--clean",
        str(entry_point)
    ]
    
    print(f"Running Command: {' '.join(cmd)}\n")
    
    try:
        # Run from root_dir so relative paths in --add-data work
        subprocess.run(cmd, check=True, cwd=str(root_dir))
        print(f"\nSUCCESS! Your CLI is ready at: {root_dir / 'dist' / 'ever-brain.exe'}")
    except subprocess.CalledProcessError as e:
        print(f"\nERROR during packaging: {e}")
    except Exception as e:
        print(f"\nAN UNEXPECTED ERROR OCCURRED: {e}")

if __name__ == "__main__":
    package()