From bb9233feb775d4c08ddffa359c76bcb08a7cb674 Mon Sep 17 00:00:00 2001 From: Fred Liang Date: Wed, 29 Apr 2026 14:11:23 -0700 Subject: [PATCH] add setup.sh bootstrap script and openai to requirements setup.sh creates a .venv, installs deps, and seeds .env from .env.example. Idempotent on re-run. Adds openai alongside anthropic so s01-s05 (OpenAI) and s06+ (still Anthropic) both work. --- requirements.txt | 1 + setup.sh | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100755 setup.sh diff --git a/requirements.txt b/requirements.txt index c27dfcc..0701ae2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +openai>=1.40.0 anthropic>=0.25.0 python-dotenv>=1.0.0 pyyaml>=6.0 \ No newline at end of file diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..6f3f5e6 --- /dev/null +++ b/setup.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bash +# Dev environment bootstrap for learn-claude-code. +# Creates a local .venv, installs requirements.txt, and seeds .env from +# .env.example. Safe to re-run -- existing venv and .env are preserved. + +set -euo pipefail + +REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +cd "$REPO_ROOT" + +VENV_DIR="${VENV_DIR:-.venv}" +PYTHON_BIN="${PYTHON_BIN:-python3}" +MIN_PY_MAJOR=3 +MIN_PY_MINOR=10 + +say() { printf '\033[36m==>\033[0m %s\n' "$*"; } +warn() { printf '\033[33m[warn]\033[0m %s\n' "$*" >&2; } +die() { printf '\033[31m[error]\033[0m %s\n' "$*" >&2; exit 1; } + +# 1. Check Python +if ! command -v "$PYTHON_BIN" >/dev/null 2>&1; then + die "'$PYTHON_BIN' not found. Install Python ${MIN_PY_MAJOR}.${MIN_PY_MINOR}+ or set PYTHON_BIN." +fi + +PY_VERSION="$("$PYTHON_BIN" -c 'import sys; print("%d.%d" % sys.version_info[:2])')" +say "Using $PYTHON_BIN ($PY_VERSION)" + +"$PYTHON_BIN" - <= (${MIN_PY_MAJOR}, ${MIN_PY_MINOR}) else 1) +PY + +# 2. Create venv +if [ ! -d "$VENV_DIR" ]; then + say "Creating virtualenv at $VENV_DIR" + "$PYTHON_BIN" -m venv "$VENV_DIR" +else + say "Reusing virtualenv at $VENV_DIR" +fi + +# shellcheck disable=SC1091 +source "$VENV_DIR/bin/activate" + +# 3. Install deps +say "Upgrading pip" +python -m pip install --upgrade pip >/dev/null + +say "Installing requirements.txt" +python -m pip install -r requirements.txt + +# 4. Seed .env +if [ ! -f .env ]; then + if [ -f .env.example ]; then + say "Creating .env from .env.example" + cp .env.example .env + warn "Edit .env and set your API key + MODEL_ID before running the agents." + else + warn "No .env.example found; skipping .env creation." + fi +else + say ".env already exists (leaving as-is)" +fi + +# 5. Quick import sanity check +say "Verifying imports" +python - <<'PY' +import importlib, sys +missing = [m for m in ("openai", "dotenv", "yaml") if not importlib.util.find_spec(m)] +if missing: + sys.exit(f"Missing modules after install: {missing}") +print(" openai, python-dotenv, pyyaml OK") +PY + +cat <