From 8e77f700bd14d85c5862cc71fa38a2b8655fe214 Mon Sep 17 00:00:00 2001 From: Anil Belur Date: Tue, 4 Oct 2022 11:15:08 +1000 Subject: [PATCH] Fix: Use pyenv for PyPI verify jobs PyPI verify jobs requires Python 3.x. The tox run picks up default version of python instead of the version made available through pyenv. To fix this Re-factor lf-activate-venv() to skip a return, while the venv is re-used, so that the PATH can be set. Update the tox install and run script to Call lf-avtivate-venv(). Issue-ID: https://jira.linuxfoundation.org/browse/RELENG-4468 Signed-off-by: Anil Belur Change-Id: Ibde3ba8beb5be75fa69c9ee6cf36a80768a8f368 --- jenkins-init-scripts/lf-env.sh | 12 ++++++------ releasenotes/notes/refactor-tox-pyenv-f5b3aac7eec3725d.yaml | 11 +++++++++++ shell/tox-install.sh | 5 ++++- shell/tox-run.sh | 5 +++++ 4 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 releasenotes/notes/refactor-tox-pyenv-f5b3aac7eec3725d.yaml diff --git a/jenkins-init-scripts/lf-env.sh b/jenkins-init-scripts/lf-env.sh index 91aa80c6..f80dc798 100644 --- a/jenkins-init-scripts/lf-env.sh +++ b/jenkins-init-scripts/lf-env.sh @@ -245,13 +245,13 @@ lf-activate-venv () { "$lf_venv/bin/pip" install --upgrade --quiet pip virtualenv || return 1 if [[ -z $pkg_list ]]; then echo "${FUNCNAME[0]}(): WARNING: No packages to install" - return 0 + else + echo "${FUNCNAME[0]}(): INFO: Installing: $pkg_list" + # $pkg_list is expected to be unquoted + # shellcheck disable=SC2086 + "$lf_venv/bin/pip" install --upgrade --quiet --upgrade-strategy eager \ + $pkg_list || return 1 fi - echo "${FUNCNAME[0]}(): INFO: Installing: $pkg_list" - # $pkg_list is expected to be unquoted - # shellcheck disable=SC2086 - "$lf_venv/bin/pip" install --upgrade --quiet --upgrade-strategy eager \ - $pkg_list || return 1 ;; *) lf-echo-stderr "${FUNCNAME[0]}(): ERROR: No support for: $python" diff --git a/releasenotes/notes/refactor-tox-pyenv-f5b3aac7eec3725d.yaml b/releasenotes/notes/refactor-tox-pyenv-f5b3aac7eec3725d.yaml new file mode 100644 index 00000000..7d1304cf --- /dev/null +++ b/releasenotes/notes/refactor-tox-pyenv-f5b3aac7eec3725d.yaml @@ -0,0 +1,11 @@ +--- +prelude: > + PyPI verify jobs requires Python 3.x. The tox run picks up default version + of python instead of the version made available through pyenv. +issues: + - | + Re-factor lf-activate-venv() to skip a return, while the venv is + re-used, so that the PATH can be set. +fixes: + - | + Update the tox install and run script to Call lf-avtivate-venv(). diff --git a/shell/tox-install.sh b/shell/tox-install.sh index 02db0c27..5e527b3f 100644 --- a/shell/tox-install.sh +++ b/shell/tox-install.sh @@ -14,7 +14,10 @@ echo "---> tox-install.sh" # Use -x to show value of $PYTHON in output set -eux -o pipefail -python3 -m pip install --user --quiet --upgrade tox tox-pyenv virtualenv +# shellcheck disable=SC1090 +source ~/lf-env.sh + +lf-activate-venv --python python3.8 --venv-file /tmp/.toxenv tox tox-pyenv virtualenv # installs are silent, show version details in log $PYTHON --version diff --git a/shell/tox-run.sh b/shell/tox-run.sh index 4321ea68..758759b1 100644 --- a/shell/tox-run.sh +++ b/shell/tox-run.sh @@ -21,6 +21,11 @@ ARCHIVE_DOC_DIR="$WORKSPACE/archives/docs" mkdir -p "$ARCHIVE_TOX_DIR" cd "$WORKSPACE/$TOX_DIR" || exit 1 +# shellcheck disable=SC1090 +source ~/lf-env.sh + +lf-activate-venv --python python3.8 --venv-file /tmp/.toxenv tox tox-pyenv virtualenv + if [[ -d /opt/pyenv ]]; then echo "---> Setting up pyenv" export PYENV_ROOT="/opt/pyenv" -- 2.16.6