Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
# Compile script for Python buildpack with uv support

set -euo pipefail
if [ "$#" -lt 2 ]; then
echo "Usage: $0 BUILD_DIR CACHE_DIR [ENV_DIR]"
exit 1
fi

BUILD_DIR=$1
CACHE_DIR=$2
ENV_DIR=$3
ENV_DIR="${3:-}"
UV_INSTALL_DIR="$CACHE_DIR/uv/bin"
UV_BIN="$UV_INSTALL_DIR/uv"
UV_PYTHON_INSTALL_ROOT="$BUILD_DIR/.uv/python"
Expand Down
32 changes: 32 additions & 0 deletions test/unit/compile_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,19 @@ run_compile() {
output="$(cat "$output_file")"
}

run_compile_without_env_dir() {
local build_dir="$1"
local cache_dir="$2"
local output_file="$TEST_ROOT/output.txt"

set +e
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
status=$?
set -e

output="$(cat "$output_file")"
}

test_compile_succeeds_for_locked_uv_project() {
# Arrange
local build_dir="$TEST_ROOT/success/build"
Expand Down Expand Up @@ -226,6 +239,24 @@ test_compile_adds_src_directory_to_pythonpath_when_present() {
assert_file_contains "$profile_file" "$build_dir/src" "profile script should add src layout projects to PYTHONPATH"
}

test_compile_accepts_two_argument_cf_invocation() {
# Arrange
local build_dir="$TEST_ROOT/two-arg/build"
local cache_dir="$TEST_ROOT/two-arg/cache"

mkdir -p "$build_dir" "$cache_dir"
touch "$build_dir/pyproject.toml" "$build_dir/uv.lock"
printf '3.13\n' > "$build_dir/.python-version"
setup_fake_commands

# Act
run_compile_without_env_dir "$build_dir" "$cache_dir"

# Assert
assert_exit_code "$status" 0 "compile should accept Cloud Foundry invocations that omit ENV_DIR"
assert_contains "$output" "Detected uv project with lockfile. Installing dependencies with uv." "compile should still run normally when ENV_DIR is omitted"
}

test_compile_fails_when_lockfile_is_missing() {
# Arrange
local build_dir="$TEST_ROOT/missing-lock/build"
Expand All @@ -247,6 +278,7 @@ test_compile_fails_when_lockfile_is_missing() {

test_compile_succeeds_for_locked_uv_project
test_compile_adds_src_directory_to_pythonpath_when_present
test_compile_accepts_two_argument_cf_invocation
test_compile_fails_when_lockfile_is_missing

echo "PASS: compile unit tests"
Loading