Skip to content

Commit bb42252

Browse files
committed
fix(common): dynamic cf runtime path for local run
1 parent db51f43 commit bb42252

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

bin/compile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,18 @@ if [ -f "pyproject.toml" ] && [ -f "uv.lock" ]; then
139139
# If the project uses a `src/` layout, include that too because the local
140140
# project itself is not installed by the exported third-party requirements.
141141
if [ -d "$SRC_DIR" ]; then
142-
# Build droplet-relative paths at runtime because the app will launch from
143-
# /home/vcap/app, not from the temporary staging directory used here.
142+
# Resolve the app root from the sourced profile script so the same file
143+
# works in both local smoke tests and the relocated CF droplet.
144144
cat > "$PROFILE_DIR/python.sh" <<EOF
145-
export APP_DIR="\${HOME}/app"
145+
export APP_DIR="\$(cd "\$(dirname "\${BASH_SOURCE[0]}")/.." && pwd)"
146146
export PATH="\$APP_DIR/.python/bin:\$APP_DIR/.python_packages/bin:\${PATH}"
147147
export PYTHONPATH="\$APP_DIR/src:\$APP_DIR/.python_packages/lib/python${PYTHON_VERSION}/site-packages:\${PYTHONPATH}"
148148
EOF
149149
else
150150
# Non-src-layout apps only need the staged site-packages directory plus the
151151
# buildpack-managed interpreter and console scripts on PATH.
152152
cat > "$PROFILE_DIR/python.sh" <<EOF
153-
export APP_DIR="\${HOME}/app"
153+
export APP_DIR="\$(cd "\$(dirname "\${BASH_SOURCE[0]}")/.." && pwd)"
154154
export PATH="\$APP_DIR/.python/bin:\$APP_DIR/.python_packages/bin:\${PATH}"
155155
export PYTHONPATH="\$APP_DIR/.python_packages/lib/python${PYTHON_VERSION}/site-packages:\${PYTHONPATH}"
156156
EOF

test/unit/compile_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ test_compile_succeeds_for_locked_uv_project() {
216216
assert_path_exists "$export_file" "compile should write the exported requirements file"
217217
assert_path_exists "$shim_dir/python3" "compile should create a python3 shim for runtime commands"
218218
assert_path_exists "$shim_dir/python" "compile should create a python shim for runtime commands"
219-
assert_file_contains "$profile_file" 'export APP_DIR="${HOME}/app"' "profile script should resolve paths from the droplet app directory at runtime"
219+
assert_file_contains "$profile_file" 'export APP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"' "profile script should resolve the app directory dynamically at runtime"
220220
assert_file_contains "$profile_file" '$APP_DIR/.python/bin:$APP_DIR/.python_packages/bin:${PATH}' "profile script should add the managed Python shims and staged console scripts to PATH"
221221
assert_file_contains "$profile_file" '$APP_DIR/.python_packages/lib/python3.13/site-packages:${PYTHONPATH}' "profile script should add staged dependencies to PYTHONPATH"
222222
assert_file_contains "$TEST_ROOT/uv.log" "python install 3.13" "compile should install the Python version pinned by .python-version"

0 commit comments

Comments
 (0)