From cb1998b5a556175819894c07b2e237c97246dddc Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Wed, 19 Jan 2022 09:10:45 +0100 Subject: [PATCH] Work-a-round: Split venv creation by using "--without-pip" and later "ensurepip" See: https://github.com/YunoHost/issues/issues/1960 --- scripts/install | 12 +++++++++--- scripts/restore | 23 +++++++++++++++++++++++ scripts/upgrade | 12 +++++++++--- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/scripts/install b/scripts/install index ef903ce..0ca3eb0 100755 --- a/scripts/install +++ b/scripts/install @@ -103,7 +103,12 @@ ynh_system_user_create --username="$app" --home_dir="$final_path" --use_shell #================================================= ynh_script_progression --message="Install project via pip..." --weight=80 -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" + cp ../conf/requirements.txt "$final_path/requirements.txt" chown -R "$app:" "$final_path" @@ -112,8 +117,9 @@ 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 pip - ynh_exec_as $app $final_path/venv/bin/pip install -r "$final_path/requirements.txt" + 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 + 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 dcd5ee0..394b186 100755 --- a/scripts/restore +++ b/scripts/restore @@ -82,6 +82,29 @@ ynh_script_progression --message="Reinstalling dependencies..." --weight=40 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=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" +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/python3 -m ensurepip + ynh_exec_as $app $final_path/venv/bin/pip3 install --upgrade wheel pip setuptools + ynh_exec_as $app $final_path/venv/bin/pip3 install --no-deps -r "$final_path/requirements.txt" +) + #================================================= # RESTORE THE PostgreSQL DATABASE #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 9ed9121..a3de19a 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -87,7 +87,12 @@ ynh_add_systemd_config --service="$app" --template="django_example_ynh.service" #================================================= ynh_script_progression --message="Upgrade project via pip..." --weight=80 -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" + cp ../conf/requirements.txt "$final_path/requirements.txt" chown -R "$app:" "$final_path" @@ -96,8 +101,9 @@ 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 pip - ynh_exec_as $app $final_path/venv/bin/pip install -r "$final_path/requirements.txt" + 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 + ynh_exec_as $app $final_path/venv/bin/pip3 install --no-deps -r "$final_path/requirements.txt" ) #=================================================