Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance error handling for init.sh #1556

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions scripts/init/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,30 @@ else
exit 1
fi

# Check if venv module is available and python3-venv is installed
if ! python3 -c "import venv ensurepip" &> /dev/null; then
if ! dpkg -s python${PYTHON_MAJOR}.${PYTHON_MINOR}-venv &> /dev/null; then
echo "python3-venv package for Python ${PYTHON_MAJOR}.${PYTHON_MINOR} is not installed. Installing..."
# Try creating the virtual environment first
echo "Attempting to create a virtual environment..."
if python3 -m venv "$SCRIPT_DIR/initPyEnv"; then
echo "Virtual environment created successfully."
else
echo "Failed to create the virtual environment. Checking for ensurepip..."
# Check if venv module and ensurepip are available
if ! python3 -c "import venv, ensurepip" &> /dev/null; then
echo "venv or ensurepip module is not available. Installing python3-venv..."
sudo apt update
sudo apt install -y python${PYTHON_MAJOR}.${PYTHON_MINOR}-venv
if [[ $? -ne 0 ]]; then
echo "Failed to install python${PYTHON_MAJOR}.${PYTHON_MINOR}-venv. Please check the package availability or use DeadSnakes PPA."
echo "Failed to install python${PYTHON_MAJOR}.${PYTHON_MINOR}-venv. Please check the package availability."
exit 1
fi
# Retry creating the virtual environment
if ! python3 -m venv "$SCRIPT_DIR/initPyEnv"; then
echo "Failed to create the virtual environment after installing python3-venv."
exit 1
fi
fi
else
echo "venv module is available."
fi

echo "Creating and activating the virtual environment..."
python3 -m venv "$SCRIPT_DIR/initPyEnv"
# Activate the virtual environment
source "$SCRIPT_DIR/initPyEnv/bin/activate"

echo
Expand Down
2 changes: 1 addition & 1 deletion scripts/init/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
requests==2.31.0

# Used for parsing and creating YAML files
PyYAML==6.0
PyYAML==6.0.1

# Used for displaying progress bars
tqdm==4.66.3
Expand Down