From 1389d840d1b6e8abd826587dc05f56cd5fa38cb6 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Tue, 7 May 2013 21:15:07 +0900 Subject: [PATCH 1/6] Remove `python-virtualenv` which was no longer used. --- README.md | 4 ++ bin/python-virtualenv | 130 ------------------------------------------ 2 files changed, 4 insertions(+), 130 deletions(-) delete mode 100755 bin/python-virtualenv diff --git a/README.md b/README.md index 1c45640..c2c99aa 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,10 @@ under `~/.pyenv/versions`. ## Version History +#### 2013XXYY + + * Remove `python-virtualenv` which was no longer used. + #### 20130507 * Display virtualenv information in `--help` and `--version` diff --git a/bin/python-virtualenv b/bin/python-virtualenv deleted file mode 100755 index d77874b..0000000 --- a/bin/python-virtualenv +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/env bash - -PYTHON_VIRTUALENV_VERSION="20130507" - -set -E -exec 3<&2 # preserve original stderr at fd 3 - - -lib() { - parse_options() { - OPTIONS=() - ARGUMENTS=() - local arg option index - - for arg in "$@"; do - if [ "${arg:0:1}" = "-" ]; then - if [ "${arg:1:1}" = "-" ]; then - OPTIONS[${#OPTIONS[*]}]="${arg:2}" - else - index=1 - while option="${arg:$index:1}"; do - [ -n "$option" ] || break - OPTIONS[${#OPTIONS[*]}]="$option" - index=$(($index+1)) - done - fi - else - ARGUMENTS[${#ARGUMENTS[*]}]="$arg" - fi - done - } - - resolve_link() { - $(type -p greadlink readlink | head -1) "$1" - } - - abs_dirname() { - local cwd="$(pwd)" - local path="$1" - - while [ -n "$path" ]; do - cd "${path%/*}" - local name="${path##*/}" - path="$(resolve_link "$name" || true)" - done - - pwd - cd "$cwd" - } - - if [ "$1" == "--$FUNCNAME" ]; then - declare -f "$FUNCNAME" - echo "$FUNCNAME \"\$1\";" - exit - fi -} -lib "$1" - -version() { - echo "python-virtualenv ${PYTHON_VIRTUALENV_VERSION}" -} - -usage() { - { version - echo "usage: python-virtualenv [-v|--verbose] [VIRTUALENV_OPTIONS] python_bin virtualenv_path" - } >&2 - - if [ -z "$1" ]; then - exit 1 - fi -} - -unset VERBOSE -PYTHON_VIRTUALENV_ROOT="$(abs_dirname "$0")/.." -VIRTUALENV_OPTIONS=() - -parse_options "$@" - -for option in "${OPTIONS[@]}"; do - case "$option" in - "h" | "help" ) - usage without_exiting - { echo - echo " -v/--verbose Verbose mode: print compilation status to stdout" - echo - } >&2 - exit 0 - ;; - "v" | "verbose" ) - VERBOSE=true - ;; - "version" ) - version - exit 0 - ;; - * ) - VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--$option" - ;; - esac -done - -PYTHON_BIN="${ARGUMENTS[0]}" -if [ -z "${PYTHON_BIN}" ]; then - usage -elif [ ! -x "${PYTHON_BIN}" ]; then - echo "python-virtualenv: given python is not an executable: ${PYTHON_BIN}" >&2 - exit 1 -fi - -VIRTUALENV_PATH="${ARGUMENTS[1]}" -if [ -z "$VIRTUALENV_PATH" ]; then - usage -fi - -VIRTUALENV_PYTHON_BIN="${VIRTUALENV_PATH}/bin/python" - -# create virtualenv -VIRTUALENV="${PYTHON_VIRTUALENV_ROOT}/libexec/python-virtualenv/virtualenv.py" -[ -f "${VIRTUALENV}" ] || VIRTUALENV="${PYTHON_VIRTUALENV_ROOT}/libexec/virtualenv.py" -"${PYTHON_BIN}" "${VIRTUALENV}" "${VIRTUALENV_OPTIONS[@]}" "${VIRTUALENV_PATH}" - -# create symlink of `python' bound for actual executable -if [ ! -f "$VIRTUALENV_PYTHON_BIN" ]; then - if [ -f "${VIRTUALENV_PATH}/bin/$(basename "${PYTHON_BIN}")" ]; then - { - cd ${VIRTUALENV_PATH}/bin - ln -fs "$(basename "${PYTHON_BIN}")" python - } - fi -fi From 9e438ee3e2b773047976aa25f9a8eda134303bcc Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Tue, 7 May 2013 21:22:51 +0900 Subject: [PATCH 2/6] Change the installation path of the `virtualenv.py` script. --- README.md | 1 + bin/pyenv-virtualenv | 2 -- install.sh | 2 +- libexec/{ => pyenv-virtualenv}/virtualenv.py | 0 4 files changed, 2 insertions(+), 3 deletions(-) rename libexec/{ => pyenv-virtualenv}/virtualenv.py (100%) diff --git a/README.md b/README.md index c2c99aa..29d04f7 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ 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`) #### 20130507 diff --git a/bin/pyenv-virtualenv b/bin/pyenv-virtualenv index 7f82342..2ff900c 100755 --- a/bin/pyenv-virtualenv +++ b/bin/pyenv-virtualenv @@ -77,8 +77,6 @@ usage() { PYENV_VIRTUALENV_ROOT="$(abs_dirname "$0")/.." VIRTUALENV="${PYENV_VIRTUALENV_ROOT}/libexec/pyenv-virtualenv/virtualenv.py" -[ -f "${VIRTUALENV}" ] || VIRTUALENV="${PYENV_VIRTUALENV_ROOT}/libexec/python-virtualenv/virtualenv.py" # backward compatibility before v20130307 -[ -f "${VIRTUALENV}" ] || VIRTUALENV="${PYENV_VIRTUALENV_ROOT}/libexec/virtualenv.py" VIRTUALENV_OPTIONS=() parse_options "$@" diff --git a/install.sh b/install.sh index 7f5f744..fa433bc 100755 --- a/install.sh +++ b/install.sh @@ -16,7 +16,7 @@ for file in bin/*; do cp "${file}" "${BIN_PATH}" done -for file in libexec/*; do +for file in libexec/pyenv-virtualenv/*.py; do cp "${file}" "${LIBEXEC_PATH}" done diff --git a/libexec/virtualenv.py b/libexec/pyenv-virtualenv/virtualenv.py similarity index 100% rename from libexec/virtualenv.py rename to libexec/pyenv-virtualenv/virtualenv.py From b594b99a1875567ffc695f330c2c295f225b8ab4 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Tue, 7 May 2013 21:26:28 +0900 Subject: [PATCH 3/6] s/VIRTUALENV_CACHE_PATH/PYENV_&/g --- bin/pyenv-virtualenv | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bin/pyenv-virtualenv b/bin/pyenv-virtualenv index 2ff900c..7fa241d 100755 --- a/bin/pyenv-virtualenv +++ b/bin/pyenv-virtualenv @@ -130,10 +130,12 @@ VIRTUALENV_PATH="${PYENV_ROOT}/versions/${VIRTUALENV_NAME}" # virtualenv may download distribute/setuptools in current directory. # change to cache directory to reuse them between invocation. -VIRTUALENV_CACHE_PATH="${PYTHON_BUILD_CACHE_PATH:-${PYENV_ROOT}/cache}" -mkdir -p "${VIRTUALENV_CACHE_PATH}" +if [ -z "${PYENV_VIRTUALENV_CACHE_PATH}" ]; then + PYENV_VIRTUALENV_CACHE_PATH="${PYTHON_BUILD_CACHE_PATH:-${PYENV_ROOT}/cache}" +fi +mkdir -p "${PYENV_VIRTUALENV_CACHE_PATH}" { - cd "${VIRTUALENV_CACHE_PATH}" + cd "${PYENV_VIRTUALENV_CACHE_PATH}" "${PYTHON_BIN}" "${VIRTUALENV}" "${VIRTUALENV_OPTIONS[@]}" "${VIRTUALENV_PATH}" } From a9903fab6ebc6acc27d6a4a1c05291b43cc45ab6 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Tue, 7 May 2013 21:51:12 +0900 Subject: [PATCH 4/6] make installation path of virtualenv.py configurable --- bin/pyenv-virtualenv | 49 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/bin/pyenv-virtualenv b/bin/pyenv-virtualenv index 7fa241d..7070d73 100755 --- a/bin/pyenv-virtualenv +++ b/bin/pyenv-virtualenv @@ -8,6 +8,7 @@ # PYENV_VIRTUALENV_VERSION="20130507" +VIRTUALENV_VERSION="${VIRTUALENV_VERSION:-1.9.1}" set -e [ -n "$PYENV_DEBUG" ] && set -x @@ -63,9 +64,40 @@ abs_dirname() { cd "$cwd" } +http() { + local method="$1" + local url="$2" + local file="$3" + [ -n "$url" ] || return 1 + + if type curl &>/dev/null; then + "http_${method}_curl" "$url" "$file" + elif type wget &>/dev/null; then + "http_${method}_wget" "$url" "$file" + else + echo "error: please install \`curl\` or \`wget\` and try again" >&2 + exit 1 + fi +} + +http_head_curl() { + curl -qsILf "$1" >&4 2>&1 +} + +http_get_curl() { + curl -C - -o "${2:--}" -qsSLf "$1" +} + +http_head_wget() { + wget -q --spider "$1" >&4 2>&1 +} + +http_get_wget() { + wget -nv -c -O "${2:--}" "$1" +} + version() { - local VIRTUALENV_VERSION="$(pyenv-exec python "${VIRTUALENV}" --version || true)" - echo "pyenv-virtualenv ${PYENV_VIRTUALENV_VERSION} (virtualenv ${VIRTUALENV_VERSION:-unknown})" + echo "pyenv-virtualenv ${PYENV_VIRTUALENV_VERSION} (virtualenv ${VIRTUALENV_VERSION})" } usage() { @@ -76,7 +108,13 @@ usage() { } PYENV_VIRTUALENV_ROOT="$(abs_dirname "$0")/.." -VIRTUALENV="${PYENV_VIRTUALENV_ROOT}/libexec/pyenv-virtualenv/virtualenv.py" +if [ -z "${PYENV_VIRTUALENV_CACHE_PATH}" ]; then + PYENV_VIRTUALENV_CACHE_PATH="${PYTHON_BUILD_CACHE_PATH:-${PYENV_ROOT}/cache}" +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_OPTIONS=() parse_options "$@" @@ -104,7 +142,7 @@ done PYTHON_BIN=$(PYENV_VERSION="${VERSION_NAME}" pyenv-which python) if [ ! -x "${PYTHON_BIN}" ]; then - echo "pyenv-virtualenv: could not obtain python executable: ${PYTHON_BIN}" >&2 + echo "pyenv-virtualenv: could not find python executable: ${PYTHON_BIN}" >&2 exit 1 fi @@ -130,9 +168,6 @@ VIRTUALENV_PATH="${PYENV_ROOT}/versions/${VIRTUALENV_NAME}" # virtualenv may download distribute/setuptools in current directory. # change to cache directory to reuse them between invocation. -if [ -z "${PYENV_VIRTUALENV_CACHE_PATH}" ]; then - PYENV_VIRTUALENV_CACHE_PATH="${PYTHON_BUILD_CACHE_PATH:-${PYENV_ROOT}/cache}" -fi mkdir -p "${PYENV_VIRTUALENV_CACHE_PATH}" { cd "${PYENV_VIRTUALENV_CACHE_PATH}" From db37bb96434e03681c53b4b835aef572a87184d8 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Tue, 7 May 2013 22:31:12 +0900 Subject: [PATCH 5/6] 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 From 20e78d8ffabf2df83aad20eff7517e2ab0defd4a Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Tue, 7 May 2013 22:51:25 +0900 Subject: [PATCH 6/6] update README --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0f83536..4fdc0c1 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,18 @@ virtualenv. For example, virtualenvs will be created into a directory of the same name under `~/.pyenv/versions`. +### Special environment variables + +You can set certain environment variables to control the pyenv-virtualenv. + +* `PYENV_VIRTUALENV_CACHE_PATH`, if set, specifies a directory to use for + caching downloaded package files. +* `PYENV_VIRTUALENV_SCRIPT_PATH`, if set, specified a directory to use for + storing virtualenv scripts. +* `VIRTUALENV_VERSION`, if set, forces pyenv-virtualenv to use desired + version of virtualenv. If the version has not been installed, + pyenv-virtualenv will try to download it. + ## Version History @@ -44,7 +56,7 @@ under `~/.pyenv/versions`. * Remove `python-virtualenv` which was no longer used. * 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. + * Download `virtualenv.py` if desired version has not been installed. #### 20130507