-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·41 lines (33 loc) · 1.05 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·41 lines (33 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"
VENV_DIR="$ROOT_DIR/.venv"
choose_python() {
local candidates=(python3.13 python3.12 python3.11 python3.10 python3)
for py in "${candidates[@]}"; do
if command -v "$py" >/dev/null 2>&1; then
echo "$py"
return 0
fi
done
return 1
}
PYTHON_BIN="$(choose_python || true)"
if [[ -z "${PYTHON_BIN:-}" ]]; then
echo "No suitable Python interpreter found." >&2
exit 1
fi
if [[ -x "$VENV_DIR/bin/python" ]]; then
VENV_VERSION="$($VENV_DIR/bin/python -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')"
TARGET_VERSION="$($PYTHON_BIN -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')"
if [[ "$VENV_VERSION" != "$TARGET_VERSION" ]]; then
rm -rf "$VENV_DIR"
fi
fi
if [[ ! -d "$VENV_DIR" ]]; then
"$PYTHON_BIN" -m venv "$VENV_DIR"
fi
# shellcheck disable=SC1091
source "$VENV_DIR/bin/activate"
pip install -r "$ROOT_DIR/requirements.txt"
exec uvicorn app.main:app --host 0.0.0.0 --port "${PORT:-8000}"