Skip to content

Commit 3bb87c3

Browse files
committed
fix: hybrid bundled deps + pip fallback for Python version mismatch
1 parent 2d352bb commit 3bb87c3

File tree

4 files changed

+44
-13
lines changed

4 files changed

+44
-13
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.5.7
1+
0.5.8

npx/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

npx/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "asyncreview",
3-
"version": "0.5.6",
3+
"version": "0.5.7",
44
"description": "AI-powered GitHub PR/Issue reviews from the command line",
55
"type": "module",
66
"bin": {

scripts/build_runtime_local.sh

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,11 @@ cp -R "$ROOT_DIR/npx/python/cr" "$STAGE_DIR/app/python/"
7070
# Copy pyproject.toml so package detection works
7171
cp "$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
7776
SYS_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
8786
fi
8887
echo "==> 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
9191
dspy>=3.1.2
9292
rich>=13.0.0
9393
python-dotenv>=1.0.0
9494
httpx>=0.28.1
9595
EOF
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)
100101
echo "==> Downloading deno binary"
@@ -135,6 +136,36 @@ export PATH="$RUNTIME_ROOT/bin:$PATH"
135136
export PYTHONPATH="$RUNTIME_ROOT/pydeps:$RUNTIME_ROOT/app/python"
136137
export 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)
139170
exec node "$RUNTIME_ROOT/app/dist/index.js" "$@"
140171
SH

0 commit comments

Comments
 (0)