Use uv for isolated Python venv in bin/ and .venv/

- install.sh: downloads uv to bin/, creates .venv/ via uv venv, installs deps
- start.sh: uses .venv/bin/python3 directly, syncs deps via bin/uv
- .gitignore: added .venv/ and bin/
- Removes global pip3 usage, all Python deps stay project-local
This commit is contained in:
Jeremy McClure 2026-08-06 05:16:01 -04:00
parent 2cdd2e64a5
commit 21989dadae
No known key found for this signature in database
GPG Key ID: CA27BD8443157067
3 changed files with 51 additions and 14 deletions

2
.gitignore vendored
View File

@ -1,6 +1,8 @@
__pycache__/
*.pyc
.env
.venv/
bin/
*.egg-info/
dist/
node_modules/

View File

@ -17,19 +17,41 @@ echo "Detected OS: $OS"
if command -v python3 &>/dev/null; then
echo "Python: $(python3 --version)"
else
echo "ERROR: Python 3.10+ required. Install via: sudo apt install python3 python3-pip"
echo "ERROR: Python 3.10+ required. Install via: sudo apt install python3"
exit 1
fi
# Check pip
if ! command -v pip3 &>/dev/null; then
echo "Installing pip..."
python3 -m ensurepip --upgrade
# Install uv into bin/ if not present
BIN_DIR="bin"
UV="$BIN_DIR/uv"
if [ -x "$UV" ]; then
echo "uv: $($UV --version)"
else
echo "Installing uv to $BIN_DIR/..."
mkdir -p "$BIN_DIR"
curl -LsSf https://astral.sh/uv/install.sh | env UV_INSTALL_DIR="$PWD/$BIN_DIR" sh
if [ ! -x "$UV" ]; then
echo "ERROR: uv installation failed. Install manually: curl -LsSf https://astral.sh/uv/install.sh | sh"
exit 1
fi
echo "uv: $($UV --version)"
# Remove shell helper scripts — we reference bin/uv directly
rm -f "$BIN_DIR/env" "$BIN_DIR/env.fish"
fi
# Install Python deps
# Create virtual environment
VENV_DIR=".venv"
if [ -d "$VENV_DIR" ]; then
echo "Virtual environment already exists at $VENV_DIR/"
else
echo "Creating virtual environment..."
"$UV" venv "$VENV_DIR"
echo "Created $VENV_DIR/"
fi
# Install Python deps into venv
echo "Installing Python dependencies..."
pip3 install -r requirements.txt --quiet
"$UV" pip install --python "$VENV_DIR/bin/python3" -r requirements.txt --quiet
# Check Node.js (for opencode)
if command -v node &>/dev/null; then

View File

@ -10,18 +10,31 @@ if [ ! -f server.py ]; then
exit 1
fi
# Check dependencies
pip3 install -r requirements.txt --quiet 2>/dev/null
# Check virtual environment
VENV_DIR=".venv"
if [ ! -d "$VENV_DIR" ]; then
echo "Virtual environment not found. Run ./install.sh first."
exit 1
fi
# Use venv Python directly (no shell activation needed)
PYTHON="$VENV_DIR/bin/python3"
# Ensure deps are up to date
UV="bin/uv"
if [ -x "$UV" ]; then
"$UV" pip install --python "$PYTHON" -r requirements.txt --quiet 2>/dev/null
else
"$PYTHON" -m pip install -r requirements.txt --quiet 2>/dev/null
fi
# Get port from settings or default
PORT=8080
if command -v python3 &>/dev/null; then
PORT=$(python3 -c "import json; f=open('data/settings.json'); d=json.load(f); print(d.get('dashboard',{}).get('port',8080)); f.close()" 2>/dev/null || echo "8080")
fi
PORT=$("$PYTHON" -c "import json; f=open('data/settings.json'); d=json.load(f); print(d.get('dashboard',{}).get('port',8080)); f.close()" 2>/dev/null || echo "8080")
echo "Dashboard: http://127.0.0.1:${PORT}"
echo "Press Ctrl+C to stop"
echo ""
# Start server
python3 server.py --port "${PORT}"
# Start server using venv Python
"$PYTHON" server.py --port "${PORT}"