- Updated the project structure to store configuration files (.env, models.yaml, extensions.yaml) in the project root instead of the user's home directory. - Enhanced the setup process to automatically copy example files to the project root on first run. - Implemented a migration function to transfer legacy configuration files from the user's home directory to the new project structure. - Revised documentation to reflect changes in file locations and setup instructions. - Improved code readability and maintainability by refactoring path management functions.
69 lines
1.9 KiB
Bash
69 lines
1.9 KiB
Bash
#!/usr/bin/env bash
|
|
# Linux / macOS / Git Bash: venv + pip + python -m gpu_rent
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
cd "$ROOT"
|
|
|
|
ok_py() {
|
|
local exe="$1"
|
|
shift || true
|
|
command -v "$exe" >/dev/null 2>&1 || return 1
|
|
"$exe" "$@" -c 'import sys; raise SystemExit(0 if sys.version_info >= (3, 11) else 1)' >/dev/null 2>&1
|
|
}
|
|
|
|
PY=()
|
|
if ok_py python3.12; then
|
|
PY=(python3.12)
|
|
elif ok_py python3.11; then
|
|
PY=(python3.11)
|
|
elif ok_py python3; then
|
|
PY=(python3)
|
|
elif ok_py python; then
|
|
PY=(python)
|
|
elif ok_py py -3.12; then
|
|
PY=(py -3.12)
|
|
elif ok_py py -3.11; then
|
|
PY=(py -3.11)
|
|
else
|
|
echo "gpu-rent: нужен Python 3.11+. Ubuntu: sudo apt install python3 python3-venv python3-pip" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [[ -x "$ROOT/.venv/Scripts/python.exe" ]]; then
|
|
VENV_PY="$ROOT/.venv/Scripts/python.exe"
|
|
elif [[ -x "$ROOT/.venv/bin/python" ]]; then
|
|
VENV_PY="$ROOT/.venv/bin/python"
|
|
else
|
|
echo "gpu-rent: создаю .venv"
|
|
"${PY[@]}" -m venv "$ROOT/.venv"
|
|
if [[ -x "$ROOT/.venv/Scripts/python.exe" ]]; then
|
|
VENV_PY="$ROOT/.venv/Scripts/python.exe"
|
|
else
|
|
VENV_PY="$ROOT/.venv/bin/python"
|
|
fi
|
|
fi
|
|
|
|
STAMP="$ROOT/.venv/.gpu-rent-installed"
|
|
if [[ ! -f "$STAMP" || "$ROOT/pyproject.toml" -nt "$STAMP" ]]; then
|
|
echo "gpu-rent: ставлю пакет в .venv"
|
|
"$VENV_PY" -m pip install -U pip
|
|
"$VENV_PY" -m pip install -e "$ROOT"
|
|
date -u +"%Y-%m-%dT%H:%M:%SZ" >"$STAMP"
|
|
fi
|
|
|
|
if [[ ! -f "$ROOT/.env" && -f "$ROOT/env.example" ]]; then
|
|
cp "$ROOT/env.example" "$ROOT/.env"
|
|
echo "gpu-rent: created .env - fill OS_* (see docs/setup.md)"
|
|
fi
|
|
if [[ ! -f "$ROOT/models.yaml" && -f "$ROOT/models.example.yaml" ]]; then
|
|
cp "$ROOT/models.example.yaml" "$ROOT/models.yaml"
|
|
echo "gpu-rent: created models.yaml"
|
|
fi
|
|
if [[ ! -f "$ROOT/extensions.yaml" && -f "$ROOT/extensions.example.yaml" ]]; then
|
|
cp "$ROOT/extensions.example.yaml" "$ROOT/extensions.yaml"
|
|
echo "gpu-rent: created extensions.yaml"
|
|
fi
|
|
|
|
exec "$VENV_PY" -m gpu_rent "$@"
|