Skip to content

Commit 5326a69

Browse files
authored
Merge pull request #4 from NickChecan/fix-compile
Support CF invoke with 2 args
2 parents 36201dc + 7e0d244 commit 5326a69

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

bin/compile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
# Compile script for Python buildpack with uv support
33

44
set -euo pipefail
5+
if [ "$#" -lt 2 ]; then
6+
echo "Usage: $0 BUILD_DIR CACHE_DIR [ENV_DIR]"
7+
exit 1
8+
fi
9+
510
BUILD_DIR=$1
611
CACHE_DIR=$2
7-
ENV_DIR=$3
12+
ENV_DIR="${3:-}"
813
UV_INSTALL_DIR="$CACHE_DIR/uv/bin"
914
UV_BIN="$UV_INSTALL_DIR/uv"
1015
UV_PYTHON_INSTALL_ROOT="$BUILD_DIR/.uv/python"

test/unit/compile_test.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,19 @@ run_compile() {
171171
output="$(cat "$output_file")"
172172
}
173173

174+
run_compile_without_env_dir() {
175+
local build_dir="$1"
176+
local cache_dir="$2"
177+
local output_file="$TEST_ROOT/output.txt"
178+
179+
set +e
180+
PATH="$FAKE_BIN_DIR:/usr/bin:/bin" TEST_ROOT="$TEST_ROOT" FAKE_MANAGED_PYTHON="$FAKE_MANAGED_PYTHON" "$COMPILE_SCRIPT" "$build_dir" "$cache_dir" >"$output_file" 2>&1
181+
status=$?
182+
set -e
183+
184+
output="$(cat "$output_file")"
185+
}
186+
174187
test_compile_succeeds_for_locked_uv_project() {
175188
# Arrange
176189
local build_dir="$TEST_ROOT/success/build"
@@ -226,6 +239,24 @@ test_compile_adds_src_directory_to_pythonpath_when_present() {
226239
assert_file_contains "$profile_file" "$build_dir/src" "profile script should add src layout projects to PYTHONPATH"
227240
}
228241

242+
test_compile_accepts_two_argument_cf_invocation() {
243+
# Arrange
244+
local build_dir="$TEST_ROOT/two-arg/build"
245+
local cache_dir="$TEST_ROOT/two-arg/cache"
246+
247+
mkdir -p "$build_dir" "$cache_dir"
248+
touch "$build_dir/pyproject.toml" "$build_dir/uv.lock"
249+
printf '3.13\n' > "$build_dir/.python-version"
250+
setup_fake_commands
251+
252+
# Act
253+
run_compile_without_env_dir "$build_dir" "$cache_dir"
254+
255+
# Assert
256+
assert_exit_code "$status" 0 "compile should accept Cloud Foundry invocations that omit ENV_DIR"
257+
assert_contains "$output" "Detected uv project with lockfile. Installing dependencies with uv." "compile should still run normally when ENV_DIR is omitted"
258+
}
259+
229260
test_compile_fails_when_lockfile_is_missing() {
230261
# Arrange
231262
local build_dir="$TEST_ROOT/missing-lock/build"
@@ -247,6 +278,7 @@ test_compile_fails_when_lockfile_is_missing() {
247278

248279
test_compile_succeeds_for_locked_uv_project
249280
test_compile_adds_src_directory_to_pythonpath_when_present
281+
test_compile_accepts_two_argument_cf_invocation
250282
test_compile_fails_when_lockfile_is_missing
251283

252284
echo "PASS: compile unit tests"

0 commit comments

Comments
 (0)