-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
77 lines (61 loc) · 2.29 KB
/
build.py
File metadata and controls
77 lines (61 loc) · 2.29 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
import argparse
import os
import shutil
import subprocess
from pathlib import Path
PROJECT_ROOT = Path(__file__).resolve().parent
def venv_python() -> Path:
if os.name == "nt":
return PROJECT_ROOT / ".venv" / "Scripts" / "python.exe"
return PROJECT_ROOT / ".venv" / "bin" / "python"
def run(command: list[str]) -> None:
subprocess.run(command, cwd=PROJECT_ROOT, check=True)
def main() -> None:
parser = argparse.ArgumentParser(description="Cross-platform PyInstaller build helper for EqnPlot.")
parser.add_argument("--onefile", action="store_true", help="Build a single-file executable.")
parser.add_argument("--upx", action="store_true", help="Enable UPX compression.")
args = parser.parse_args()
python_exe = venv_python()
if not python_exe.exists():
raise SystemExit(f"Virtualenv Python not found: {python_exe}")
icon_path = PROJECT_ROOT / "assets" / "eqnplot-icon.ico"
data_separator = ";" if os.name == "nt" else ":"
print("Installing build tools...")
run([str(python_exe), "-m", "pip", "install", "--upgrade", "pip", "pyinstaller"])
print("Cleaning build/ and dist/ ...")
for directory in ("build", "dist"):
shutil.rmtree(PROJECT_ROOT / directory, ignore_errors=True)
if args.onefile:
print("Running PyInstaller in onefile mode...")
command = [
str(python_exe),
"-m",
"PyInstaller",
"--noconfirm",
"--clean",
"--windowed",
"--name",
"EqnPlot",
"--onefile",
"--specpath",
"build",
]
if not args.upx:
command.append("--noupx")
if icon_path.exists():
command += ["--icon", str(icon_path), "--add-data", f"{icon_path}{data_separator}assets"]
command.append("main.py")
run(command)
else:
print("Running PyInstaller with EqnPlot.spec...")
env = os.environ.copy()
env["EQNPLOT_USE_UPX"] = "1" if args.upx else "0"
subprocess.run(
[str(python_exe), "-m", "PyInstaller", "--noconfirm", "--clean", "EqnPlot.spec"],
cwd=PROJECT_ROOT,
check=True,
env=env,
)
print("Build complete. Output is in dist/")
if __name__ == "__main__":
main()