From fd23b8b0aa8ae7bc4e6edffce0e3efc1703d137a Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Mon, 22 Nov 2021 21:45:39 +0100 Subject: [PATCH 1/5] "--upgrade" seems not to be needed, if venv already exists --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index c86f71e..93f08a3 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -87,7 +87,7 @@ ynh_add_systemd_config --service="$app" --template="pyinventory.service" #================================================= ynh_script_progression --message="Upgrade project via pip..." --weight=80 -python3 -m venv --upgrade "${final_path}/venv" +python3 -m venv "${final_path}/venv" cp ../conf/requirements.txt "$final_path/requirements.txt" chown -R "$app:" "$final_path" From 8d2ea6d519aa933495dfa8a8fc46165295f46884 Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Mon, 22 Nov 2021 21:45:53 +0100 Subject: [PATCH 2/5] Use pip install with "--no-deps" Work-a-round for https://github.com/pypa/pip/issues/9644 Any generally a good idea, because our "requirements.txt" should always contain all needed packages ;) --- scripts/install | 2 +- scripts/restore | 2 +- scripts/upgrade | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/install b/scripts/install index 364d932..01024fd 100755 --- a/scripts/install +++ b/scripts/install @@ -113,7 +113,7 @@ chown -R "$app:" "$final_path" 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/pip install --no-deps -r "$final_path/requirements.txt" ) #================================================= diff --git a/scripts/restore b/scripts/restore index ffb0748..8ebdb84 100755 --- a/scripts/restore +++ b/scripts/restore @@ -96,7 +96,7 @@ python3 -m venv --upgrade "${final_path}/venv" 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/pip install --no-deps -r "$final_path/requirements.txt" ) #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 93f08a3..708e3ec 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -97,7 +97,7 @@ chown -R "$app:" "$final_path" 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/pip install --no-deps -r "$final_path/requirements.txt" ) #================================================= From bc5421ca3c44eb13763e44a3420104ac6b278386 Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Mon, 22 Nov 2021 22:32:12 +0100 Subject: [PATCH 3/5] Install/Update "wheel" package, too. --- scripts/install | 2 +- scripts/restore | 2 +- scripts/upgrade | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/install b/scripts/install index 01024fd..89e8771 100755 --- a/scripts/install +++ b/scripts/install @@ -112,7 +112,7 @@ 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 --upgrade wheel pip ynh_exec_as $app $final_path/venv/bin/pip install --no-deps -r "$final_path/requirements.txt" ) diff --git a/scripts/restore b/scripts/restore index 8ebdb84..b4a7746 100755 --- a/scripts/restore +++ b/scripts/restore @@ -95,7 +95,7 @@ python3 -m venv --upgrade "${final_path}/venv" 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 --upgrade wheel pip ynh_exec_as $app $final_path/venv/bin/pip install --no-deps -r "$final_path/requirements.txt" ) diff --git a/scripts/upgrade b/scripts/upgrade index 708e3ec..7a3e577 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -96,7 +96,7 @@ 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 --upgrade wheel pip ynh_exec_as $app $final_path/venv/bin/pip install --no-deps -r "$final_path/requirements.txt" ) From b90433d5ca93d400db32e9e72850d78d980a9ae4 Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Mon, 22 Nov 2021 22:32:33 +0100 Subject: [PATCH 4/5] Don't use "--upgrade" in restore script, too. --- scripts/restore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/restore b/scripts/restore index b4a7746..498e617 100755 --- a/scripts/restore +++ b/scripts/restore @@ -88,7 +88,7 @@ ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies" #================================================= ynh_script_progression --message="Upgrade Python virtualenv..." --weight=10 -python3 -m venv --upgrade "${final_path}/venv" +python3 -m venv "${final_path}/venv" #run source in a 'sub shell' ( From 51d4e20ba5682845054054ec1452ea91cd72f734 Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Mon, 22 Nov 2021 22:32:48 +0100 Subject: [PATCH 5/5] Add a test scipt to faster test the venv creation --- test_requirements.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 test_requirements.sh diff --git a/test_requirements.sh b/test_requirements.sh new file mode 100755 index 0000000..e7ececf --- /dev/null +++ b/test_requirements.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# Test to create the python virtual env and install all requirements. +# Note: Maybe you didn't have all OS packages installed ;) + +set -e + +final_path="./local_test" + +set -x + +mkdir -p "${final_path}/" +python3 -m venv "${final_path}/venv" +source "${final_path}/venv/bin/activate" + +$final_path/venv/bin/pip install --upgrade wheel pip +$final_path/venv/bin/pip install --no-deps -r "./conf/requirements.txt"