-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup-env.sh
60 lines (49 loc) · 1.59 KB
/
setup-env.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
#!/bin/bash
# Check if Python3 is installed
if ! command -v python3 &> /dev/null; then
echo "Error: Python3 is not installed."
exit 1
fi
# Check if .venv folder exists, create if missing
if [ ! -d ".venv" ]; then
echo ".venv folder not found. Creating a new virtual environment..."
python3 -m venv .venv
if [ $? -ne 0 ]; then
echo "Error: Failed to create a virtual environment."
exit 1
fi
echo ".venv created successfully."
fi
# Activate the virtual environment (cross-platform support)
echo "Activating the virtual environment..."
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
source .venv/Scripts/activate
else
source .venv/bin/activate
fi
# Check if activation was successful
if [ "$VIRTUAL_ENV" != "" ]; then
echo "Virtual environment activated: $VIRTUAL_ENV"
else
echo "Error: Failed to activate the virtual environment."
exit 1
fi
# Check if requirements.txt exists and install dependencies
if [ ! -f "requirements.txt" ]; then
echo "Error: requirements.txt file not found or not available in the current directory."
echo "Please ensure that requirements.txt exists and is readable."
deactivate
exit 1
fi
echo "Installing dependencies from requirements.txt..."
pip install -r requirements.txt > pip_install.log 2>&1
if [ $? -eq 0 ]; then
echo "Dependencies installed successfully."
else
echo "Error occurred while installing dependencies. Check pip_install.log for details."
deactivate
exit 1
fi
# Deactivate the virtual environment (optional)
# deactivate
# echo "Virtual environment deactivated."