scripts/upgrade_pyvenv.sh
2025-11-01 08:37:06 +01:00

85 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/bash
set -e
check_arguments() {
[[ -f "$1" ]] && return
echo "Missing configuration file argument ($1)"
exit 1
}
check_venv_path() {
[[ -n "$VENV_PATH" ]] && \
[[ -d "$VENV_PATH" ]] && \
[[ -f "$VENV_PATH/bin/python" ]] && \
return;
echo "$VENV_PATH is not a virtual environment"
exit 1
}
check_requirements_file() {
[[ -n "$REQUIREMENTS_FILE" ]] && \
[[ -f "$REQUIREMENTS_FILE" ]] && \
return;
echo "$REQUIREMENTS_FILE does not exist"
exit 1
}
check_repo_path() {
[[ -n "$REPO_PATH" ]] && \
[[ -d "$REPO_PATH" ]] && \
(cd $REPO_PATH && git status) && return;
echo "$REPO_PATH is not a git repository"
exit 1
}
check_arguments $1
source $1
echo "Upgrading virtual environment for `basename $1`"
check_venv_path
check_requirements_file
check_repo_path
PIP_PATH=$VENV_PATH/bin/pip
reset_venv() {
rm -r $VENV_PATH
python3 -m venv $VENV_PATH
}
update_repo() {
cd $REPO_PATH
git fetch
if [[ `git log HEAD..origin | wc -l` == 0 ]];
then
echo "No changes in current branch of repository"
else
echo "Changes done in current branch:\n"
git log HEAD..origin
echo "\nPull new changes? (y/n)"
read pull_changes
[[ "$pull_changes" == "y" ]] && git pull
fi
}
install_requirements() {
$PIP_PATH install -r $REQUIREMENTS_FILE
}
echo "Resetting venv..."
reset_venv
update_repo
echo "Installing requirements..."
install_requirements > /dev/null
echo "Done."