-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_exe.py
More file actions
86 lines (73 loc) · 2.45 KB
/
build_exe.py
File metadata and controls
86 lines (73 loc) · 2.45 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
#!/usr/bin/env python
"""
Build script to create executable for codestory CLI tool using PyInstaller.
Usage:
python build_lite.py
"""
import platform
import subprocess
import sys
from pathlib import Path
def main():
# Get the system platform
system = platform.system().lower()
is_windows = system == "windows"
# Define output directory and filenames
dist_path = Path("dist")
exe_name = "cst.exe" if is_windows else "cst"
# Entry point
entry_point = Path("src/codestory/cli.py")
if not entry_point.exists():
print(f"Error: Entry point {entry_point} not found.")
sys.exit(1)
# Ensure PyInstaller is installed
try:
subprocess.check_call(
[sys.executable, "-m", "PyInstaller", "--version"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
except (subprocess.CalledProcessError, FileNotFoundError):
print("PyInstaller not found. Installing...")
subprocess.check_call([sys.executable, "-m", "pip", "install", "pyinstaller"])
# Set up PyInstaller command
cmd = [
sys.executable,
"-m",
"PyInstaller",
"--onedir",
"--name",
exe_name.replace(".exe", ""),
"--clean",
# Include dynamically imported modules
"--hidden-import=tree_sitter_language_pack.bindings",
"--collect-all=tree_sitter_language_pack",
"--collect-all=aisuite",
"--collect-all=codestory",
# Lazy imports from embedder.py and clusterer.py
"--hidden-import=fastembed",
"--hidden-import=sklearn",
"--hidden-import=networkx",
# Include package data
"--copy-metadata=tree_sitter_language_pack",
"--copy-metadata=codestory-cli",
str(entry_point),
]
if is_windows:
cmd.append("--console")
print(f"Building {exe_name} for {system} using PyInstaller...")
print("Command:", " ".join(cmd))
try:
subprocess.check_call(cmd)
except subprocess.CalledProcessError as e:
print(f"Build failed with error code {e.returncode}")
sys.exit(e.returncode)
# Validation
target_output = dist_path / exe_name.replace(".exe", "") / exe_name
if target_output.exists():
print(f"Build successful! Artifact located at: {target_output}")
else:
print(f"Build finished but expected artifact {target_output} not found.")
sys.exit(1)
if __name__ == "__main__":
main()