Skip to content

Instantly share code, notes, and snippets.

@alastori
Created August 29, 2025 11:46
Show Gist options
  • Select an option

  • Save alastori/ed46fba72be8398e171c401761d0be9e to your computer and use it in GitHub Desktop.

Select an option

Save alastori/ed46fba72be8398e171c401761d0be9e to your computer and use it in GitHub Desktop.
setup_venv.sh — create a project-local Python .venv using uv and add .venv/ to .gitignore
#!/usr/bin/env bash
set -euo pipefail
VENV_DIR=".venv"
if ! command -v uv >/dev/null 2>&1; then
echo "Error: uv is not installed. Install with: brew install uv"
exit 1
fi
# Create venv if missing
if [ ! -d "$VENV_DIR" ]; then
echo "Creating Python virtual environment in $VENV_DIR"
uv venv
else
echo "Virtual environment already exists in $VENV_DIR"
fi
# Ensure .gitignore excludes it
if [ ! -f .gitignore ] || ! grep -qE '(^|/)\.venv/?$' .gitignore; then
echo ".venv/" >> .gitignore
echo "Added .venv/ to .gitignore"
fi
echo "Done. Activate with: source $VENV_DIR/bin/activate"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment