From a405251903ffbf60c2080a30b136dd8d47c12d19 Mon Sep 17 00:00:00 2001 From: Eric Ball Date: Thu, 21 Apr 2022 16:43:59 -0700 Subject: [PATCH] Feat: Choose best python version to run venv We've seen problems with capture-instance-metadata.sh choosing the best python path, so this should help get the best version on each builder. If the $PYTHON variable is set, this will be used. If not, we check to see if python3 is available, as this should point to the latest version. If this is also not available, we run with the basic python command. Change-Id: I9950cc286c72fd17eac7a3c678ef8ca04ccd8921 Signed-off-by: Eric Ball --- releasenotes/notes/smart-venv-activate-f7f691e15cf0bde4.yaml | 8 ++++++++ shell/capture-instance-metadata.sh | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/smart-venv-activate-f7f691e15cf0bde4.yaml diff --git a/releasenotes/notes/smart-venv-activate-f7f691e15cf0bde4.yaml b/releasenotes/notes/smart-venv-activate-f7f691e15cf0bde4.yaml new file mode 100644 index 00000000..8a7d3f70 --- /dev/null +++ b/releasenotes/notes/smart-venv-activate-f7f691e15cf0bde4.yaml @@ -0,0 +1,8 @@ +--- +features: + - | + Post-build script capture-instance-metadata.sh will attempt to choose the + best possible version of Python to use. If the ``$PYTHON`` variable is set, + this will be used. If not, we check to see if ``python3`` is available, + as this should point to the latest version. If this is also not available, + we run with the basic ``python`` command. diff --git a/shell/capture-instance-metadata.sh b/shell/capture-instance-metadata.sh index 0648d1dd..172ed109 100644 --- a/shell/capture-instance-metadata.sh +++ b/shell/capture-instance-metadata.sh @@ -14,7 +14,13 @@ echo "---> capture-instance-metadata.sh" # shellcheck disable=SC1090 source ~/lf-env.sh -lf-activate-venv --python python3.8 lftools +if [[ "${PYTHON:-}" -ne "" ]]; then + lf-activate-venv --python $PYTHON lftools +elif python3; then + lf-activate-venv --python python3 lftools +else + lf-activate-venv lftools +fi # detect if we're in EC2 if [ -n "${NOMAD_DC}" ]; then -- 2.16.6