@@ -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+
6882cd " $BUILD_DIR "
6983
7084# Only treat the app as a supported uv project when both the project
7185# metadata and the lockfile are present.
7286if [ -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
0 commit comments