This repository was archived by the owner on Apr 18, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
134 lines (107 loc) · 3.74 KB
/
build.py
File metadata and controls
134 lines (107 loc) · 3.74 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env python3
"""
Build script for Dymo Code
Creates standalone executables for Windows, macOS, and Linux
Usage:
python build.py # Build for current platform
python build.py --clean # Clean build artifacts before building
python build.py --help # Show help
"""
import subprocess
import sys
import shutil
import platform
from pathlib import Path
def get_platform_info():
"""Get current platform information"""
system = platform.system().lower()
machine = platform.machine().lower()
if system == "windows": return "windows", "exe", f"dymo-code-windows-{machine}.exe"
elif system == "darwin": return "macos", "", f"dymo-code-macos-{machine}"
else: return "linux", "", f"dymo-code-linux-{machine}"
def clean_build():
"""Clean build artifacts"""
project_root = Path(__file__).parent
dirs_to_clean = ["build", "dist", "__pycache__"]
files_to_clean = ["*.pyc", "*.pyo", "*.spec.bak"]
for dir_name in dirs_to_clean:
dir_path = project_root / dir_name
if dir_path.exists():
print(f"Removing {dir_path}...")
shutil.rmtree(dir_path)
# Clean __pycache__ in subdirectories
for pycache in project_root.rglob("__pycache__"):
print(f"Removing {pycache}...")
shutil.rmtree(pycache)
print("Clean complete!")
def check_dependencies():
"""Check if required build dependencies are installed"""
try:
import PyInstaller
print(f"PyInstaller version: {PyInstaller.__version__}")
return True
except ImportError:
print("PyInstaller not found. Installing...")
subprocess.check_call([sys.executable, "-m", "pip", "install", "pyinstaller"])
return True
def build():
"""Build the executable"""
project_root = Path(__file__).parent
spec_file = project_root / "dymo-code.spec"
platform_name, ext, output_name = get_platform_info()
print(f"\n{'='*60}")
print(f"Building Dymo Code for {platform_name.upper()}")
print(f"{'='*60}\n")
# Check dependencies.
check_dependencies()
# Run PyInstaller.
cmd = [
sys.executable, "-m", "PyInstaller",
"--clean",
"--noconfirm",
str(spec_file)
]
print(f"Running: {' '.join(cmd)}\n")
result = subprocess.run(cmd, cwd=str(project_root))
if result.returncode != 0:
print(f"\nBuild failed with return code {result.returncode}")
sys.exit(1)
# Rename output to platform-specific name
dist_dir = project_root / "dist"
if platform_name == "windows":
original = dist_dir / "dymo-code.exe"
renamed = dist_dir / output_name
else:
original = dist_dir / "dymo-code"
renamed = dist_dir / output_name
if original.exists():
if renamed.exists(): renamed.unlink()
original.rename(renamed)
print(f"\n{'='*60}")
print(f"Build successful!")
print(f"Output: {renamed}")
print(f"Size: {renamed.stat().st_size / (1024*1024):.2f} MB")
print(f"{'='*60}\n")
else: print(f"\nWarning: Expected output file not found at {original}")
def show_help():
"""Show help message"""
print(__doc__)
print("\nPlatform-specific notes:")
print(" - Windows: Produces .exe file")
print(" - macOS: Produces Unix executable")
print(" - Linux: Produces Unix executable")
print("\nNote: Cross-compilation is not supported.")
print(" Build on each target platform separately.")
def main():
args = sys.argv[1:]
if "--help" in args or "-h" in args:
show_help()
return
if "--clean" in args:
clean_build()
args.remove("--clean")
if "--clean-only" in args:
clean_build()
return
build()
if __name__ == "__main__": main()