-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.sh
70 lines (58 loc) · 2.09 KB
/
run.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
#!/usr/bin/env sh
VENV_DIR="venv"
REQUIREMENTS_FILE="requirements.txt"
# Check if virtual environment exists
if [ -d "$VENV_DIR" ]; then
# Determine the shell type
SHELL_TYPE="$(basename $SHELL)"
# Activate virtual environment based on shell type
case "$SHELL_TYPE" in
zsh)
source "$VENV_DIR"/bin/activate
;;
bash | sh)
. "$VENV_DIR"/bin/activate
;;
csh | tcsh)
source "$VENV_DIR"/bin/activate.csh
;;
*)
echo "Unsupported shell type: $SHELL_TYPE"
exit 1
;;
esac
# Check if requirements are already installed
if ! python3 -m pip list --format=freeze --disable-pip-version-check 2>/dev/null | grep -q -F -f "$REQUIREMENTS_FILE"; then
echo "Installing missing requirements from $REQUIREMENTS_FILE..."
python3 -m pip install -r "$REQUIREMENTS_FILE" --disable-pip-version-check
if [ $? -ne 0 ]; then
echo "Failed to install requirements. Exiting."
exit 1
fi
fi
else
echo "Virtual environment not found. Creating..."
# Create virtual environment (adjust for your Python version if needed)
python3 -m venv "$VENV_DIR"
if [ $? -ne 0 ]; then
echo "Failed to create virtual environment. Exiting."
exit 1
fi
# Install requirements (since venv was just created)
if [ -f "$REQUIREMENTS_FILE" ]; then
echo "Installing requirements from $REQUIREMENTS_FILE..."
# Activate the virtual environment first before installing requirements.
. "$VENV_DIR"/bin/activate
pip cache purge
pip install --upgrade pip setuptools wheel
python3 -m pip install -r "$REQUIREMENTS_FILE" --disable-pip-version-check
if [ $? -ne 0 ]; then
echo "Failed to install requirements. Exiting."
exit 1
fi
fi
fi
# Execute Python script with python3 (assuming it's within the venv)
python3 -m streamlit run appd-extractor.py
# Optionally, deactivate the virtual environment after the script finishes
deactivate