Created
August 29, 2025 11:46
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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