diff options
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 |
