-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.py
More file actions
83 lines (67 loc) · 2.22 KB
/
build.py
File metadata and controls
83 lines (67 loc) · 2.22 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
import shutil
import subprocess
import sys
import tomllib # Python 3.11+
from pathlib import Path
# Paths
PROJECT_ROOT = Path(__file__).parent
PYPROJECT_PATH = PROJECT_ROOT / "pyproject.toml"
SRC_ENTRY = PROJECT_ROOT / "src" / "MaskMapWizard" / "__main__.py"
HOOKS_DIR = PROJECT_ROOT / "hooks"
ICON_PATH = PROJECT_ROOT / "assets" / "icon.ico"
BUILD_DIR = PROJECT_ROOT / "build"
DIST_DIR = PROJECT_ROOT / "dist"
SPEC_DIR = BUILD_DIR / "specs"
ONEFILE = True # Set to False for debugging
def read_project_metadata():
"""Read project name and version from pyproject.toml"""
try:
with PYPROJECT_PATH.open("rb") as f:
data = tomllib.load(f)
name = data["project"]["name"]
version = data["project"]["version"]
return name, version
except Exception as e:
print(f"❌ Failed to read metadata from pyproject.toml: {e}")
sys.exit(1)
def clean_previous_builds():
"""Remove build/ and dist/ directories before a new build"""
for folder in [BUILD_DIR, DIST_DIR]:
if folder.exists():
print(f"🗑️ Removing {folder}")
shutil.rmtree(folder)
def build():
"""Run PyInstaller build command"""
cmd = [
"pyinstaller",
"--name",
BUILD_NAME,
"--additional-hooks-dir",
str(HOOKS_DIR),
"--icon",
str(ICON_PATH),
"--noconsole",
f"--specpath={SPEC_DIR}",
f"--distpath={DIST_DIR}",
f"--workpath={BUILD_DIR / 'work'}",
str(SRC_ENTRY),
]
cmd.append("--onefile" if ONEFILE else "--onedir")
print("🔨 Building with:")
print(" " + " ".join(cmd))
subprocess.run(cmd, check=True)
print(f"\n✅ Build completed: dist/{BUILD_NAME}/")
if __name__ == "__main__":
# Read project name + version
name, version = read_project_metadata()
BUILD_NAME = f"{name}_v{version}"
# Validate important files
if not HOOKS_DIR.exists() or not (HOOKS_DIR / "hook-tkinterdnd2.py").exists():
print("❌ Missing hook: ./hooks/hook-tkinterdnd2.py")
sys.exit(1)
if not ICON_PATH.exists():
print("❌ Missing icon file: ./assets/icon.ico")
sys.exit(1)
# Clean and build
clean_previous_builds()
build()