-
Notifications
You must be signed in to change notification settings - Fork 23
Fix: make dev_setup.sh cross-platform (Windows & Linux/Mac) — follow-up to #770 #867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 17.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| VENV_DIR=".venv" | ||
|
|
||
| # Pick a Python command that exists | ||
| if command -v python3 >/dev/null 2>&1; then | ||
| PY=python3 | ||
| elif command -v python >/dev/null 2>&1; then | ||
| PY=python | ||
| elif command -v py >/dev/null 2>&1; then | ||
| PY="py -3" | ||
| else | ||
| echo "❌ Python not found. Install Python 3 and try again." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Create venv only if missing | ||
| if [ ! -d "$VENV_DIR" ]; then | ||
| eval $PY -m venv "$VENV_DIR" | ||
| fi | ||
|
|
||
| # Activate (Linux/Mac = bin; Windows = Scripts) | ||
| if [ -f "$VENV_DIR/bin/activate" ]; then | ||
| # shellcheck source=/dev/null | ||
| source "$VENV_DIR/bin/activate" | ||
| elif [ -f "$VENV_DIR/Scripts/activate" ]; then | ||
| # shellcheck source=/dev/null | ||
| source "$VENV_DIR/Scripts/activate" | ||
| else | ||
| echo "❌ Could not find activate script in $VENV_DIR" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Upgrade pip | ||
| python -m pip install --upgrade pip | ||
|
|
||
| # Install deps if present | ||
| if [ -f "requirements.txt" ]; then | ||
| pip install -r requirements.txt | ||
| else | ||
| echo "ℹ️ No requirements.txt — skipping" | ||
| fi | ||
|
|
||
| echo "✅ Environment Ready" | ||
|
Comment on lines
+24
to
+45
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The This can be done by storing the path to the activation script and printing a helpful message at the end. # Activate (Linux/Mac = bin; Windows = Scripts)
ACTIVATE_SCRIPT=""
if [ -f "$VENV_DIR/bin/activate" ]; then
ACTIVATE_SCRIPT="$VENV_DIR/bin/activate"
elif [ -f "$VENV_DIR/Scripts/activate" ]; then
ACTIVATE_SCRIPT="$VENV_DIR/Scripts/activate"
fi
if [ -z "$ACTIVATE_SCRIPT" ]; then
echo "❌ Could not find activate script in $VENV_DIR"
exit 1
fi
# shellcheck source=/dev/null
source "$ACTIVATE_SCRIPT"
# Upgrade pip
python -m pip install --upgrade pip
# Install deps if present
if [ -f "requirements.txt" ]; then
pip install -r requirements.txt
else
echo "ℹ️ No requirements.txt — skipping"
fi
echo "✅ Environment Ready"
echo "To use it, run:"
echo "source $ACTIVATE_SCRIPT" |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
evalcan be a security risk if the variable contains untrusted input. While it's safe in this specific context as you control the inputs, it's a best practice to avoid it. You can use a bash array to handle commands with arguments, which is safer and more robust.This also simplifies the command execution when creating the virtual environment.