"""Builds the desktop programs into dist/: python -m pip install pyinstaller pywebview pillow python packaging/build.py Windows: dist/DSP Control.exe desktop app (own window, no PIN; optional remote access with PIN) dist/DSP Control Pi Writer.exe SD card writer for a Raspberry Pi running the WebUI macOS: dist/DSP Control.app the same desktop app dist/DSP Control.dmg disk image with the app and a link to /Applications """ import shutil import subprocess import sys import tempfile from pathlib import Path ROOT = Path(__file__).resolve().parent.parent SEP = ";" if sys.platform == "win32" else ":" def pyinstaller(*args, onefile=True): cmd = [sys.executable, "-m", "PyInstaller", "--noconfirm", "--onefile" if onefile else "--onedir", "--windowed", "--distpath", str(ROOT / "dist"), "--workpath", str(ROOT / "build"), "--specpath", str(ROOT / "build"), *args] print(">", " ".join(cmd)) subprocess.run(cmd, cwd=ROOT, check=True) def data(src, dest="."): return ["--add-data", f"{ROOT / src}{SEP}{dest}"] def build_mac(): app = ROOT / "dist" / "DSP Control.app" pyinstaller("--name", "DSP Control", "--icon", str(ROOT / "packaging" / "dsp-control.icns"), "--osx-bundle-identifier", "at.thiemoo.dspcontrol", *data("static", "static"), str(ROOT / "desktop.py"), onefile=False) # a .app bundle is always a folder shutil.rmtree(ROOT / "dist" / "DSP Control", ignore_errors=True) # the loose onedir copy next to the .app dmg = ROOT / "dist" / "DSP Control.dmg" dmg.unlink(missing_ok=True) with tempfile.TemporaryDirectory() as tmp: shutil.copytree(app, Path(tmp) / app.name, symlinks=True) (Path(tmp) / "Applications").symlink_to("/Applications") subprocess.run(["hdiutil", "create", "-volname", "DSP Control", "-srcfolder", tmp, "-ov", "-format", "UDZO", str(dmg)], check=True) print("\nDone:", app.name, dmg.name, sep="\n ") subprocess.run([sys.executable, str(ROOT / "packaging" / "make_icons.py")], check=True) if sys.platform == "darwin": build_mac() sys.exit() pyinstaller("--name", "DSP Control", "--icon", str(ROOT / "packaging" / "dsp-control.ico"), *data("static", "static"), str(ROOT / "desktop.py")) pyinstaller("--name", "DSP Control Pi Writer", "--icon", str(ROOT / "packaging" / "pi-writer.ico"), "--uac-admin", *data("server.py"), *data("sim.py"), *data("dsp", "dsp"), *data("static", "static"), str(ROOT / "pi_writer.py")) print("\nDone:", *(p.name for p in (ROOT / "dist").glob("*.exe")), sep="\n ")