|
@ -111,27 +111,24 @@ usage() { |
|
|
[ -z "$1" ] || exit "$1" |
|
|
[ -z "$1" ] || exit "$1" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
virtualenv_is_pyvenv() { |
|
|
|
|
|
# Use pyvenv only if virtualenv is not installed and there is pyvenv |
|
|
|
|
|
if pyenv-which "virtualenv" 1>/dev/null 2>&1; then |
|
|
|
|
|
return 1 |
|
|
|
|
|
else |
|
|
|
|
|
pyenv-which "pyvenv" 1>/dev/null 2>&1 |
|
|
|
|
|
fi |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
venv() { |
|
|
venv() { |
|
|
if virtualenv_is_pyvenv; then |
|
|
|
|
|
pyenv-exec pyvenv "$@" |
|
|
|
|
|
|
|
|
local args=("$@") |
|
|
|
|
|
if [ -n "${USE_PYVENV}" ]; then |
|
|
|
|
|
pyenv-exec pyvenv "${args[@]}" |
|
|
|
|
|
|
|
|
|
|
|
local last="${args[${#args[@]}-1]}" |
|
|
|
|
|
ensurepip "${last##*/}" |
|
|
else |
|
|
else |
|
|
pyenv-exec virtualenv "$@" |
|
|
|
|
|
|
|
|
pyenv-exec virtualenv "${args[@]}" |
|
|
fi |
|
|
fi |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
install_setuptools() { |
|
|
install_setuptools() { |
|
|
local version="$1" |
|
|
local version="$1" |
|
|
{ if [ "${EZ_SETUP+defined}" ] && [ -f "${EZ_SETUP}" ]; then |
|
|
{ if [ "${EZ_SETUP+defined}" ] && [ -f "${EZ_SETUP}" ]; then |
|
|
echo "Installing setuptools from ${EZ_SETUP}..." 1>&2 |
|
|
|
|
|
|
|
|
if [ -n "$VERBOSE" ]; then |
|
|
|
|
|
echo "Installing setuptools from ${EZ_SETUP}..." 1>&2 |
|
|
|
|
|
fi |
|
|
cat "${EZ_SETUP}" |
|
|
cat "${EZ_SETUP}" |
|
|
else |
|
|
else |
|
|
[ -n "${EZ_SETUP_URL}" ] || { |
|
|
[ -n "${EZ_SETUP_URL}" ] || { |
|
@ -141,7 +138,9 @@ install_setuptools() { |
|
|
EZ_SETUP_URL="https://bitbucket.org/pypa/setuptools/downloads/ez_setup.py" |
|
|
EZ_SETUP_URL="https://bitbucket.org/pypa/setuptools/downloads/ez_setup.py" |
|
|
fi |
|
|
fi |
|
|
} |
|
|
} |
|
|
echo "Installing setuptools from ${EZ_SETUP_URL}..." 1>&2 |
|
|
|
|
|
|
|
|
if [ -n "$VERBOSE" ]; then |
|
|
|
|
|
echo "Installing setuptools from ${EZ_SETUP_URL}..." 1>&2 |
|
|
|
|
|
fi |
|
|
http get "${EZ_SETUP_URL}" |
|
|
http get "${EZ_SETUP_URL}" |
|
|
fi |
|
|
fi |
|
|
} | PYENV_VERSION="${version}" pyenv-exec python |
|
|
} | PYENV_VERSION="${version}" pyenv-exec python |
|
@ -150,7 +149,9 @@ install_setuptools() { |
|
|
install_pip() { |
|
|
install_pip() { |
|
|
local version="$1" |
|
|
local version="$1" |
|
|
{ if [ "${GET_PIP+defined}" ] && [ -f "${GET_PIP}" ]; then |
|
|
{ if [ "${GET_PIP+defined}" ] && [ -f "${GET_PIP}" ]; then |
|
|
echo "Installing pip from ${GET_PIP}..." 1>&2 |
|
|
|
|
|
|
|
|
if [ -n "$VERBOSE" ]; then |
|
|
|
|
|
echo "Installing pip from ${GET_PIP}..." 1>&2 |
|
|
|
|
|
fi |
|
|
cat "${GET_PIP}" |
|
|
cat "${GET_PIP}" |
|
|
else |
|
|
else |
|
|
[ -n "${GET_PIP_URL}" ] || { |
|
|
[ -n "${GET_PIP_URL}" ] || { |
|
@ -160,12 +161,20 @@ install_pip() { |
|
|
GET_PIP_URL="https://raw.github.com/pypa/pip/master/contrib/get-pip.py" |
|
|
GET_PIP_URL="https://raw.github.com/pypa/pip/master/contrib/get-pip.py" |
|
|
fi |
|
|
fi |
|
|
} |
|
|
} |
|
|
echo "Installing pip from ${GET_PIP_URL}..." 1>&2 |
|
|
|
|
|
|
|
|
if [ -n "$VERBOSE" ]; then |
|
|
|
|
|
echo "Installing pip from ${GET_PIP_URL}..." 1>&2 |
|
|
|
|
|
fi |
|
|
http get "${GET_PIP_URL}" |
|
|
http get "${GET_PIP_URL}" |
|
|
fi |
|
|
fi |
|
|
} | PYENV_VERSION="${version}" pyenv-exec python |
|
|
} | PYENV_VERSION="${version}" pyenv-exec python |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
install_virtualenv() { |
|
|
|
|
|
local version="$1" |
|
|
|
|
|
VIRTUALENV_VERSION="==${VIRTUALENV_VERSION}" |
|
|
|
|
|
PYENV_VERSION="${version}" pyenv-exec pip install $QUIET $VERBOSE "virtualenv${VIRTUALENV_VERSION%==}" |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
ensurepip() { |
|
|
ensurepip() { |
|
|
local version="$1" |
|
|
local version="$1" |
|
|
if PYENV_VERSION="${version}" pyenv-exec python -m ensurepip 2>/dev/null; then |
|
|
if PYENV_VERSION="${version}" pyenv-exec python -m ensurepip 2>/dev/null; then |
|
@ -186,6 +195,32 @@ ensurepip() { |
|
|
fi |
|
|
fi |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
prepare_upgrade() { |
|
|
|
|
|
local version="$1" |
|
|
|
|
|
local prefix="$2" |
|
|
|
|
|
PYENV_VERSION="${version}" pyenv-exec pip freeze >"${UPGRADE_LIST}" |
|
|
|
|
|
mv -f "${prefix}" "${UPGRADE_PATH}" |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
upgrade() { |
|
|
|
|
|
local version="$1" |
|
|
|
|
|
local prefix="$2" |
|
|
|
|
|
## Migrate previously installed packages from requirements.txt |
|
|
|
|
|
if ! PYENV_VERSION="${version}" pyenv-exec pip install $QUIET $VERBOSE --requirement "${UPGRADE_LIST}"; then |
|
|
|
|
|
{ echo |
|
|
|
|
|
echo "UPGRADE FAILED" |
|
|
|
|
|
echo |
|
|
|
|
|
echo "Inspect or clean up the original tree at ${UPGRADE_PATH}" |
|
|
|
|
|
echo |
|
|
|
|
|
echo "Package list:" |
|
|
|
|
|
cat "${UPGRADE_LIST}" |
|
|
|
|
|
} 1>&2 |
|
|
|
|
|
return 1 |
|
|
|
|
|
fi |
|
|
|
|
|
rm -f "${UPGRADE_LIST}" |
|
|
|
|
|
rm -fr "${UPGRADE_PATH}" |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
PYENV_VIRTUALENV_ROOT="$(abs_dirname "$0")/.." |
|
|
PYENV_VIRTUALENV_ROOT="$(abs_dirname "$0")/.." |
|
|
if [ -z "${PYENV_VIRTUALENV_CACHE_PATH}" ]; then |
|
|
if [ -z "${PYENV_VIRTUALENV_CACHE_PATH}" ]; then |
|
|
PYENV_VIRTUALENV_CACHE_PATH="${PYTHON_BUILD_CACHE_PATH:-${PYENV_ROOT}/cache}" |
|
|
PYENV_VIRTUALENV_CACHE_PATH="${PYTHON_BUILD_CACHE_PATH:-${PYENV_ROOT}/cache}" |
|
@ -264,7 +299,22 @@ UPGRADE_LIST="${TMP}/pyenv-virtualenv.${SEED}.txt" |
|
|
|
|
|
|
|
|
VIRTUALENV_PATH="${PYENV_ROOT}/versions/${VIRTUALENV_NAME}" |
|
|
VIRTUALENV_PATH="${PYENV_ROOT}/versions/${VIRTUALENV_NAME}" |
|
|
|
|
|
|
|
|
if virtualenv_is_pyvenv; then |
|
|
|
|
|
|
|
|
unset HAS_VIRTUALENV |
|
|
|
|
|
unset HAS_PYVENV |
|
|
|
|
|
unset USE_PYVENV |
|
|
|
|
|
|
|
|
|
|
|
if pyenv-which "virtualenv" 1>/dev/null 2>&1; then |
|
|
|
|
|
HAS_VIRTUALENV=1 |
|
|
|
|
|
fi |
|
|
|
|
|
if pyenv-which "pyvenv" 1>/dev/null 2>&1; then |
|
|
|
|
|
HAS_PYVENV=1 |
|
|
|
|
|
fi |
|
|
|
|
|
# Use pyvenv only if virtualenv is not installed and there is pyvenv |
|
|
|
|
|
if [ -n "${HAS_PYVENV}" ] && [ -z "${HAS_VIRTUALENV}" ]; then |
|
|
|
|
|
USE_PYVENV=1 |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
if [ -n "${USE_PYVENV}" ]; then |
|
|
# Unset some arguments not supported by pyvenv |
|
|
# Unset some arguments not supported by pyvenv |
|
|
unset QUIET |
|
|
unset QUIET |
|
|
unset VERBOSE |
|
|
unset VERBOSE |
|
@ -273,11 +323,10 @@ if virtualenv_is_pyvenv; then |
|
|
VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--upgrade" |
|
|
VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--upgrade" |
|
|
fi |
|
|
fi |
|
|
else |
|
|
else |
|
|
pyenv-which "virtualenv" 1>/dev/null 2>&1 || { |
|
|
|
|
|
VIRTUALENV_VERSION="==${VIRTUALENV_VERSION}" |
|
|
|
|
|
pyenv-exec pip install $QUIET $VERBOSE "virtualenv${VIRTUALENV_VERSION%==}" |
|
|
|
|
|
pyenv-rehash |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if [ -z "${HAS_VIRTUALENV}" ]; then |
|
|
|
|
|
install_virtualenv "${PYENV_VERSION}" |
|
|
|
|
|
HAS_VIRTUALENV=1 |
|
|
|
|
|
fi |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
# Unset environment variables which starts with `VIRTUALENV_`. |
|
|
# Unset environment variables which starts with `VIRTUALENV_`. |
|
@ -301,9 +350,10 @@ after_virtualenv() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
# Load plugin hooks. |
|
|
# Load plugin hooks. |
|
|
for script in $(pyenv-hooks virtualenv); do |
|
|
|
|
|
source "$script" |
|
|
|
|
|
done |
|
|
|
|
|
|
|
|
OLDIFS="$IFS" |
|
|
|
|
|
IFS=$'\n' scripts=(`pyenv-hooks virtualenv`) |
|
|
|
|
|
IFS="$OLDIFS" |
|
|
|
|
|
for script in "${scripts[@]}"; do source "$script"; done |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[ -d "${VIRTUALENV_PATH}" ] && PREFIX_EXISTS=1 |
|
|
[ -d "${VIRTUALENV_PATH}" ] && PREFIX_EXISTS=1 |
|
@ -322,8 +372,7 @@ if [ -d "${VIRTUALENV_PATH}/bin" ]; then |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
if [ -n "$UPGRADE" ]; then |
|
|
if [ -n "$UPGRADE" ]; then |
|
|
PYENV_VERSION="${VIRTUALENV_NAME}" pyenv-exec pip freeze >"${UPGRADE_LIST}" |
|
|
|
|
|
mv -f "${VIRTUALENV_PATH}" "${UPGRADE_PATH}" |
|
|
|
|
|
|
|
|
prepare_upgrade "${VIRTUALENV_NAME}" "${VIRTUALENV_PATH}" |
|
|
fi |
|
|
fi |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
@ -343,30 +392,11 @@ STATUS=0 |
|
|
# change to cache directory to reuse them between invocation. |
|
|
# change to cache directory to reuse them between invocation. |
|
|
mkdir -p "${PYENV_VIRTUALENV_CACHE_PATH}" |
|
|
mkdir -p "${PYENV_VIRTUALENV_CACHE_PATH}" |
|
|
cd "${PYENV_VIRTUALENV_CACHE_PATH}" |
|
|
cd "${PYENV_VIRTUALENV_CACHE_PATH}" |
|
|
venv $QUIET $VERBOSE "${VIRTUALENV_OPTIONS[@]}" "${VIRTUALENV_PATH}" && { |
|
|
|
|
|
if virtualenv_is_pyvenv; then |
|
|
|
|
|
ensurepip "${VIRTUALENV_NAME}" |
|
|
|
|
|
fi |
|
|
|
|
|
} 1>&2 || STATUS="$?" |
|
|
|
|
|
|
|
|
venv $QUIET $VERBOSE "${VIRTUALENV_OPTIONS[@]}" "${VIRTUALENV_PATH}" || STATUS="$?" |
|
|
|
|
|
|
|
|
## Migrate previously installed packages from requirements.txt |
|
|
## Migrate previously installed packages from requirements.txt |
|
|
if [ -n "$UPGRADE" ]; then |
|
|
if [ -n "$UPGRADE" ]; then |
|
|
UPGRADE_STATUS=0 |
|
|
|
|
|
PYENV_VERSION="${VIRTUALENV_NAME}" pyenv-exec pip install $QUIET $VERBOSE --requirement "${UPGRADE_LIST}" || UPGRADE_STATUS=$? |
|
|
|
|
|
if [ "$UPGRADE_STATUS" == "0" ]; then |
|
|
|
|
|
rm -f "${UPGRADE_LIST}" |
|
|
|
|
|
rm -fr "${UPGRADE_PATH}" |
|
|
|
|
|
else |
|
|
|
|
|
{ echo |
|
|
|
|
|
echo "UPGRADE FAILED" |
|
|
|
|
|
echo |
|
|
|
|
|
echo "Inspect or clean up the original tree at ${UPGRADE_PATH}" |
|
|
|
|
|
echo |
|
|
|
|
|
echo "Package list:" |
|
|
|
|
|
cat "${UPGRADE_LIST}" |
|
|
|
|
|
} 1>&2 |
|
|
|
|
|
STATUS="$UPGRADE_STATUS" |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
upgrade "${VIRTUALENV_NAME}" "${VIRTUALENV_PATH}" || STATUS="$?" |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
# Execute `after_virtualenv` hooks |
|
|
# Execute `after_virtualenv` hooks |
|
|