From a09561656907523265db86137299b09472a16b8b Mon Sep 17 00:00:00 2001 From: kqjy Date: Sat, 22 Nov 2025 20:32:57 +0800 Subject: [PATCH] Prepare for binary release --- app/__init__.py | 6 +++++- app/config.py | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 3ea9264..c86e458 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -35,7 +35,11 @@ def create_app( """Create and configure the Flask application.""" config = AppConfig.from_env(test_config) - project_root = Path(__file__).resolve().parent.parent + if getattr(sys, "frozen", False): + project_root = Path(sys._MEIPASS) + else: + project_root = Path(__file__).resolve().parent.parent + app = Flask( __name__, static_folder=str(project_root / "static"), diff --git a/app/config.py b/app/config.py index 2033cbd..b5fa037 100644 --- a/app/config.py +++ b/app/config.py @@ -4,12 +4,18 @@ from __future__ import annotations import os import secrets import shutil +import sys import warnings from dataclasses import dataclass from pathlib import Path from typing import Any, Dict, Optional -PROJECT_ROOT = Path(__file__).resolve().parent.parent +if getattr(sys, "frozen", False): + # Running in a PyInstaller bundle + PROJECT_ROOT = Path(sys._MEIPASS) +else: + # Running in a normal Python environment + PROJECT_ROOT = Path(__file__).resolve().parent.parent def _prepare_config_file(active_path: Path, legacy_path: Optional[Path] = None) -> Path: -- 2.49.1