From b4c2bf500d1939d93f1c2146798842d5f98902de Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Wed, 25 Jun 2025 00:17:14 -0500 Subject: pyinstaller support --- .gitignore | 2 ++ flaskapi.py | 7 ++++--- manager.py | 21 +++++++++++++++++++++ pix.spec | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 pix.spec diff --git a/.gitignore b/.gitignore index 4197899..40f82d2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ __pycache__ +build +dist *.jpg *.json diff --git a/flaskapi.py b/flaskapi.py index 633eed2..7d10a7e 100644 --- a/flaskapi.py +++ b/flaskapi.py @@ -1,14 +1,15 @@ from flask import Flask, Blueprint, request, send_from_directory, send_file, abort, redirect, jsonify from flask_socketio import SocketIO, emit from flask_cors import CORS +from engineio.async_drivers import threading # For pyinstaller from manager import PixMan from settings import Config -app = Flask(__name__, static_folder="static/dist", static_url_path="/") +app = Flask(__name__, static_folder=PixMan().static_dir, static_url_path="/") api = Blueprint("api", __name__) -socketio = SocketIO(app, cors_allowed_origins="*") # NOTE debug +socketio = SocketIO(app, async_mode="threading", cors_allowed_origins="*") # NOTE debug, async_mode for pyinstaller CORS(api, origins="*") # NOTE debug @@ -17,7 +18,7 @@ CORS(api, origins="*") # NOTE debug @app.route("/albums") @app.route("/settings") def home(): - return send_from_directory("static/public", "index.html") + return send_from_directory(PixMan().static_public, "index.html") @socketio.on("seek") diff --git a/manager.py b/manager.py index 6a6498e..275e6b2 100644 --- a/manager.py +++ b/manager.py @@ -3,6 +3,7 @@ import sys import signal import copy from threading import Thread +from pathlib import Path from OpenGL.GLUT import glutLeaveMainLoop @@ -109,6 +110,26 @@ class PixMan: return True + @property + def frozen(self): + # For pyinstaller + # https://api.arcade.academy/en/latest/tutorials/bundling_with_pyinstaller/index.html#handling-data-files + if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"): + return True + return False + + @property + def static_dir(self): + if self.frozen: + return Path(sys._MEIPASS) / "static" + return Path("./static/dist") + + @property + def static_public(self): + if self.frozen: + return Path(sys._MEIPASS) / "public" + return Path("./static/public") + from lazycachelist import LazyCachingTextureList from window import PixDisplay diff --git a/pix.spec b/pix.spec new file mode 100644 index 0000000..c14fa14 --- /dev/null +++ b/pix.spec @@ -0,0 +1,38 @@ +# -*- mode: python ; coding: utf-8 -*- + + +a = Analysis( + ['pix.py'], + pathex=[], + binaries=[], + datas=[('./static/dist', 'static'), ('./static/public', 'public')], + hiddenimports=['flask_socketio', 'engineio'], + hookspath=[], + hooksconfig={}, + runtime_hooks=[], + excludes=[], + noarchive=False, + optimize=0, +) +pyz = PYZ(a.pure) + +exe = EXE( + pyz, + a.scripts, + a.binaries, + a.datas, + [], + name='pix', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + upx_exclude=[], + runtime_tmpdir=None, + console=True, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, +) -- cgit v1.2.3