mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
feat: enhance Python installation script with requirements handling and dependency updates
- Added jq to the dependencies in the Docker base image installation script. - Updated the Python installation script to support handling of custom requirements via command-line arguments. - Implemented a new function to manage requirements installation, falling back to a default requirements file if none is provided. - Improved version check logic to prevent redundant installations of Python versions, enhancing efficiency in Docker environments.
This commit is contained in:
@@ -24,6 +24,7 @@ apt-get install -y \
|
||||
nginx \
|
||||
unzip \
|
||||
zip \
|
||||
jq \
|
||||
gnupg2 \
|
||||
libc6
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ set -e
|
||||
|
||||
# Function to print usage
|
||||
print_usage() {
|
||||
echo "Usage: $0 <command> [version]"
|
||||
echo "Usage: $0 <command> [version] [requirements]"
|
||||
echo "Commands:"
|
||||
echo " install <version> - Install Python version (default: 3.12)"
|
||||
echo " uninstall <version> - Uninstall Python version"
|
||||
@@ -86,18 +86,41 @@ cleanup() {
|
||||
apt-get autoremove -y
|
||||
}
|
||||
|
||||
# Function to handle requirements
|
||||
handle_requirements() {
|
||||
local requirements_content="$1"
|
||||
if [ -n "$requirements_content" ]; then
|
||||
REQUIREMENTS_FILE="/tmp/requirements_$(date +%s)_$RANDOM.txt"
|
||||
echo "$requirements_content" > "$REQUIREMENTS_FILE"
|
||||
pip install -r "$REQUIREMENTS_FILE"
|
||||
rm "$REQUIREMENTS_FILE"
|
||||
else
|
||||
# Fallback to default requirements file if it exists
|
||||
if [ -f "/app/install/python/requirements.txt" ]; then
|
||||
pip install -r /app/install/python/requirements.txt
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Main logic
|
||||
command="${1:-install}"
|
||||
version="${2:-3.12}"
|
||||
requirements="${3:-}"
|
||||
|
||||
case $command in
|
||||
"install")
|
||||
install_dependencies
|
||||
setup_pyenv
|
||||
pyenv install $version
|
||||
pyenv global $version
|
||||
# Check if version is already installed
|
||||
if pyenv versions | grep -q $version; then
|
||||
echo "Python $version is already installed. Switching to it..."
|
||||
pyenv global $version
|
||||
else
|
||||
install_dependencies
|
||||
pyenv install $version
|
||||
pyenv global $version
|
||||
fi
|
||||
verify_python $version
|
||||
pip install -r /app/install/python/requirements.txt
|
||||
handle_requirements "$requirements"
|
||||
create_symlinks
|
||||
cleanup
|
||||
;;
|
||||
@@ -111,17 +134,6 @@ case $command in
|
||||
pyenv uninstall -f $version
|
||||
;;
|
||||
|
||||
"switch")
|
||||
if [ -z "$version" ]; then
|
||||
echo "Please specify a version to switch to"
|
||||
exit 1
|
||||
fi
|
||||
setup_pyenv
|
||||
pyenv global $version
|
||||
verify_python $version
|
||||
create_symlinks
|
||||
;;
|
||||
|
||||
"list")
|
||||
setup_pyenv
|
||||
pyenv versions
|
||||
|
||||
Reference in New Issue
Block a user