From a539b91762496cd07441d2472b9c830be1ea3f2a Mon Sep 17 00:00:00 2001 From: claudi Date: Tue, 14 Apr 2026 15:07:33 +0200 Subject: [PATCH] feat: Enhance Python environment detection in build scripts and improve project root resolution in PyInstaller spec --- build/scripts/build_macos.sh | 24 ++++++++++++++++++------ build/webdrop_bridge.spec | 23 ++++++++++++++++++++++- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/build/scripts/build_macos.sh b/build/scripts/build_macos.sh index afed596..49a58a9 100644 --- a/build/scripts/build_macos.sh +++ b/build/scripts/build_macos.sh @@ -35,6 +35,7 @@ APP_NAME="WebDropBridge" DMG_VOLUME_NAME="WebDrop Bridge" BUNDLE_IDENTIFIER="de.him_tools.webdrop-bridge" VERSION="" +PYTHON_BIN="" # Default .env file ENV_FILE="$PROJECT_ROOT/.env" @@ -81,7 +82,18 @@ if [ -z "$BRAND" ]; then BRAND="webdrop_bridge" fi -eval "$(python3 "$BRAND_HELPER" env --brand "$BRAND")" +if [ -x "$PROJECT_ROOT/.venv/bin/python" ]; then + PYTHON_BIN="$PROJECT_ROOT/.venv/bin/python" +elif command -v python3 &> /dev/null; then + PYTHON_BIN="$(command -v python3)" +fi + +if [ -z "$PYTHON_BIN" ]; then + echo "❌ Python 3 not found" + exit 1 +fi + +eval "$("$PYTHON_BIN" "$BRAND_HELPER" env --brand "$BRAND")" APP_NAME="$WEBDROP_ASSET_PREFIX" DMG_VOLUME_NAME="$WEBDROP_APP_DISPLAY_NAME" BUNDLE_IDENTIFIER="$WEBDROP_BUNDLE_ID" @@ -92,7 +104,7 @@ if [ -n "$WEBDROP_APP_DISPLAY_NAME" ]; then echo "🏷️ Building brand: $WEBDROP_APP_DISPLAY_NAME ($WEBDROP_BRAND_ID)" fi -VERSION="$(python3 -c "from pathlib import Path; import sys; sys.path.insert(0, str(Path(r'$BUILD_DIR/scripts').resolve())); from version_utils import get_current_version; print(get_current_version())")" +VERSION="$("$PYTHON_BIN" -c "from pathlib import Path; import sys; sys.path.insert(0, str(Path(r'$BUILD_DIR/scripts').resolve())); from version_utils import get_current_version; print(get_current_version())")" # Colors for output RED='\033[0;31m' @@ -159,14 +171,14 @@ check_prerequisites() { log_info "Checking prerequisites..." # Check Python - if ! command -v python3 &> /dev/null; then + if [ ! -x "$PYTHON_BIN" ]; then log_error "Python 3 not found" exit 1 fi - log_success "Python 3 found: $(python3 --version)" + log_success "Python 3 found: $($PYTHON_BIN --version)" # Check PyInstaller - if ! python3 -m pip show pyinstaller &> /dev/null; then + if ! "$PYTHON_BIN" -m pip show pyinstaller &> /dev/null; then log_error "PyInstaller not installed. Run: pip install pyinstaller" exit 1 fi @@ -222,7 +234,7 @@ build_executable() { export WEBDROP_VERSION="$VERSION" export WEBDROP_BUNDLE_ID="$BUNDLE_IDENTIFIER" - python3 -m PyInstaller \ + "$PYTHON_BIN" -m PyInstaller \ --distpath="$DIST_DIR" \ --workpath="$TEMP_BUILD" \ "$SPEC_FILE" diff --git a/build/webdrop_bridge.spec b/build/webdrop_bridge.spec index 3c56159..23e8fb8 100644 --- a/build/webdrop_bridge.spec +++ b/build/webdrop_bridge.spec @@ -11,8 +11,29 @@ import os project_root = Path.cwd() + if not (project_root / "src").exists(): - project_root = Path(__file__).resolve().parents[1] + env_root = os.environ.get("WEBDROP_PROJECT_ROOT") + if env_root: + candidate = Path(env_root).resolve() + if (candidate / "src").exists(): + project_root = candidate + +if not (project_root / "src").exists(): + # PyInstaller exposes SPECPATH while evaluating spec files. + spec_path = globals().get("SPECPATH") + if spec_path: + spec_candidate = Path(spec_path).resolve() + for candidate in (spec_candidate, spec_candidate.parent): + if (candidate / "src").exists(): + project_root = candidate + break + +if not (project_root / "src").exists(): + raise SystemExit( + "Unable to determine project root for PyInstaller spec. " + "Run from repository root or set WEBDROP_PROJECT_ROOT." + ) pathex = [str(project_root / "src")] entry_script = str(project_root / "src" / "webdrop_bridge" / "main.py")