-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
74 lines (61 loc) · 1.98 KB
/
build.py
File metadata and controls
74 lines (61 loc) · 1.98 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
import os
import subprocess
import sys
import shutil
import time
from pathlib import Path
def build_executable():
print("Starting build process...")
# Clean previous builds
for dir_name in ["dist", "build"]:
if os.path.exists(dir_name):
print(f"Cleaning {dir_name} directory...")
shutil.rmtree(dir_name)
time.sleep(1)
# Ensure we're in the project root directory
project_root = Path(__file__).parent
os.chdir(project_root)
print(f"Working directory: {project_root}")
# Add src to PYTHONPATH
src_path = str(project_root / "src")
if "PYTHONPATH" in os.environ:
os.environ["PYTHONPATH"] = f"{src_path}{os.pathsep}{os.environ['PYTHONPATH']}"
else:
os.environ["PYTHONPATH"] = src_path
print(f"PYTHONPATH set to: {os.environ['PYTHONPATH']}")
try:
print("Running PyInstaller...")
# Build the executable using python -m
process = subprocess.run(
[
sys.executable,
"-m",
"PyInstaller",
"optimisation_ntn.spec",
"--clean",
"--noconfirm",
],
capture_output=True,
text=True,
)
# Print output regardless of success/failure
if process.stdout:
print("\nBuild Output:")
print(process.stdout)
if process.stderr:
print("\nBuild Errors/Warnings:")
print(process.stderr)
# Check if process was successful
process.check_returncode()
print(
"\nBuild completed successfully! Executable can be found in the 'dist' directory."
)
except subprocess.CalledProcessError as e:
print("\nError during build process!")
print(f"Return code: {e.returncode}")
sys.exit(1)
except Exception as e:
print(f"\nUnexpected error: {str(e)}")
sys.exit(1)
if __name__ == "__main__":
build_executable()