mirror of
https://github.com/pyenv/pyenv-virtualenv.git
synced 2025-11-14 06:23:52 -05:00
Merge branch 'virtualenv-install'
This commit is contained in:
8
.gitignore
vendored
8
.gitignore
vendored
@@ -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
|
||||
|
||||
18
README.md
18
README.md
@@ -37,9 +37,27 @@ 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
|
||||
|
||||
#### 2013XXYY
|
||||
|
||||
* 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 desired version has not been installed.
|
||||
|
||||
#### 20130507
|
||||
|
||||
* Display virtualenv information in `--help` and `--version`
|
||||
|
||||
@@ -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() {
|
||||
@@ -75,12 +107,30 @@ 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")/.."
|
||||
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"
|
||||
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_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
|
||||
@@ -106,7 +156,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}" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -132,10 +182,9 @@ 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}"
|
||||
mkdir -p "${PYENV_VIRTUALENV_CACHE_PATH}"
|
||||
{
|
||||
cd "${VIRTUALENV_CACHE_PATH}"
|
||||
cd "${PYENV_VIRTUALENV_CACHE_PATH}"
|
||||
"${PYTHON_BIN}" "${VIRTUALENV}" "${VIRTUALENV_OPTIONS[@]}" "${VIRTUALENV_PATH}"
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -16,8 +16,8 @@ for file in bin/*; do
|
||||
cp "${file}" "${BIN_PATH}"
|
||||
done
|
||||
|
||||
for file in libexec/*; do
|
||||
cp "${file}" "${LIBEXEC_PATH}"
|
||||
for file in libexec/pyenv-virtualenv/*; do
|
||||
cp -Rp "${file}" "${LIBEXEC_PATH}"
|
||||
done
|
||||
|
||||
echo "Installed pyenv-virtualenv at ${PREFIX}"
|
||||
|
||||
Reference in New Issue
Block a user