diff options
| author | Sylvain Herlédan <sylvain.herledan@hrafnagud.info> | 2018-01-07 14:50:03 +0100 |
|---|---|---|
| committer | Sylvain Herlédan <sylvain.herledan@hrafnagud.info> | 2018-01-07 14:50:03 +0100 |
| commit | e1ff419cb22b5e6cd31872ebd2125f8611e36f30 (patch) | |
| tree | cfaf156f1d9c8ff15a542fa23bed61bcb2fc3ab8 /python_install.sh | |
| parent | aa9f6318a22a35d741ede10a550b213646997eb1 (diff) | |
| download | admin_toolbox-e1ff419cb22b5e6cd31872ebd2125f8611e36f30.tar.gz admin_toolbox-e1ff419cb22b5e6cd31872ebd2125f8611e36f30.tar.bz2 admin_toolbox-e1ff419cb22b5e6cd31872ebd2125f8611e36f30.zip | |
Add script to create a Python virtualenv properly isolated from the system.
Diffstat (limited to 'python_install.sh')
| -rwxr-xr-x | python_install.sh | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/python_install.sh b/python_install.sh new file mode 100755 index 0000000..c92e7c5 --- /dev/null +++ b/python_install.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +# @author: <sylvain.herledan@hrafnagud.info> +# @date: 2017-06-06 + +set -o nounset +set -o errexit +set -o pipefail + +readonly PROGNAME="$(basename "${0}")"; +readonly PROGDIR="$(readlink -f "$(dirname "${0}")")"; +readonly ARGS="${@}"; + +install_virtualenv() +{ + local python="${1}"; shift; + local env_dir="${1}"; shift; + local install_script_path="$(mktemp)"; + + wget 'https://bootstrap.pypa.io/get-pip.py' -O "${install_script_path}" + + mkdir -p "${env_dir}" + + PYTHONUSERBASE="${env_dir}" \ + "${python}" "${install_script_path}" --user --ignore-installed --no-cache + rm -f "${install_script_path}" + + PYTHONUSERBASE="${env_dir}" \ + "${env_dir}/bin/pip" install --user --ignore-installed --no-cache virtualenv + + local virtualenv_path="$(find "${env_dir}/lib" -name 'virtualenv.py')"; + local python_pkg_dir="$(readlink -f "$(dirname "${virtualenv_path}")")"; + + mkdir -p "${env_dir}/cache" + + PIP_CACHE_DIR="${env_dir}/cache" \ + PIP_IGNORE_INSTALLED=true \ + PYTHONPATH="${python_pkg_dir}" \ + "${python}" -m virtualenv "${env_dir}" + + cat > "${env_dir}/pip.conf" << EOF +[global] +cache-dir=${env_dir}/cache +EOF + + echo 'Environment ready' +} + +main() +{ + local python="${1}"; shift; + local _install_dir="${1}"; shift; + local install_dir="$(readlink -f "${_install_dir}")"; + local env_dir="${install_dir}/env"; + + install_virtualenv "${python}" "${env_dir}" +} + +main ${ARGS} +exit 0 |
