From 497723afe105e85c5a9c5b0e432d70d37466ef1e Mon Sep 17 00:00:00 2001 From: masq Date: Sat, 1 Nov 2025 08:37:06 +0100 Subject: [PATCH] add upgrade pyvenv scripts --- upgrade_pyvenv.sh | 84 ++++++++++++++++++++++++++++++++++++++ upgrade_pyvenv_projects.sh | 9 ++++ 2 files changed, 93 insertions(+) create mode 100755 upgrade_pyvenv.sh create mode 100755 upgrade_pyvenv_projects.sh diff --git a/upgrade_pyvenv.sh b/upgrade_pyvenv.sh new file mode 100755 index 0000000..fa7e915 --- /dev/null +++ b/upgrade_pyvenv.sh @@ -0,0 +1,84 @@ +#!/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." diff --git a/upgrade_pyvenv_projects.sh b/upgrade_pyvenv_projects.sh new file mode 100755 index 0000000..9923229 --- /dev/null +++ b/upgrade_pyvenv_projects.sh @@ -0,0 +1,9 @@ +#!/usr/bin/bash +set -e + +CONF_DIR=/home/emixam/.config/pyvenv_projects.d + +for conf_file in $CONF_DIR/*; +do + upgrade_pyvenv.sh $conf_file; +done;