Rebuild from scratch
This commit is contained in:
2021-01-09 13:04:07 +01:00
parent 02648b8f83
commit 1061909d5b

View File

@@ -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,88 +62,85 @@ 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
l=$(echo "$info" | sed -n '1p')
m=$(sed "1s/.*/\\${bold}$l\\${reset}/" <<< "$info")
echo -e "$m" | head -4
echo "" echo ""
z+="$i "
done 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 ""
for i in $upd
do
if [ -x "$(command -v pipdeptree)" ]; then
dependencies=$(echo "$i" | xargs pipdeptree -r -p | grep "$upd")
#asgiref==3.2.10 echo -e "🐍 ${underline}Check dependancies:${reset}\n"
# - Django==3.1.2 [requires: asgiref~=3.2.10] echo -e "Be carefull!! This updates can be a dependancie for some modules. Check for any incompatible version.\n"
#parso==0.7.1 z=$(echo "$z" | sed 's/.$//' | sed 's/ /,/g')
# - jedi==0.17.2 [requires: parso>=0.7.0,<0.8.0] dependencies=$(echo "$z" | xargs pipdeptree -r -p )
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}"
elif [[ "${line}" = *"~="* ]]; then
echo -e "${yellow}${line}${reset}"
else else
if [ "$z" -eq 0 ]; then echo "${line}"
echo -e "${italic}$line${reset}"
else
echo "$line"
fi
z=$((z+1))
fi fi
done <<< "$dependencies" done <<< "$dependencies"
echo ""
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
fi fi
# If the update is not in the do_not_update array, we install it.
FOUND=`echo ${do_not_update[*]} | grep "$i"` # Updating packages
if [ "${FOUND}" = "" ] && [ "$no_distract" = false ]; then 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)") 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
@@ -144,10 +151,9 @@ if [ -n "$upd" ]; then
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
@@ -155,8 +161,9 @@ 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