Skip to content

Commit 0b6d149

Browse files
committed
fix(common): improve release issue monitoring and add python shim
1 parent 4ea7f72 commit 0b6d149

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

bin/compile

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,26 @@ install_managed_python() {
6565
fi
6666
}
6767

68+
write_python_shim() {
69+
local shim_path="$1"
70+
local shim_name="$2"
71+
local managed_python_relative="${PYTHON_BIN#"$BUILD_DIR"/}"
72+
73+
cat > "$shim_path" <<EOF
74+
#!/usr/bin/env bash
75+
set -euo pipefail
76+
APP_DIR="\$(cd "\$(dirname "\${BASH_SOURCE[0]}")/../.." && pwd)"
77+
exec "\$APP_DIR/$managed_python_relative" "\$@"
78+
EOF
79+
chmod +x "$shim_path"
80+
}
81+
6882
cd "$BUILD_DIR"
6983

7084
# Only treat the app as a supported uv project when both the project
7185
# metadata and the lockfile are present.
7286
if [ -f "pyproject.toml" ] && [ -f "uv.lock" ]; then
7387
echo "Detected uv project with lockfile. Installing dependencies with uv."
74-
install_managed_python
75-
7688
# Keep installer caches inside the buildpack cache directory so repeated
7789
# builds are faster and do not depend on user-specific cache locations.
7890
export PIP_CACHE_DIR="$CACHE_DIR/pip"
@@ -81,10 +93,13 @@ if [ -f "pyproject.toml" ] && [ -f "uv.lock" ]; then
8193
mkdir -p "$PIP_CACHE_DIR" "$UV_CACHE_DIR"
8294
mkdir -p "$PYTHON_SHIM_DIR"
8395

96+
install_managed_python
97+
8498
# The release script still looks for `python3`/`python` on PATH, so provide
85-
# stable shim names that point at the uv-managed interpreter we just installed.
86-
ln -sf "$PYTHON_BIN" "$PYTHON_SHIM_DIR/python3"
87-
ln -sf "$PYTHON_BIN" "$PYTHON_SHIM_DIR/python"
99+
# wrapper shims that resolve the managed interpreter relative to the droplet
100+
# instead of capturing an absolute staging path.
101+
write_python_shim "$PYTHON_SHIM_DIR/python3" "python3"
102+
write_python_shim "$PYTHON_SHIM_DIR/python" "python"
88103

89104
PYTHON_VERSION=$("$PYTHON_BIN" -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
90105
# Stage dependencies into a buildpack-owned location instead of a local venv

bin/release

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env bash
22
# Release script for Python buildpack with uv support
33

4+
set -euo pipefail
5+
46
if [ -x ".python/bin/python3" ]; then
57
PYTHON_BIN=".python/bin/python3"
68
elif [ -x ".python/bin/python" ]; then

0 commit comments

Comments
 (0)