Skip to content

Commit fabcff6

Browse files
authored
Merge pull request #5 from NickChecan/fix-release
Fix Release
2 parents 9607902 + 39912f4 commit fabcff6

File tree

9 files changed

+486
-1
lines changed

9 files changed

+486
-1
lines changed

bin/release

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

4-
if command -v python3 >/dev/null 2>&1; then
4+
if [ -x ".python/bin/python3" ]; then
5+
PYTHON_BIN=".python/bin/python3"
6+
elif [ -x ".python/bin/python" ]; then
7+
PYTHON_BIN=".python/bin/python"
8+
elif command -v python3 >/dev/null 2>&1; then
59
PYTHON_BIN="python3"
610
elif command -v python >/dev/null 2>&1; then
711
PYTHON_BIN="python"

example/my-app/.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13

example/my-app/README.md

Whitespace-only changes.

example/my-app/manifest.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
applications:
3+
- name: my-app
4+
memory: 256M
5+
disk_quota: 512M
6+
instances: 1
7+
buildpacks:
8+
- https://github.com/NickChecan/uv-python-buildpack
9+
random-route: true

example/my-app/pyproject.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[project]
2+
name = "my-app"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.13"
7+
dependencies = [
8+
"fastapi>=0.135.3",
9+
"uvicorn[standard]>=0.44.0",
10+
]
11+
12+
[project.scripts]
13+
start = "my_app.main:start"
14+
15+
[build-system]
16+
requires = ["uv_build>=0.11.5,<0.12.0"]
17+
build-backend = "uv_build"

example/my-app/src/my_app/__init__.py

Whitespace-only changes.

example/my-app/src/my_app/main.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from fastapi import FastAPI
2+
import uvicorn
3+
4+
app = FastAPI()
5+
6+
7+
@app.get("/")
8+
def hello_world():
9+
return {"message": "Hello, World!"}
10+
11+
def start() -> None:
12+
uvicorn.run("my_app.main:app", host="0.0.0.0", port=8000, reload=True)

example/my-app/uv.lock

Lines changed: 414 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/unit/release_test.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,33 @@ EOF
145145
assert_contains "$output" 'web: python3 -c "from server.main import start; start()"' "release should fall back to the start script"
146146
}
147147

148+
test_release_prefers_buildpack_managed_python_when_present() {
149+
# Arrange
150+
local app_dir="$TEST_ROOT/managed-python-app"
151+
mkdir -p "$app_dir/.python/bin"
152+
setup_fake_python_commands
153+
cat > "$app_dir/pyproject.toml" <<'EOF'
154+
[project]
155+
name = "my-app"
156+
157+
[project.scripts]
158+
start = "server.main:start"
159+
EOF
160+
cat > "$app_dir/.python/bin/python3" <<'EOF'
161+
#!/usr/bin/env bash
162+
set -euo pipefail
163+
exec "$REAL_PYTHON3" "$@"
164+
EOF
165+
chmod +x "$app_dir/.python/bin/python3"
166+
167+
# Act
168+
run_release "$app_dir"
169+
170+
# Assert
171+
assert_exit_code "$status" 0 "release should succeed when the buildpack-managed python is present"
172+
assert_contains "$output" 'web: .python/bin/python3 -c "from server.main import start; start()"' "release should prefer the buildpack-managed python shim"
173+
}
174+
148175
test_release_falls_back_to_main_py() {
149176
# Arrange
150177
local app_dir="$TEST_ROOT/main-py-app"
@@ -194,6 +221,7 @@ test_release_leaves_web_process_empty_when_no_entrypoint_exists() {
194221
test_release_exits_when_procfile_exists
195222
test_release_prefers_project_name_script_over_start
196223
test_release_falls_back_to_start_script
224+
test_release_prefers_buildpack_managed_python_when_present
197225
test_release_falls_back_to_main_py
198226
test_release_falls_back_to_app_py
199227
test_release_leaves_web_process_empty_when_no_entrypoint_exists

0 commit comments

Comments
 (0)