From f0aba8bb5ffd86b4bd9f9e36f7d36d1ff9531983 Mon Sep 17 00:00:00 2001 From: Sangwook Ha Date: Tue, 30 Aug 2022 23:54:49 -0700 Subject: [PATCH] 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 --- jenkins-init-scripts/lf-env.sh | 8 ++++---- releasenotes/notes/fix-lf-pyver-regex-ad607c8c93d11bfb.yaml | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/fix-lf-pyver-regex-ad607c8c93d11bfb.yaml 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. -- 2.16.6