forked from Borea-dev/python-client-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-venv.sh
executable file
·62 lines (52 loc) · 1.58 KB
/
setup-venv.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
#!/bin/bash
# Exit on error
set -e
# Function to print usage
print_usage() {
echo "Usage: ./setup.sh [OPTIONS]"
echo "Options:"
echo " -r, --recreate Recreate virtual environment (deletes existing .venv)"
echo " -i, --reinstall Reinstall all requirements"
echo " -h, --help Show this help message"
}
# Parse command line arguments
RECREATE=false
REINSTALL=false
while [[ "$#" -gt 0 ]]; do
case $1 in
-r|--recreate) RECREATE=true ;;
-i|--reinstall) REINSTALL=true ;;
-h|--help) print_usage; exit 0 ;;
*) echo "Unknown parameter: $1"; print_usage; exit 1 ;;
esac
shift
done
echo "Setting up Python virtual environment..."
# Handle recreation of virtual environment if requested
if [ "$RECREATE" = true ] && [ -d ".venv" ]; then
echo "Removing existing virtual environment..."
rm -rf .venv
fi
# Create virtual environment if it doesn't exist
if [ ! -d ".venv" ]; then
python -m venv .venv
echo "Virtual environment created"
else
echo "Virtual environment already exists"
fi
# Activate virtual environment
source .venv/bin/activate
# Install or reinstall dependencies
if [ "$REINSTALL" = true ]; then
echo "Reinstalling all dependencies..."
pip install --force-reinstall .
echo "Dependencies reinstalled successfully"
elif [ -f "pyproject.toml" ]; then
pip install -e .
echo "Dependencies installed successfully"
else
echo "Error: pyproject.toml not found"
exit 1
fi
echo "Setup complete! Virtual environment is activated."
echo "To deactivate the virtual environment, run: deactivate"