Skip to content

Commit ff30ca6

Browse files
committed
improve setup-env.sh script
1 parent bbaf627 commit ff30ca6

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

setup-env.sh

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,56 @@
22

33
# Check if Python3 is installed
44
if ! command -v python3 &> /dev/null; then
5-
echo "Error: Python3 is not installed."
5+
echo "Error: Python3 is not installed."
6+
exit 1
67
fi
78

89
# Check if .venv folder exists, create if missing
910
if [ ! -d ".venv" ]; then
10-
echo ".venv folder not found. Creating a new virtual environment..."
11-
python3 -m venv .venv
11+
echo ".venv folder not found. Creating a new virtual environment..."
12+
python3 -m venv .venv
1213

13-
if [ $? -ne 0 ]; then
14-
echo "Failed to create a virtual environment."
15-
fi
14+
if [ $? -ne 0 ]; then
15+
echo "Error: Failed to create a virtual environment."
16+
exit 1
17+
fi
1618

17-
echo ".venv created successfully."
19+
echo ".venv created successfully."
1820
fi
1921

2022
# Activate the virtual environment (cross-platform support)
2123
echo "Activating the virtual environment..."
2224
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
23-
source .venv/Scripts/activate
25+
source .venv/Scripts/activate
2426
else
25-
source .venv/bin/activate
27+
source .venv/bin/activate
2628
fi
2729

2830
# Check if activation was successful
2931
if [ "$VIRTUAL_ENV" != "" ]; then
30-
echo "Virtual environment activated: $VIRTUAL_ENV"
32+
echo "Virtual environment activated: $VIRTUAL_ENV"
3133
else
32-
echo "Failed to activate the virtual environment."
34+
echo "Error: Failed to activate the virtual environment."
35+
exit 1
3336
fi
3437

3538
# Check if requirements.txt exists and install dependencies
3639
if [ ! -f "requirements.txt" ]; then
37-
echo "Error: requirements.txt file not found in the current directory."
38-
deactivate # Clean up before exiting.
40+
echo "Error: requirements.txt file not found or not available in the current directory."
41+
echo "Please ensure that requirements.txt exists and is readable."
42+
deactivate
43+
exit 1
3944
fi
4045

4146
echo "Installing dependencies from requirements.txt..."
4247
pip install -r requirements.txt > pip_install.log 2>&1
4348

4449
if [ $? -eq 0 ]; then
45-
echo "Dependencies installed successfully."
50+
echo "Dependencies installed successfully."
4651
else
47-
echo "Error occurred while installing dependencies. Check pip_install.log for details."
52+
echo "Error occurred while installing dependencies. Check pip_install.log for details."
53+
deactivate
54+
exit 1
4855
fi
4956

5057
# Deactivate the virtual environment (optional)

0 commit comments

Comments
 (0)