-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
75 lines (59 loc) · 1.75 KB
/
Copy pathbuild.py
File metadata and controls
75 lines (59 loc) · 1.75 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
"""Build a standalone Windows .exe with PyInstaller.
Usage:
python build.py
Writes ``dist/StarlightFilter.exe``.
"""
from __future__ import annotations
import os
import shutil
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent
ICON = ROOT / "assets" / "icon.ico"
def ensure_pyinstaller() -> None:
try:
import PyInstaller # noqa: F401
return
except ImportError:
pass
print("PyInstaller not found — installing into the current environment...")
subprocess.check_call(
[sys.executable, "-m", "pip", "install", "pyinstaller"]
)
def build() -> Path:
ensure_pyinstaller()
cmd = [
sys.executable,
"-m",
"PyInstaller",
"--onefile",
"--windowed",
"--name",
"StarlightFilter",
"--noconfirm",
"--clean",
]
if ICON.exists():
cmd += ["--icon", str(ICON)]
# Bundle the icon so the running app can call iconbitmap() on it.
cmd += ["--add-data", f"{ICON}{os.pathsep}assets"]
else:
print(f"(no icon at {ICON}; building without one)")
# pystray's Windows backend is loaded dynamically; PyInstaller doesn't
# always trace it. Pin it explicitly so the tray icon works in the bundle.
cmd += [
"--hidden-import", "pystray._win32",
"--collect-submodules", "pystray",
"--collect-submodules", "PIL",
]
cmd += [str(ROOT / "run.py")]
print("Running:", " ".join(cmd))
subprocess.check_call(cmd, cwd=ROOT)
exe = ROOT / "dist" / "StarlightFilter.exe"
if not exe.exists():
raise SystemExit(f"Build finished but {exe} not found.")
print(f"\nBuilt: {exe}")
return exe
if __name__ == "__main__":
build()