pip.sh
Rebuild from scratch
This commit is contained in:
143
plugins.d/pip.sh
143
plugins.d/pip.sh
@@ -13,37 +13,47 @@
|
||||
#
|
||||
# Settings:
|
||||
|
||||
# Display info on updated pakages / casks
|
||||
#[[ $@ =~ "--info" ]] && display_info=false || display_info=true
|
||||
display_info=true
|
||||
|
||||
# No distract mode (no user interaction)
|
||||
[[ $@ =~ "--nodistract" ]] && no_distract=true || no_distract=false
|
||||
|
||||
# Display dependancies on updated pakages / casks
|
||||
#[[ $@ =~ "--depend" ]] && display_depend=false || display_depend=true
|
||||
display_depend=true
|
||||
|
||||
#version: pip ou pip3
|
||||
# pip: python3.8 - pip3: python3.9
|
||||
pip_version=pip3
|
||||
#user: "" or "--user"
|
||||
user=""
|
||||
# No distract mode
|
||||
no_distract=false
|
||||
#add module to do_not_update array
|
||||
|
||||
# Add module to the do_not_update array for prevent to update.
|
||||
#declare -a do_not_update=()
|
||||
#declare -a do_not_update=("parso" "asgiref")
|
||||
declare -a do_not_update=("asgiref")
|
||||
#
|
||||
#########################################
|
||||
|
||||
: <<'END_COMMENT'
|
||||
blabla
|
||||
END_COMMENT
|
||||
|
||||
italic="\033[3m"
|
||||
underline="\033[4m"
|
||||
ita_under="\033[3;4m"
|
||||
bold="\033[1m"
|
||||
bold_under="\033[1;4m"
|
||||
redbox="\033[1;41m"
|
||||
redbold="\033[1;31m"
|
||||
red="\033[31m"
|
||||
yellow="\033[33m"
|
||||
reset="\033[0m"
|
||||
|
||||
if [[ $1 == "--nodistract" ]]; then
|
||||
no_distract=true
|
||||
fi
|
||||
|
||||
if ! [ -x "$(command -v $pip_version)" ]; then
|
||||
echo "Error: $pip_version is not installed." >&2
|
||||
exit 1
|
||||
fi
|
||||
command -v pipdeptree >/dev/null 2>&1 || { echo -e "You shoud intall ${bold}pipdeptree${reset} for checking packages dependancies ${italic}($pip_version install pipdeptree)${reset}.\n"; }
|
||||
command -v $pip_version >/dev/null 2>&1 || { echo -e "${bold}$pip_version${reset} is not installed." && exit 1; }
|
||||
|
||||
echo -e "${bold}🐍 $pip_version (Python 3) ${reset}"
|
||||
|
||||
@@ -52,111 +62,108 @@ echo ""
|
||||
echo -e "Current ${underline}Python3${reset} version: $(python3 -V | awk '{print $2}')"
|
||||
echo -e "Current ${underline}pip3${reset} version: $(pip3 -V)"
|
||||
|
||||
#$pip_version install --upgrade pip
|
||||
$pip_version install --upgrade pip > /dev/null
|
||||
#$pip_version install --upgrade pip > /dev/null
|
||||
echo ""
|
||||
|
||||
# Do not update casks
|
||||
if (( ${#do_not_update[@]} )); then
|
||||
|
||||
nbp=${#do_not_update[*]}
|
||||
|
||||
echo -e "${underline}List of${reset} ${redbox} $nbp ${reset} ${underline}'do not update' packages:${reset}"
|
||||
echo -e "${redbold}${do_not_update[*]}${reset}"
|
||||
echo "To remove package from this list, you need to edit the do_not_update array."
|
||||
echo -e "To remove package from this list, you need to edit the ${italic}do_not_update${reset} array."
|
||||
echo ""
|
||||
|
||||
fi
|
||||
|
||||
|
||||
#Packages update
|
||||
echo -e "🐍 ${underline}Search for packages update...${reset}\n"
|
||||
|
||||
pip_outdated=$($pip_version list --outdated --format columns)
|
||||
upd=$(echo "$pip_outdated" | sed '1,2d' | awk '{print $1}')
|
||||
#upd="asgiref CairoSVG setuptools"
|
||||
|
||||
# Find infos about updated packages
|
||||
if [ -n "$upd" ]; then
|
||||
|
||||
nb=$(echo "$upd" | wc -w | xargs)
|
||||
|
||||
echo -e "${redbox} $nb ${reset} ${underline}availables updates:${reset}"
|
||||
#echo $pip3_outdated_freeze | tr [:space:] '\n'
|
||||
echo "$pip_outdated"
|
||||
echo -e "\n$pip_outdated"
|
||||
echo ""
|
||||
|
||||
for i in $upd
|
||||
do
|
||||
info=$($pip_version show "$i")
|
||||
echo "$info" | head -4
|
||||
echo ""
|
||||
done
|
||||
do
|
||||
info=$($pip_version show "$i")
|
||||
|
||||
if [ -x "$(command -v pipdeptree)" ]; then
|
||||
echo -e "${underline}Check dependancies:${reset}"
|
||||
echo "Be carefull!! This updates can be a dependancie for some modules. Check for any incompatible version."
|
||||
fi
|
||||
echo ""
|
||||
for i in $upd
|
||||
do
|
||||
if [ -x "$(command -v pipdeptree)" ]; then
|
||||
dependencies=$(echo "$i" | xargs pipdeptree -r -p | grep "$upd")
|
||||
l=$(echo "$info" | sed -n '1p')
|
||||
m=$(sed "1s/.*/\\${bold}$l\\${reset}/" <<< "$info")
|
||||
echo -e "$m" | head -4
|
||||
echo ""
|
||||
|
||||
#asgiref==3.2.10
|
||||
# - Django==3.1.2 [requires: asgiref~=3.2.10]
|
||||
z+="$i "
|
||||
|
||||
#parso==0.7.1
|
||||
# - jedi==0.17.2 [requires: parso>=0.7.0,<0.8.0]
|
||||
done
|
||||
|
||||
z=0
|
||||
while read -r line; do
|
||||
if [[ $line = *"<"* ]]; then
|
||||
echo -e "${red}$line${reset}"
|
||||
elif [[ $line = *"~="* ]]; then
|
||||
echo -e "${yellow}$line${reset}"
|
||||
else
|
||||
if [ "$z" -eq 0 ]; then
|
||||
echo -e "${italic}$line${reset}"
|
||||
else
|
||||
echo "$line"
|
||||
fi
|
||||
z=$((z+1))
|
||||
fi
|
||||
done <<< "$dependencies"
|
||||
echo ""
|
||||
# Check dependancies
|
||||
if [ -x "$(command -v pipdeptree)" ] && [ "$display_depend" == true ]; then
|
||||
|
||||
echo -e "🐍 ${underline}Check dependancies:${reset}\n"
|
||||
echo -e "Be carefull!! This updates can be a dependancie for some modules. Check for any incompatible version.\n"
|
||||
|
||||
z=$(echo "$z" | sed 's/.$//' | sed 's/ /,/g')
|
||||
dependencies=$(echo "$z" | xargs pipdeptree -r -p )
|
||||
|
||||
while IFS= read -r line; do
|
||||
z=$(echo "${line}" | grep -i ^[a-z])
|
||||
if [ -n "$z" ] ; then
|
||||
echo -e "\n${bold}${line}${reset}"
|
||||
elif [[ "${line}" = *"<"* ]]; then
|
||||
echo -e "${red}${line}${reset}"
|
||||
elif [[ "${line}" = *"~="* ]]; then
|
||||
echo -e "${yellow}${line}${reset}"
|
||||
else
|
||||
c=$(echo -e "Do you want to install pipdeptree to check dependancies ? (y/n)")
|
||||
read -pr "$c" choice
|
||||
case "$choice" in
|
||||
y|Y|o ) $pip_version install $user pipdeptree ;;
|
||||
n|N ) echo "Ok, let's continue";;
|
||||
* ) echo "invalid";;
|
||||
esac
|
||||
|
||||
echo "${line}"
|
||||
fi
|
||||
done <<< "$dependencies"
|
||||
|
||||
# If the update is not in the do_not_update array, we install it.
|
||||
fi
|
||||
|
||||
FOUND=`echo ${do_not_update[*]} | grep "$i"`
|
||||
if [ "${FOUND}" = "" ] && [ "$no_distract" = false ]; then
|
||||
|
||||
b=$(echo -e "Do you wanna run ${bold}$pip_version install $user --upgrade $i${reset} ? (y/n)")
|
||||
# Updating packages
|
||||
echo -e "\n🐍 ${underline}Updating packages...${reset}\n"
|
||||
|
||||
[ "${#do_not_update[@]}" -gt 0 ] && echo -e "${redbold}Do not update: ${underline}${do_not_update[@]}${reset}${redbold} . It won't be updated!'${reset}\n"
|
||||
|
||||
for i in $upd
|
||||
do
|
||||
if [[ ! " ${do_not_update[@]} " =~ " ${i} " ]]; then
|
||||
if [ "$no_distract" = false ]; then
|
||||
|
||||
b=$(echo -e "Do you wanna run ${bold}$pip_version install $user --upgrade $i${reset} ? (y/n)")
|
||||
read -p "$b" choice
|
||||
case "$choice" in
|
||||
y|Y|o ) echo "$i" | xargs $pip_version install $user --upgrade ;;
|
||||
n|N ) echo "Ok, let's continue";;
|
||||
n|N ) echo "Ok, let's continue";;
|
||||
* ) echo "invalid";;
|
||||
esac
|
||||
echo ""
|
||||
|
||||
elif [ "${FOUND}" = "" ]; then
|
||||
|
||||
else
|
||||
echo "$i" | xargs $pip_version install $user --upgrade
|
||||
|
||||
fi
|
||||
done
|
||||
fi
|
||||
done
|
||||
|
||||
else
|
||||
echo -e "${underline}No availables updates.${reset}"
|
||||
fi
|
||||
|
||||
|
||||
echo ""
|
||||
echo -e "🐍 Running ${bold}pip check${reset} for checking that everything is ok."
|
||||
echo -e "🐍 ${underline}Running ${reset}${bold_under}pip check${reset}${underline} for checking that everything is ok...${reset}\n"
|
||||
|
||||
$pip_version check
|
||||
|
||||
|
||||
Reference in New Issue
Block a user