Merge branch 'pyvenv-with-p'

This commit is contained in:
Yamashita Yuu
2014-04-20 15:27:41 +09:00
2 changed files with 55 additions and 5 deletions

View File

@@ -130,8 +130,8 @@ detect_venv() {
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 only if there is pyvenv, virtualenv is not installed, and `-p` not given
if [ -n "${HAS_PYVENV}" ] && [ -z "${HAS_VIRTUALENV}" ] && [ -z "${VIRTUALENV_PYTHON}" ]; then
USE_PYVENV=1
fi
}
@@ -253,6 +253,7 @@ fi
VIRTUALENV_OPTIONS=()
unset FORCE
unset VIRTUALENV_PYTHON
unset QUIET
unset UPGRADE
unset VERBOSE
@@ -266,8 +267,8 @@ for option in "${OPTIONS[@]}"; do
"h" | "help" )
usage 0
;;
"p" )
VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--python=${ARGUMENTS[0]}"
"p" | "python" )
VIRTUALENV_PYTHON="${ARGUMENTS[0]}"
ARGUMENTS=("${ARGUMENTS[@]:1}") # shift 1
;;
"q" | "quiet" )
@@ -284,7 +285,11 @@ for option in "${OPTIONS[@]}"; do
exit 0
;;
* ) # virtualenv long options
if [[ "$option" == "python="* ]]; then
VIRTUALENV_PYTHON="${option#python=}"
else
VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--$option"
fi
;;
esac
done
@@ -338,6 +343,9 @@ if [ -n "${USE_PYVENV}" ]; then
VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--upgrade"
fi
else
if [ -n "${VIRTUALENV_PYTHON}" ]; then
VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--python=${VIRTUALENV_PYTHON}"
fi
if [ -z "${HAS_VIRTUALENV}" ]; then
install_virtualenv "${PYENV_VERSION}"
HAS_VIRTUALENV=1

View File

@@ -97,6 +97,48 @@ rehashed
OUT
}
@test "install virtualenv if -p has given" {
stub_pyenv "3.4.0"
stub pyenv-which "virtualenv : false"
stub pyenv-which "pyvenv : echo '${PYENV_ROOT}/versions/bin/pyvenv'"
stub pyenv-exec "echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
stub pyenv-exec "echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
run pyenv-virtualenv -p python3 venv
unstub_pyenv
unstub pyenv-which
unstub pyenv-exec
assert_success
assert_output <<OUT
PYENV_VERSION=3.4.0 pip install virtualenv
PYENV_VERSION=3.4.0 virtualenv --python=python3 ${PYENV_ROOT}/versions/venv
rehashed
OUT
}
@test "install virtualenv if --python has given" {
stub_pyenv "3.4.0"
stub pyenv-which "virtualenv : false"
stub pyenv-which "pyvenv : echo '${PYENV_ROOT}/versions/bin/pyvenv'"
stub pyenv-exec "echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
stub pyenv-exec "echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
run pyenv-virtualenv --python=python3 venv
unstub_pyenv
unstub pyenv-which
unstub pyenv-exec
assert_success
assert_output <<OUT
PYENV_VERSION=3.4.0 pip install virtualenv
PYENV_VERSION=3.4.0 virtualenv --python=python3 ${PYENV_ROOT}/versions/venv
rehashed
OUT
}
@test "install virtualenv with unsetting troublesome pip options" {
stub_pyenv "3.2.1"
stub pyenv-which "virtualenv : false" \