forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenapi_runner.sh
More file actions
executable file
·69 lines (57 loc) · 1.88 KB
/
Copy pathopenapi_runner.sh
File metadata and controls
executable file
·69 lines (57 loc) · 1.88 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env bash
set -euo pipefail
BACKEND_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
REQUIREMENTS="$BACKEND_DIR/openapi-requirements.txt"
DEFAULT_VENV_DIR="$BACKEND_DIR/.openapi-venv"
VENV_DIR="${OPENAPI_RUNNER_VENV:-$DEFAULT_VENV_DIR}"
PYTHON_VERSION="$(cat "$BACKEND_DIR/.python-version")"
PYTHON_MINOR="${PYTHON_VERSION%.*}"
PYTHON_BIN="${OPENAPI_RUNNER_PYTHON:-python$PYTHON_MINOR}"
find_venv_python() {
local candidate
for candidate in "$VENV_DIR/bin/python" "$VENV_DIR/Scripts/python.exe"; do
if [ -x "$candidate" ]; then
printf '%s\n' "$candidate"
return 0
fi
done
return 1
}
if [ ! -f "$REQUIREMENTS" ]; then
echo "FAIL: missing OpenAPI runner requirements at $REQUIREMENTS" >&2
exit 1
fi
if ! command -v uv >/dev/null 2>&1; then
echo "FAIL: uv is required for the OpenAPI runner. Install uv or run with CI's setup-uv step." >&2
exit 1
fi
if ! command -v "$PYTHON_BIN" >/dev/null 2>&1; then
PYTHON_BIN=python3
fi
VENV_PYTHON="$(find_venv_python || true)"
if [ -n "$VENV_PYTHON" ]; then
VENV_PYTHON_VERSION="$("$VENV_PYTHON" -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')"
if [ "$VENV_PYTHON_VERSION" != "$PYTHON_MINOR" ]; then
if [ "$VENV_DIR" != "$DEFAULT_VENV_DIR" ]; then
echo "FAIL: custom OpenAPI runner venv at $VENV_DIR uses Python $VENV_PYTHON_VERSION; expected $PYTHON_MINOR. Remove or replace it explicitly." >&2
exit 1
fi
rm -rf "$VENV_DIR"
VENV_PYTHON=""
fi
fi
if [ -z "$VENV_PYTHON" ]; then
"$PYTHON_BIN" -m venv "$VENV_DIR"
VENV_PYTHON="$(find_venv_python || true)"
fi
if [ -z "$VENV_PYTHON" ]; then
echo "FAIL: OpenAPI runner venv has no supported Python executable under $VENV_DIR" >&2
exit 1
fi
uv pip sync --python "$VENV_PYTHON" "$REQUIREMENTS"
"$VENV_PYTHON" - <<'PY'
import tiktoken
tiktoken.encoding_for_model('gpt-4')
PY
cd "$BACKEND_DIR"
exec "$VENV_PYTHON" "$@"