|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | set -euo pipefail |
3 | 3 |
|
4 | | -# Simple wrapper to create/activate a virtualenv and launch the prompt editor GUI. |
| 4 | +# Use uv to manage venv, install deps, and run the prompt editor GUI. |
5 | 5 |
|
6 | 6 | SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
7 | 7 | REPO_ROOT="$SCRIPT_DIR" |
8 | 8 | VENV_DIR="${REPO_ROOT}/.venv" |
9 | 9 | PYTHON_BIN="${PYTHON:-python3}" |
10 | 10 |
|
| 11 | +if ! command -v uv >/dev/null 2>&1; then |
| 12 | + echo "[run] Error: 'uv' is not installed or not on PATH." >&2 |
| 13 | + echo "[run] Please install uv: https://docs.astral.sh/uv/ and re-run." >&2 |
| 14 | + exit 1 |
| 15 | +fi |
| 16 | + |
11 | 17 | echo "[run] Using python: ${PYTHON_BIN}" |
12 | 18 |
|
13 | 19 | if [[ ! -d "${VENV_DIR}" ]]; then |
14 | | - echo "[run] Creating virtual environment at ${VENV_DIR}" |
15 | | - "${PYTHON_BIN}" -m venv "${VENV_DIR}" |
| 20 | + echo "[run] Creating virtual environment with uv at ${VENV_DIR}" |
| 21 | + uv venv --python "${PYTHON_BIN}" "${VENV_DIR}" |
16 | 22 | fi |
17 | 23 |
|
| 24 | +# Activate the environment created by uv |
18 | 25 | source "${VENV_DIR}/bin/activate" |
19 | 26 | echo "[run] Virtualenv activated: ${VENV_DIR}" |
20 | 27 |
|
21 | | -# If a requirements file exists, install it (best-effort). Skip if offline. |
| 28 | +# Install dependencies using uv |
22 | 29 | REQ_FILE="${REPO_ROOT}/requirements.txt" |
23 | | -if [[ -f "${REQ_FILE}" ]]; then |
24 | | - echo "[run] Installing dependencies from requirements.txt (if network available)" |
25 | | - pip install -r "${REQ_FILE}" || echo "[run] pip install skipped/failed (likely offline). Continuing." |
| 30 | +PYPROJECT_FILE="${REPO_ROOT}/pyproject.toml" |
| 31 | +if [[ -f "${PYPROJECT_FILE}" ]]; then |
| 32 | + echo "[run] Installing dependencies via 'uv sync' (pyproject.toml)" |
| 33 | + uv sync || echo "[run] uv sync failed/skipped (possibly offline); continuing." |
| 34 | +elif [[ -f "${REQ_FILE}" ]]; then |
| 35 | + echo "[run] Installing dependencies from requirements.txt via 'uv pip'" |
| 36 | + uv pip install -r "${REQ_FILE}" || echo "[run] uv pip failed/skipped (possibly offline); continuing." |
| 37 | +else |
| 38 | + echo "[run] No dependency file found (pyproject.toml or requirements.txt); skipping install." |
26 | 39 | fi |
27 | 40 |
|
28 | 41 | echo "[run] Launching GUI..." |
29 | 42 | exec python "${REPO_ROOT}/scripts/prompt_editor.py" "$@" |
30 | | - |
|
0 commit comments