@@ -70,12 +70,11 @@ cp -R "$ROOT_DIR/npx/python/cr" "$STAGE_DIR/app/python/"
7070# Copy pyproject.toml so package detection works
7171cp " $ROOT_DIR /npx/python/pyproject.toml" " $STAGE_DIR /app/python/"
7272
73- # 3) Install python deps into pydeps (no venv)
74- echo " ==> Installing python deps into pydeps/ (no venv)"
75- # Find a working system python with pip (avoid venv issues)
76- # Check python3 from PATH first (GitHub Actions sets this up), then homebrew, then system
73+ # 3) Bundle Python deps for instant start (+ requirements.txt as fallback if Python version mismatch)
74+ echo " ==> Installing python deps into pydeps/ (bundled for instant start)"
75+ # Find a working system python with pip
7776SYS_PYTHON=" "
78- for py in python3 python3.12 /opt/homebrew/opt/python@3.12/bin/python3.12 /opt/homebrew/bin/python3 /usr/local/bin/python3 /usr/bin/python3; do
77+ for py in python3 python3.11 /opt/homebrew/bin/python3 /usr/local/bin/python3 /usr/bin/python3; do
7978 if command -v " $py " > /dev/null 2>&1 && " $py " -m pip --version > /dev/null 2>&1 ; then
8079 SYS_PYTHON=" $py "
8180 break
@@ -86,15 +85,17 @@ if [ -z "$SYS_PYTHON" ]; then
8685 exit 1
8786fi
8887echo " ==> Using Python: $SYS_PYTHON "
89- # Create a temporary requirements file pointing to the python package
90- cat > " $STAGE_DIR /pydeps_install.txt" << EOF
88+
89+ # Create requirements.txt (used as fallback if bundled deps fail)
90+ cat > " $STAGE_DIR /requirements.txt" << EOF
9191dspy>=3.1.2
9292rich>=13.0.0
9393python-dotenv>=1.0.0
9494httpx>=0.28.1
9595EOF
96- " $SYS_PYTHON " -m pip install --break-system-packages --target " $STAGE_DIR /pydeps" -r " $STAGE_DIR /pydeps_install.txt"
97- rm " $STAGE_DIR /pydeps_install.txt"
96+
97+ # Bundle deps (instant start for matching Python versions)
98+ " $SYS_PYTHON " -m pip install --break-system-packages --target " $STAGE_DIR /pydeps" -r " $STAGE_DIR /requirements.txt"
9899
99100# 4) Download and bundle Deno (no runtime install scripts)
100101echo " ==> Downloading deno binary"
@@ -135,6 +136,36 @@ export PATH="$RUNTIME_ROOT/bin:$PATH"
135136export PYTHONPATH="$RUNTIME_ROOT/pydeps:$RUNTIME_ROOT/app/python"
136137export DENO_DIR="${DENO_DIR:-$RUNTIME_ROOT/.deno_cache}"
137138
139+ # Verify bundled Python deps work (may fail if Python version mismatches CI/CD build)
140+ # If they fail, reinstall with user's local pip
141+ DEPS_VERIFIED="$RUNTIME_ROOT/pydeps/.verified"
142+ if [ ! -f "$DEPS_VERIFIED" ]; then
143+ # Find Python
144+ PYTHON=""
145+ for py in python3 python3.12 python3.11 /opt/homebrew/bin/python3 /usr/local/bin/python3 /usr/bin/python3; do
146+ if command -v "$py" >/dev/null 2>&1; then
147+ PYTHON="$py"
148+ break
149+ fi
150+ done
151+
152+ if [ -z "$PYTHON" ]; then
153+ echo "ERROR: Python 3 not found. Please install Python 3.11+." >&2
154+ exit 1
155+ fi
156+
157+ # Test if bundled deps work (pydantic_core is the problematic one)
158+ if ! PYTHONPATH="$RUNTIME_ROOT/pydeps" "$PYTHON" -c "import pydantic_core" 2>/dev/null; then
159+ echo "📦 Reinstalling Python deps for your Python version (one-time)..."
160+ rm -rf "$RUNTIME_ROOT/pydeps"/*
161+ "$PYTHON" -m pip install --quiet --target "$RUNTIME_ROOT/pydeps" -r "$RUNTIME_ROOT/requirements.txt" 2>/dev/null || \
162+ "$PYTHON" -m pip install --quiet --break-system-packages --target "$RUNTIME_ROOT/pydeps" -r "$RUNTIME_ROOT/requirements.txt"
163+ echo "✅ Done"
164+ fi
165+
166+ touch "$DEPS_VERIFIED"
167+ fi
168+
138169# Run the Node.js CLI (which handles API keys, UI, and calls Python)
139170exec node "$RUNTIME_ROOT/app/dist/index.js" "$@"
140171SH
0 commit comments