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

View File

@@ -97,6 +97,48 @@ rehashed
OUT 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" { @test "install virtualenv with unsetting troublesome pip options" {
stub_pyenv "3.2.1" stub_pyenv "3.2.1"
stub pyenv-which "virtualenv : false" \ stub pyenv-which "virtualenv : false" \