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