-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup_local_dev.sh
executable file
·99 lines (84 loc) · 2.61 KB
/
setup_local_dev.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
set -e # Exit on any error
# Check if direnv is installed
if ! command -v direnv &> /dev/null; then
echo "direnv not found. Installing..."
if command -v brew &> /dev/null; then
brew install direnv
elif command -v apt-get &> /dev/null; then
sudo apt-get update && sudo apt-get install -y direnv
else
echo "Please install direnv manually: https://direnv.net/docs/installation.html"
exit 1
fi
fi
# Detect shell and add hook if not present
CURRENT_SHELL=$(basename "$SHELL")
SHELL_CONFIG=""
case "$CURRENT_SHELL" in
"bash")
SHELL_CONFIG="$HOME/.bashrc"
;;
"zsh")
SHELL_CONFIG="$HOME/.zshrc"
;;
*)
SHELL_CONFIG=""
;;
esac
if [ -n "$SHELL_CONFIG" ]; then
if ! grep -q "eval \"\$(direnv hook $CURRENT_SHELL)\"" "$SHELL_CONFIG"; then
echo "eval \"\$(direnv hook $CURRENT_SHELL)\"" >> "$SHELL_CONFIG"
echo "Added direnv hook to $SHELL_CONFIG"
fi
fi
# Function to setup a project directory
setup_project() {
local project_dir="$1"
echo "Setting up $project_dir..."
cd "$project_dir"
# Create virtual environment if it doesn't exist
if [ ! -d ".venv" ]; then
python3 -m venv .venv
echo "Created virtual environment in $project_dir/.venv"
fi
# Create or update .envrc
echo 'source .venv/bin/activate' > .envrc
direnv allow
# Install requirements and package
if [ -f "requirements.txt" ]; then
.venv/bin/pip install -r requirements.txt
fi
if [ -f "setup.py" ] || [ -f "pyproject.toml" ]; then
.venv/bin/pip install -e .
fi
cd ..
echo "Completed setup for $project_dir"
echo "----------------------------------------"
}
# Main script
echo "Starting local development setup..."
# Find all directories that might be Python projects
for dir in */; do
if [ -f "${dir}requirements.txt" ] || [ -f "${dir}setup.py" ] || [ -f "${dir}pyproject.toml" ]; then
setup_project "${dir%/}" # Remove trailing slash
fi
done
# At the end of the script:
echo "----------------------------------------"
if [ -z "$SHELL_CONFIG" ]; then
echo "Please add the appropriate direnv hook to your shell's config file:"
echo ""
echo "For bash: Add to ~/.bashrc:"
echo 'eval "$(direnv hook bash)"'
echo ""
echo "For zsh: Add to ~/.zshrc:"
echo 'eval "$(direnv hook zsh)"'
echo ""
echo "For fish: Add to ~/.config/fish/config.fish:"
echo 'direnv hook fish | source'
echo ""
else
echo "Setup complete! Please restart your shell or run:"
echo "source $SHELL_CONFIG"
fi