diff --git a/tools/summarizer/README.md b/tools/summarizer/README.md index f75f057..05dc32f 100644 --- a/tools/summarizer/README.md +++ b/tools/summarizer/README.md @@ -30,9 +30,29 @@ pip install -r requirements.txt python -m uvicorn app:app --host 127.0.0.1 --port 8001 --workers 1 ``` +If the host is missing `python3-venv` or `pip`, use the bootstrap script instead: + +```bash +./scripts/bootstrap-and-test.sh bootstrap +``` + ## Docker The Dockerfile installs Tesseract OCR so scanned PDFs and supported images can be processed inside the container. +## Tests + +Run the summarizer unit tests with: + +```bash +./scripts/bootstrap-and-test.sh test +``` + +The script: +- creates `.venv` with stdlib `venv` when available +- falls back to user-space `virtualenv` when host `venv` support is missing +- installs `requirements-dev.txt` +- writes pytest cache under `tmp/pytest-cache` to avoid stale root-owned `.pytest_cache` directories + ## API - `GET /health` — health check and runtime capabilities, including Ollama version/model metadata when configured - `POST /summarize` — JSON body `{ "text": "...", "max_length": 150, "min_length": 30 }` diff --git a/tools/summarizer/pytest.ini b/tools/summarizer/pytest.ini new file mode 100644 index 0000000..8a69410 --- /dev/null +++ b/tools/summarizer/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +cache_dir = tmp/pytest-cache diff --git a/tools/summarizer/scripts/bootstrap-and-test.sh b/tools/summarizer/scripts/bootstrap-and-test.sh new file mode 100755 index 0000000..0aced9c --- /dev/null +++ b/tools/summarizer/scripts/bootstrap-and-test.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash +set -euo pipefail + +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +VENV_DIR="$ROOT_DIR/.venv" +PYTHON_BIN="${PYTHON_BIN:-python3}" +VIRTUALENV_BIN="${VIRTUALENV_BIN:-$HOME/.local/bin/virtualenv}" + +ensure_user_pip() { + if "$PYTHON_BIN" -m pip --version >/dev/null 2>&1; then + return 0 + fi + + mkdir -p /tmp/jobtracker-python-bootstrap + cd /tmp/jobtracker-python-bootstrap + if [[ ! -f get-pip.py ]]; then + curl -fsSLo get-pip.py https://bootstrap.pypa.io/get-pip.py + fi + "$PYTHON_BIN" get-pip.py --user --break-system-packages +} + +ensure_venv() { + if [[ -x "$VENV_DIR/bin/python" && -x "$VENV_DIR/bin/pip" ]]; then + return 0 + fi + + if "$PYTHON_BIN" -m venv "$VENV_DIR" >/dev/null 2>&1; then + return 0 + fi + + ensure_user_pip + if [[ ! -x "$VIRTUALENV_BIN" ]]; then + "$PYTHON_BIN" -m pip install --user --break-system-packages virtualenv + fi + "$VIRTUALENV_BIN" "$VENV_DIR" +} + +install_requirements() { + "$VENV_DIR/bin/pip" install -r "$ROOT_DIR/requirements-dev.txt" +} + +run_tests() { + mkdir -p "$ROOT_DIR/tmp/pytest-cache" + cd "$ROOT_DIR" + AI_SERVICE_SKIP_MODEL_LOAD=1 "$VENV_DIR/bin/python" -m pytest -q -o cache_dir=tmp/pytest-cache tests/test_app.py +} + +case "${1:-test}" in + bootstrap) + ensure_venv + install_requirements + ;; + test) + ensure_venv + install_requirements + run_tests + ;; + *) + echo "Usage: $0 [bootstrap|test]" >&2 + exit 2 + ;; +esac