mkvenv optimsed

This commit is contained in:
Dirk Alders 2025-08-11 19:28:00 +02:00
parent c378340019
commit 67a6d7f108

43
mkvenv
View File

@ -1,12 +1,37 @@
#!/bin/bash
#
BASEPATH=$(pwd -P)
#
# Create venv
#
if [ ! -e venv ];then
python3 -m venv venv
if venv/bin/pip -V | grep `pwd -P`; then
venv/bin/pip install --upgrade pip
find . -name requirements.txt | xargs -L 1 venv/bin/pip install -r
#venv/bin/pip list --outdated --format=json | jq -r '.[] | .name'|xargs -n1 venv/bin/pip install -U
else
echo Not running in the venv!
fi
echo -e "\033[1;33mCreating venv in $BASEPATH...\e[0m"
python3 -m venv $BASEPATH/venv > /dev/null 2>&1
else
echo Virtualenv already exists!
echo -e "\033[1;33mVirtualenv already exists in $BASEPATH...\e[0m"
fi
echo
#
# Install modules
#
echo -e "\033[1;33mInstalling modules to venv in $BASEPATH...\e[0m"
for req_file in $(find $BASEPATH -name requirements.txt); do
# echo " $req_file"
while read req_mod; do
if [[ $req_mod = *[![:space:]]* ]]; then
# req_mod is not empty
OUT=$($BASEPATH/venv/bin/pip install -U $req_mod)
if [[ $OUT =~ "Successfully installed" ]]; then
echo " * $req_mod installed."
elif [[ $OUT =~ "already satisfied" ]]; then
echo " * $req_mod already installed."
else
echo " * $req_mod installation FAILED!"
echo $OUT
fi
fi
done < $req_file
done
echo