Skip to content

Commit 7f468ca

Browse files
committed
chore(common): add test for procfile
1 parent 73f3a2d commit 7f468ca

7 files changed

Lines changed: 473 additions & 23 deletions

File tree

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
APP_DIR := test/my-app-1
1+
APP_DIR := test/my-app-4
22
BUILD_DIR := /tmp/uv-bp-build
33
CACHE_DIR := /tmp/uv-bp-cache
44
ENV_DIR := /tmp/uv-bp-env
@@ -35,4 +35,5 @@ start-local:
3535
echo "Could not determine a web command to run locally."; \
3636
exit 1; \
3737
fi; \
38+
WEB_CMD=$$(printf "%s" "$$WEB_CMD" | sed "s/^python /$(PYTHON_BIN) /"); \
3839
eval "$$WEB_CMD"'

bin/release

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@ else
99
PYTHON_BIN="python"
1010
fi
1111

12-
# If the app provides its own Procfile, let Cloud Foundry use that.
13-
if [ -f "Procfile" ]; then
14-
exit 0
15-
# Otherwise, prefer a script named after `project.name`, then fall back to `start`.
16-
elif [ -n "$PYTHON_BIN" ] && [ -f "pyproject.toml" ]; then
17-
START_TARGET=$("$PYTHON_BIN" -c '
12+
resolve_script_target() {
13+
"$PYTHON_BIN" -c '
1814
import sys
1915
try:
2016
import tomllib
@@ -29,25 +25,40 @@ project_name = project.get("name", "")
2925
scripts = project.get("scripts", {})
3026
3127
print(scripts.get(project_name) or scripts.get("start", ""))
32-
')
33-
34-
if [ -n "$START_TARGET" ]; then
35-
MODULE_NAME="${START_TARGET%%:*}"
36-
FUNCTION_NAME="${START_TARGET##*:}"
37-
DEFAULT_WEB_PROCESS="${PYTHON_BIN} -c \"from ${MODULE_NAME} import ${FUNCTION_NAME}; ${FUNCTION_NAME}()\""
38-
elif [ -f "main.py" ]; then
39-
DEFAULT_WEB_PROCESS="${PYTHON_BIN} main.py"
40-
elif [ -f "app.py" ]; then
41-
DEFAULT_WEB_PROCESS="${PYTHON_BIN} app.py"
42-
else
43-
DEFAULT_WEB_PROCESS="${PYTHON_BIN} -m uvicorn main:app --host 0.0.0.0 --port \${PORT:-8000}"
28+
'
29+
}
30+
31+
build_python_entrypoint() {
32+
local target="$1"
33+
local module_name="${target%%:*}"
34+
local function_name="${target##*:}"
35+
echo "${PYTHON_BIN} -c \"from ${module_name} import ${function_name}; ${function_name}()\""
36+
}
37+
38+
DEFAULT_WEB_PROCESS=""
39+
40+
# If the app provides its own Procfile, let Cloud Foundry use that.
41+
if [ -f "Procfile" ]; then
42+
exit 0
43+
fi
44+
45+
# Prefer a script named after `project.name`, then fall back to `start`.
46+
if [ -f "pyproject.toml" ]; then
47+
SCRIPT_TARGET="$(resolve_script_target)"
48+
if [ -n "$SCRIPT_TARGET" ]; then
49+
DEFAULT_WEB_PROCESS="$(build_python_entrypoint "$SCRIPT_TARGET")"
4450
fi
45-
# If pyproject.toml is missing or cannot be parsed here, fall back to common app files.
46-
elif [ -f "main.py" ]; then
51+
fi
52+
53+
if [ -z "$DEFAULT_WEB_PROCESS" ] && [ -f "main.py" ]; then
4754
DEFAULT_WEB_PROCESS="${PYTHON_BIN} main.py"
48-
elif [ -f "app.py" ]; then
55+
fi
56+
57+
if [ -z "$DEFAULT_WEB_PROCESS" ] && [ -f "app.py" ]; then
4958
DEFAULT_WEB_PROCESS="${PYTHON_BIN} app.py"
50-
else
59+
fi
60+
61+
if [ -z "$DEFAULT_WEB_PROCESS" ]; then
5162
DEFAULT_WEB_PROCESS="${PYTHON_BIN} -m uvicorn main:app --host 0.0.0.0 --port \${PORT:-8000}"
5263
fi
5364

test/my-app-4/.python-version

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

test/my-app-4/Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: python main.py

test/my-app-4/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() -> dict[str, str]:
9+
return {"message": "Hello, World!"}
10+
11+
if __name__ == "__main__":
12+
uvicorn.run(app, host="0.0.0.0", port=8000)

test/my-app-4/pyproject.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[project]
2+
name = "my-app-4"
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+
]

test/my-app-4/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.

0 commit comments

Comments
 (0)