From: Sangwook Ha Date: Wed, 31 Aug 2022 06:54:49 +0000 (-0700) Subject: Fix: Update pyenv version selection X-Git-Tag: v0.80.2~1 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=f0aba8bb5ffd86b4bd9f9e36f7d36d1ff9531983;p=releng%2Fglobal-jjb.git Fix: Update pyenv version selection lf-pyver() fails to include the currently selected version in the output of 'pyenv versions', which makes the version change every time the local version is set by pyenv with the version from lf-pyver(). Fix the command to extract the list of Python versions to include all the numeric versions in the list. Issue-ID: RELENG-4403 Change-Id: I8eb1a1842a9ccd7514f096ec6989559a5526c3b6 Signed-off-by: Sangwook Ha Signed-off-by: Anil Belur --- diff --git a/jenkins-init-scripts/lf-env.sh b/jenkins-init-scripts/lf-env.sh index 97318e2b..a2b8cb2c 100644 --- a/jenkins-init-scripts/lf-env.sh +++ b/jenkins-init-scripts/lf-env.sh @@ -367,7 +367,7 @@ lf-pyver() { local py_version_xy="${1:-python3}" local py_version_xyz="" - pyenv versions | sed 's/[[:alpha:]|(|)|/||*|[:space:]]//g'| tr -d ' ' \ + pyenv versions | sed 's/^[ *]* //' | awk '{ print $1 }' | grep -E '^[0-9.]*[0-9]$' \ > "/tmp/.pyenv_versions" if [[ ! -s "/tmp/.pyenv_versions" ]]; then lf-echo-stderr "${FUNCNAME[0]}(): ERROR: pyenv not available" @@ -376,9 +376,9 @@ lf-pyver() { # strip out any prefix for (ex: 'python3.8' or 'v3.8') and match regex # to the output return by pyenv - py_version_xyz=$(grep "^${py_version_xy//[a-zA-Z]/}\(\..*\)\?\.[0-9]\+$" \ - "/tmp/.pyenv_versions" | sort -V | tail -n 1;) - if [[ ! -n ${py_version_xyz} ]]; then + py_version_xyz=$(grep "^${py_version_xy//[a-zA-Z]/}" "/tmp/.pyenv_versions" | + sort -V | tail -n 1;) + if [[ -z ${py_version_xyz} ]]; then lf-echo-stderr "${FUNCNAME[0]}(): ERROR: Not installed on host: ${py_version_xy}" return 1 fi diff --git a/releasenotes/notes/fix-lf-pyver-regex-ad607c8c93d11bfb.yaml b/releasenotes/notes/fix-lf-pyver-regex-ad607c8c93d11bfb.yaml new file mode 100644 index 00000000..f50aba16 --- /dev/null +++ b/releasenotes/notes/fix-lf-pyver-regex-ad607c8c93d11bfb.yaml @@ -0,0 +1,9 @@ +--- +fixes: + - | + lf-pyver() fails to include the currently selected version in the output + of 'pyenv versions', which makes the version change every time the local + version is set by pyenv with the version from lf-pyver(). + + Fix the command to extract the list of Python versions to include all + the numeric versions in the list.