Fix: Update pyenv version selection 74/70574/4
authorSangwook Ha <sangwook.ha@verizon.com>
Wed, 31 Aug 2022 06:54:49 +0000 (23:54 -0700)
committerAnil Belur <abelur@linuxfoundation.org>
Wed, 31 Aug 2022 10:36:49 +0000 (20:36 +1000)
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 <sangwook.ha@verizon.com>
Signed-off-by: Anil Belur <abelur@linuxfoundation.org>
jenkins-init-scripts/lf-env.sh
releasenotes/notes/fix-lf-pyver-regex-ad607c8c93d11bfb.yaml [new file with mode: 0644]

index 97318e2..a2b8cb2 100644 (file)
@@ -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 (file)
index 0000000..f50aba1
--- /dev/null
@@ -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.