From 2b564763aafe6466f42bc5cf2ccc47ddf4169986 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Wed, 11 Feb 2015 17:01:02 -0600 Subject: [PATCH] Teach pip_install() about virtual envs Set PIP_VIRTUAL_ENV to install the package(s) into an existing virtual environment. This works by simply using the pip command already in the venv, and not using sudo. Change-Id: I910e1752e58a666174f83b4f97e547851e66e655 --- inc/python | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/inc/python b/inc/python index 0348cb389f..4a107ac8ec 100644 --- a/inc/python +++ b/inc/python @@ -31,6 +31,13 @@ function get_pip_command { # Get the path to the direcotry where python executables are installed. # get_python_exec_prefix function get_python_exec_prefix { + local xtrace=$(set +o | grep xtrace) + set +o xtrace + if [[ -z "$os_PACKAGE" ]]; then + GetOSVersion + fi + $xtrace + if is_fedora || is_suse; then echo "/usr/bin" else @@ -39,8 +46,8 @@ function get_python_exec_prefix { } # Wrapper for ``pip install`` to set cache and proxy environment variables -# Uses globals ``INSTALL_TESTONLY_PACKAGES``, ``OFFLINE``, ``TRACK_DEPENDS``, -# ``*_proxy`` +# Uses globals ``INSTALL_TESTONLY_PACKAGES``, ``OFFLINE``, ``PIP_VIRTUAL_ENV``, +# ``TRACK_DEPENDS``, ``*_proxy`` # pip_install package [package ...] function pip_install { local xtrace=$(set +o | grep xtrace) @@ -62,8 +69,13 @@ function pip_install { local cmd_pip=$DEST/.venv/bin/pip local sudo_pip="env" else - local cmd_pip=$(get_pip_command) - local sudo_pip="sudo -H" + if [[ -n ${PIP_VIRTUAL_ENV:=} && -d ${PIP_VIRTUAL_ENV} ]]; then + local cmd_pip=$PIP_VIRTUAL_ENV/bin/pip + local sudo_pip="env" + else + local cmd_pip=$(get_pip_command) + local sudo_pip="sudo -H" + fi fi local pip_version=$(python -c "import pip; \ @@ -93,6 +105,7 @@ function pip_install { -r $test_req fi fi + $xtrace } # should we use this library from their git repo, or should we let it