Fix: Use lf-activate-venv to install openstack dep
[releng/global-jjb.git] / shell / python-tools-install.sh
index 27b7aa4..e5d836b 100644 (file)
@@ -12,6 +12,24 @@ echo "---> python-tools-install.sh"
 
 set -eufo pipefail
 
+# Souce the python version from lf-env.sh if available.
+python="python3"
+if [[ -f ~/lf-env.sh ]]; then
+    source ~/lf-env.sh
+    lf-activate-venv --python "$python" lftools
+    # Save the virtualenv path
+    echo "$lf_venv" > "/tmp/.os_lf_venv"
+elif [[ -d /opt/pyenv ]]; then
+    echo "Setup up pyenv"
+    export PYENV_ROOT="/opt/pyenv"
+    export PATH="$PYENV_ROOT/bin:$PATH"
+    pyenv versions
+    if command -v pyenv 1>/dev/null 2>&1; then
+        eval "$(pyenv init - --no-rehash)"
+        pyenv local "$python"
+    fi
+fi
+
 # This script will typically be called during pre-build & post-build.
 # Create the user venv during pre-build.
 if [[ ! -f /tmp/pre-build-complete ]]; then
@@ -52,10 +70,10 @@ EOF
         fi
     fi
 
-    python3 -m pip install --user --quiet --upgrade pip
-    python3 -m pip install --user --quiet --no-warn-script-location --upgrade setuptools
-    python3 -m pip install --user --quiet --no-warn-script-location --upgrade lftools[openstack]
-    python3 -m pip install --user --quiet --no-warn-script-location --upgrade \
+    python3 -m pip install --quiet --upgrade pip
+    python3 -m pip install --quiet --no-warn-script-location --upgrade setuptools
+    python3 -m pip install --quiet --no-warn-script-location --upgrade lftools[openstack]
+    python3 -m pip install --quiet --no-warn-script-location --upgrade \
         --upgrade-strategy eager -r "$requirements_file"
     # installs are silent, show version details in log
     python3 --version