summary |
shortlog |
log |
commit | commitdiff |
review |
tree
raw |
patch |
inline | side by side (from parent 1:
c53e11d)
Update the lf-venv-create() function to support a list of python
packages to install in the new venv.
Issue: RELENG-2502
Change-Id: Ic2e186e3d7db653f57b755974aeb1c63581df8f2
Signed-off-by: Tim Johnson <tijohnson@linuxfoundation.org>
# Name: lf-echo-stderr
#
# SYNOPSIS
# Name: lf-echo-stderr
#
# SYNOPSIS
-# lf-echo-stderr "this entire" "string will be sent to stderr"
+# lf-echo-stderr "this entire" "string will be sent to stderr"
-# This function will echo all command line aruments to 'stderr'
+# This function will echo all command line aruments to 'stderr'
#
################################################################################
#
################################################################################
# lf-boolean()
#
# SYNOPSIS
# lf-boolean()
#
# SYNOPSIS
-# # shellcheck disable=SC1090
-# source ~/lf-env.sh
+# # shellcheck disable=SC1090
+# source ~/lf-env.sh
-# if lf-boolean $VAR; then
-# echo "VAR is true"
-# fi
+# if lf-boolean $VAR; then
+# echo "VAR is true"
+# fi
-# This function will return a BOOLEAN (true or false) based upon the value
-# of VAR. The value of VAR will be mapped to lower case. If VAR maps to
-# "true", return true(0). If VAR maps to "false", return false(1). Any
-# other values will return false(2) and an error message.
+# This function will return a BOOLEAN (true or false) based upon the value
+# of VAR. The value of VAR will be mapped to lower case. If VAR maps to
+# "true", return true(0). If VAR maps to "false", return false(1). Any
+# other values will return false(2) and an error message.
-# true(0), false(1) or false(2)
+# true(0), false(1) or false(2)
#
################################################################################
function lf-boolean()
{
if (( $# != 1 )); then
#
################################################################################
function lf-boolean()
{
if (( $# != 1 )); then
- echo "ERROR: ${FUNCNAME[0]}() line: ${BASH_LINENO[0]} : Missing required argument"
+ echo "ERROR: ${FUNCNAME[0]}() line: ${BASH_LINENO[0]} : Missing Required Argument"
################################################################################
#
# NAME
################################################################################
#
# NAME
-# # shellcheck disable=SC1090
-# source ~/lf-env.sh
+# # shellcheck disable=SC1090
+# source ~/lf-env.sh
-# lf-venv-activate python3
+# lf-venv-activate python3
-# This function will validate existance of 'python' venv. If it exists
-# 'path-to-venv/bin' will be prepended to the PATH.
+# This function will validate existance of 'python' venv. If it exists
+# 'path-to-venv/bin' will be prepended to the PATH.
#
################################################################################
#
################################################################################
################################################################################
#
# NAME
################################################################################
#
# NAME
+# lf-venv-create python [package]...
-# # shellcheck disable=SC1090
-# source ~/lf-env.sh
+# # shellcheck disable=SC1090
+# source ~/lf-env.sh
-# lf-venv-create python2
-# or
-# lf-venv-create python3.6
+# lf-venv-create python3 tox tox-pyenv virtualenv
+# lf-venv-create python3.6
-# This function will create a Python Virtual Environment based on the
-# python specified. The 'python' argument must be in the PATH. The venv
-# will be located in ~/.venv## where ## comes from the 'python' argument.
-# I.E. python3 -> ~/.venv3. The resulting venv will be left 'read-only' to
-# discourage the installation of any other packages (except by
-# lf-venv-add()).
+# This function will create/update a Python Virtual Environment (venv) based
+# on the python specified. The 'python' argument must be in the PATH. The venv
+# will be located in ~/.venv## where ## comes from the 'python' argument.
+# I.E. python3 -> ~/.venv3. The resulting venv will be left 'read-only' to
+# discourage the installation of any other packages (except by
+# lf-venv-create()). By default, only versioned packages will be installed, so
+# any required packages need to be specified. By default the 'pip install
+# --upgrade' will be run multiple times. Sometimes pip needs that to get the
+# versioning correct.
function lf-venv-create()
{
function lf-venv-create()
{
- if (( $# != 1 )); then
- lf-echo-stderr "${FUNCNAME[0]}(): ERROR: Missing Python argument"
+ if (( $# < 1 )); then
+ lf-echo-stderr "${FUNCNAME[0]}(): ERROR: Missing Required Arguments"
if ! type $python > /dev/null; then
lf-echo-stderr "${FUNCNAME[0]}(): ERROR: Unknown Python: $python"
return 1
fi
if ! type $python > /dev/null; then
lf-echo-stderr "${FUNCNAME[0]}(): ERROR: Unknown Python: $python"
return 1
fi
local venv=~/.venv${python#python}
local suffix=$python-$$
local pip_log=/tmp/pip_log.$suffix
local venv=~/.venv${python#python}
local suffix=$python-$$
local pip_log=/tmp/pip_log.$suffix
# For Python2, just create venv and install pip
virtualenv -p $python $venv > $pip_log || return 1
$venv/bin/pip install --upgrade pip > $pip_log || return 1
# For Python2, just create venv and install pip
virtualenv -p $python $venv > $pip_log || return 1
$venv/bin/pip install --upgrade pip > $pip_log || return 1
+ $venv/bin/pip install --upgrade $pkg_list > $pip_log || return 1
- local pkg_list="git-review jenkins-job-builder lftools[openstack] "
- pkg_list+="python-heatclient python-openstackclient "
- pkg_list+="setuptools testresources tox yq"
+ # Include any packages that are tied to a specific version
+ pkg_list+="jenkins-job-builder==2.8.0 "
$python -m venv $venv > $pip_log
$venv/bin/pip install --upgrade pip > $pip_log || return 1
# Redirect errors for now
$venv/bin/pip install --upgrade $pkg_list >> $pip_log 2> /dev/null || return 1
# Generate list of packages
pkg_list=$($venv/bin/pip freeze | awk -F '=' '{print $1}') || return 1
$python -m venv $venv > $pip_log
$venv/bin/pip install --upgrade pip > $pip_log || return 1
# Redirect errors for now
$venv/bin/pip install --upgrade $pkg_list >> $pip_log 2> /dev/null || return 1
# Generate list of packages
pkg_list=$($venv/bin/pip freeze | awk -F '=' '{print $1}') || return 1
- # Update all packages, usuaally need to run twice to get all versions
- # correct.
- local upgrade_cmd="$venv/bin/pip install --upgrade $pkg_list"
- if $upgrade_cmd >> $pip_log 2>&1 > /dev/null ; then
- echo -n "Running 'pip --upgrade' to validate..."
- $upgrade_cmd >> $pip_log || return 1
- echo "..OK"
- fi
+ # Update all packages, may need to run twice to get all versions
+ # synced up. Ignore exit status on first try
+ $venv/bin/pip install --upgrade $pkg_list >> $pip_log || true
+ echo "Running 'pip --upgrade' to validate..."
+ $venv/bin/pip install --upgrade $pkg_list >> $pip_log || return 1
;;
*)
lf-echo-stderr "${FUNCNAME[0]}(): ERROR: No support for: $python"
;;
*)
lf-echo-stderr "${FUNCNAME[0]}(): ERROR: No support for: $python"
################################################################################
#
# NAME
################################################################################
#
# NAME
-# # shellcheck disable=SC1090
-# source ~/lf-env.sh
+# # shellcheck disable=SC1090
+# source ~/lf-env.sh
-# lf-venv-add python3 pkg
-# or
-# lf-venv-add python2 pkg1 pkg2 pkg3
+# lf-venv-add python3 pkg
+# or
+# lf-venv-add python2 pkg1 pkg2 pkg3
-# This function will add one or more python packages to an existing venv.
-# Attempts to add packages directly (pip) will result in errors because
-# the venv does not have 'write' permission.
+# This function will add one or more python packages to an existing venv.
+# Attempts to add packages directly (pip) will result in errors because
+# the venv does not have 'write' permission.
#
################################################################################
#
################################################################################
--- /dev/null
+---
+features:
+ - |
+ By default, the lf-venv-create() function only installs/upgrades 'pip' and
+ and any packages that need to be tied to a specific version like. Currently
+ the only version specific package is: 'jenkins-job-builder==2.8.0'. The
+ current version of lf-venv-create() supports being called twice but that
+ functionality has NOT yet been thoroughly tested. RELENG-2508 has been
+ created to validate & optimize that functionality.