From 67f4d47ea396304e8825da9d6b836196753ae163 Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Fri, 15 Apr 2022 16:38:10 +0200 Subject: [PATCH] Always recreate fresh venv --- scripts/install | 17 ++++++++++++----- scripts/restore | 17 ++++++++++++----- scripts/upgrade | 17 ++++++++++++----- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/scripts/install b/scripts/install index d92008f..920fbd7 100755 --- a/scripts/install +++ b/scripts/install @@ -63,7 +63,7 @@ redis_db=$(ynh_redis_get_free_db) #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies..." --weight=40 +ynh_script_progression --message="Installing dependencies..." --weight=20 ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies" @@ -101,9 +101,14 @@ ynh_system_user_create --username="$app" --home_dir="$final_path" --use_shell #================================================= # PIP INSTALLATION #================================================= -ynh_script_progression --message="Install project via pip..." --weight=80 +ynh_script_progression --message="Install project via pip..." --weight=50 + +# Always recreate everything fresh with current python version +ynh_secure_remove "${final_path}/venv" + +# Skip pip because of: https://github.com/YunoHost/issues/issues/1960 +python3 -m venv --without-pip "${final_path}/venv" -python3 -m venv "${final_path}/venv" cp ../conf/requirements.txt "$final_path/requirements.txt" chown -R "$app:" "$final_path" @@ -112,13 +117,15 @@ chown -R "$app:" "$final_path" set +o nounset source "${final_path}/venv/bin/activate" set -o nounset - ynh_exec_as $app $final_path/venv/bin/pip install --upgrade wheel pip + + ynh_exec_as $app $final_path/venv/bin/python3 -m ensurepip + ynh_exec_as $app $final_path/venv/bin/pip3 install --upgrade wheel pip setuptools # for installing packages like "matplotlib" # See: https://github.com/YunoHost-Apps/django-for-runners_ynh/issues/15 ynh_exec_as $app $final_path/venv/bin/pip install --upgrade --prefer-binary Cython - ynh_exec_as $app $final_path/venv/bin/pip install --no-deps --prefer-binary -r "$final_path/requirements.txt" + ynh_exec_as $app $final_path/venv/bin/pip3 install --no-deps -r "$final_path/requirements.txt" ) #================================================= diff --git a/scripts/restore b/scripts/restore index 96bd9c8..d93716a 100755 --- a/scripts/restore +++ b/scripts/restore @@ -78,7 +78,7 @@ chown -R "$app:" "$final_path" #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Reinstalling dependencies..." --weight=40 +ynh_script_progression --message="Reinstalling dependencies..." --weight=20 ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies" @@ -86,22 +86,29 @@ ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies" # REINSTALL PYTHON VIRTUALENV # Maybe the backup contains a other Python version #================================================= -ynh_script_progression --message="Upgrade Python virtualenv..." --weight=10 +ynh_script_progression --message="Upgrade Python virtualenv..." --weight=50 -python3 -m venv "${final_path}/venv" +# Always recreate everything fresh with current python version +ynh_secure_remove "${final_path}/venv" + +# Skip pip because of: https://github.com/YunoHost/issues/issues/1960 +python3 -m venv --without-pip "${final_path}/venv" +chown -R "$app:" "$final_path" #run source in a 'sub shell' ( set +o nounset source "${final_path}/venv/bin/activate" set -o nounset - ynh_exec_as $app $final_path/venv/bin/pip install --upgrade wheel pip + + ynh_exec_as $app $final_path/venv/bin/python3 -m ensurepip + ynh_exec_as $app $final_path/venv/bin/pip3 install --upgrade wheel pip setuptools # for installing packages like "matplotlib" # See: https://github.com/YunoHost-Apps/django-for-runners_ynh/issues/15 ynh_exec_as $app $final_path/venv/bin/pip install --upgrade --prefer-binary Cython - ynh_exec_as $app $final_path/venv/bin/pip install --no-deps --prefer-binary -r "$final_path/requirements.txt" + ynh_exec_as $app $final_path/venv/bin/pip3 install --no-deps -r "$final_path/requirements.txt" ) #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 3d78a06..ad0d010 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -63,7 +63,7 @@ ynh_add_nginx_config "public_path" "port" #================================================= # Update dependencies #================================================= -ynh_script_progression --message="Upgrading dependencies..." +ynh_script_progression --message="Upgrading dependencies..." --weight=20 ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies" @@ -85,9 +85,14 @@ ynh_add_systemd_config --service="$app" --template="django-for-runners.service" #================================================= # UPGRADE VENV #================================================= -ynh_script_progression --message="Upgrade project via pip..." --weight=80 +ynh_script_progression --message="Upgrade project via pip..." --weight=50 + +# Always recreate everything fresh with current python version +ynh_secure_remove "${final_path}/venv" + +# Skip pip because of: https://github.com/YunoHost/issues/issues/1960 +python3 -m venv --without-pip "${final_path}/venv" -python3 -m venv --upgrade "${final_path}/venv" cp ../conf/requirements.txt "$final_path/requirements.txt" chown -R "$app:" "$final_path" @@ -96,13 +101,15 @@ chown -R "$app:" "$final_path" set +o nounset source "${final_path}/venv/bin/activate" set -o nounset - ynh_exec_as $app $final_path/venv/bin/pip install --upgrade wheel pip + + ynh_exec_as $app $final_path/venv/bin/python3 -m ensurepip + ynh_exec_as $app $final_path/venv/bin/pip3 install --upgrade wheel pip setuptools # for installing packages like "matplotlib" # See: https://github.com/YunoHost-Apps/django-for-runners_ynh/issues/15 ynh_exec_as $app $final_path/venv/bin/pip install --upgrade --prefer-binary Cython - ynh_exec_as $app $final_path/venv/bin/pip install --no-deps --prefer-binary -r "$final_path/requirements.txt" + ynh_exec_as $app $final_path/venv/bin/pip3 install --no-deps -r "$final_path/requirements.txt" ) #=================================================