From db37bb96434e03681c53b4b835aef572a87184d8 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Tue, 7 May 2013 22:31:12 +0900 Subject: [PATCH] Download `virtualenv.py` if specified version has not been installed. --- .gitignore | 8 ++++---- README.md | 3 ++- bin/pyenv-virtualenv | 18 ++++++++++++++++-- install.sh | 4 ++-- .../pyenv-virtualenv/{ => 1.9.1}/virtualenv.py | 0 5 files changed, 24 insertions(+), 9 deletions(-) rename libexec/pyenv-virtualenv/{ => 1.9.1}/virtualenv.py (100%) diff --git a/.gitignore b/.gitignore index a097bf0..c860e56 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ -/libexec/*.class -/libexec/*.pyc -/libexec/*.pyo -/libexec/__pycache__ +/libexec/pyenv-virtualenv/*/*.class +/libexec/pyenv-virtualenv/*/*.pyc +/libexec/pyenv-virtualenv/*/*.pyo +/libexec/pyenv-virtualenv/*/__pycache__ *.swo *.swp diff --git a/README.md b/README.md index 29d04f7..0f83536 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,8 @@ under `~/.pyenv/versions`. #### 2013XXYY * Remove `python-virtualenv` which was no longer used. - * Change the installation path of the `virtualenv.py` script. (`./libexec` -> `./libexec/pyenv-virtualenv`) + * Change the installation path of the `virtualenv.py` script. (`./libexec` -> `./libexec/pyenv-virtualenv/${VIRTUALENV_VERSION}`) + * Download `virtualenv.py` if specified version has not been installed. #### 20130507 diff --git a/bin/pyenv-virtualenv b/bin/pyenv-virtualenv index 7070d73..ad563b9 100755 --- a/bin/pyenv-virtualenv +++ b/bin/pyenv-virtualenv @@ -107,6 +107,15 @@ usage() { [ -z "$1" ] || exit "$1" } +ensure_virtualenv() { + local file="$1" + local url="$2" + [ -f "${file}" ] || { + mkdir -p "$(dirname "${file}")" + http get "${url}" "${file}" + } +} + PYENV_VIRTUALENV_ROOT="$(abs_dirname "$0")/.." if [ -z "${PYENV_VIRTUALENV_CACHE_PATH}" ]; then PYENV_VIRTUALENV_CACHE_PATH="${PYTHON_BUILD_CACHE_PATH:-${PYENV_ROOT}/cache}" @@ -114,9 +123,14 @@ fi if [ -z "${PYENV_VIRTUALENV_SCRIPT_PATH}" ]; then PYENV_VIRTUALENV_SCRIPT_PATH="${PYENV_VIRTUALENV_ROOT}/libexec/pyenv-virtualenv" fi -VIRTUALENV="${PYENV_VIRTUALENV_SCRIPT_PATH}/virtualenv.py" +VIRTUALENV="${PYENV_VIRTUALENV_SCRIPT_PATH}/${VIRTUALENV_VERSION}/virtualenv.py" VIRTUALENV_OPTIONS=() +ensure_virtualenv "${VIRTUALENV}" "https://raw.github.com/pypa/virtualenv/${VIRTUALENV_VERSION}/virtualenv.py" || { + echo "pyenv-virtualenv: could not find virtualenv script: ${VIRTUALENV}" 1>&2 + exit 1 +} + parse_options "$@" for option in "${OPTIONS[@]}"; do case "$option" in @@ -142,7 +156,7 @@ done PYTHON_BIN=$(PYENV_VERSION="${VERSION_NAME}" pyenv-which python) if [ ! -x "${PYTHON_BIN}" ]; then - echo "pyenv-virtualenv: could not find python executable: ${PYTHON_BIN}" >&2 + echo "pyenv-virtualenv: could not find python executable: ${PYTHON_BIN}" 1>&2 exit 1 fi diff --git a/install.sh b/install.sh index fa433bc..062e588 100755 --- a/install.sh +++ b/install.sh @@ -16,8 +16,8 @@ for file in bin/*; do cp "${file}" "${BIN_PATH}" done -for file in libexec/pyenv-virtualenv/*.py; do - cp "${file}" "${LIBEXEC_PATH}" +for file in libexec/pyenv-virtualenv/*; do + cp -Rp "${file}" "${LIBEXEC_PATH}" done echo "Installed pyenv-virtualenv at ${PREFIX}" diff --git a/libexec/pyenv-virtualenv/virtualenv.py b/libexec/pyenv-virtualenv/1.9.1/virtualenv.py similarity index 100% rename from libexec/pyenv-virtualenv/virtualenv.py rename to libexec/pyenv-virtualenv/1.9.1/virtualenv.py