27 Commits

Author SHA1 Message Date
Yamashita Yuu
4a6ef11349 v20140614 2014-06-14 14:45:57 +09:00
Yamashita Yuu
21e999cc7c Fix deactivation issue with system version
$ pyenv global system
    $ pyenv shell venv
    (venv) $ pyenv shell --unset
    (venv) $ pyenv version
    system (set by /home/yamashita/.pyenv/version)
    (venv) $ pyenv which python
    /home/yamashita/.pyenv/versions/venv/bin/python # <-- should be `/usr/bin/python` (system)
2014-06-13 19:30:37 +09:00
Yamashita Yuu
e853f74b26 Fix test cases around create_symlinks 2014-06-12 20:35:46 +09:00
Yamashita Yuu
fe5e69846e Create symlinks for executables with version suffix 2014-06-12 20:35:44 +09:00
Yamashita Yuu
c17e4ec9a4 style 2014-06-05 19:31:10 +09:00
Yamashita Yuu
7828a15066 Use pyenv-virtualenv-init to show caveats 2014-06-05 00:17:06 +09:00
Yamashita Yuu
55a2a9e482 Read shell profile from $TMP during tests 2014-06-05 00:16:41 +09:00
Yamashita Yuu
b258bfa907 Display notice about virtualenv-init in activate 2014-06-05 00:08:21 +09:00
Yamashita, Yuu
8838bae3bc Merge pull request #24 from yyuu/automatic-activation
Automatic activation
2014-06-04 20:51:05 +09:00
Yamashita Yuu
b7535395e8 Update README 2014-06-04 20:48:22 +09:00
Yamashita Yuu
6761ed09cd Add test for pyenv-virtualenv-init 2014-06-04 20:48:22 +09:00
Yamashita Yuu
8a837758dc activate: invoke pyenv shell only if the arguments passed 2014-06-04 15:24:36 +09:00
Yamashita Yuu
ea120da0c5 fish: Suppress annoying stderr outputs from pyenv-sh-activate 2014-06-04 15:24:34 +09:00
Yamashita Yuu
af6c157a79 Add eval "$(pyenv virtualenv-init -)" to setup _precmd_ for user's shell 2014-06-04 15:24:12 +09:00
Yamashita Yuu
c9043920db v20140602 2014-06-02 21:42:27 +09:00
Yamashita Yuu
26f2004abb Add semicolon for the deactivate scripts for non-fish 2014-06-02 16:02:39 +09:00
Yamashita, Yuu
b9e2fc6acb Merge pull request #23 from fgimian/fish-activation-fix
Repaired virtualenv activation and deactivation for the fish shell
2014-05-31 14:19:02 +09:00
Fotis Gimian
21a8745bcf Updated tests to correctly pass for fish shell bug fix 2014-05-31 15:15:45 +10:00
Fotis Gimian
f7da0c5808 Repaired virtualenv activation and deactivation for the fish shell 2014-05-31 12:29:19 +10:00
Yamashita Yuu
3f5171e2fc Use new style GH raw url to avoid redirects (raw.github.com -> raw.githubusercontent.com) 2014-04-30 11:52:15 +09:00
Yamashita Yuu
579f4784c8 v20140421 (fixes #19) 2014-04-21 20:24:25 +09:00
Yamashita Yuu
a8940e2f85 Merge branch 'pyvenv-with-p' 2014-04-20 15:27:41 +09:00
Yamashita Yuu
2cab533652 Use virtualenv instead of pyvenv if -p has given (yyuu/pyenv#158) 2014-04-20 15:24:40 +09:00
Yamashita Yuu
5033c3ba0d Update README about pyenv activate --unset (#15) 2014-02-03 16:13:41 +09:00
Yamashita Yuu
a958640776 Fix completion of pyenv activate (fixes #15) 2014-02-03 14:49:47 +09:00
Yamashita Yuu
503a51564e Display error if pyenv activate was invoked as a command 2014-01-25 19:14:58 +09:00
Yamashita Yuu
1db565b67c Update README.
Restart shell after installation of the plugin to enable `pyenv-sh-*`
commands.
2014-01-25 18:39:29 +09:00
14 changed files with 478 additions and 130 deletions

View File

@@ -14,13 +14,9 @@ to manage your virtualenvs.)
### Installing as a pyenv plugin
Installing pyenv-virtualenv as a pyenv plugin will give you access to the
`pyenv virtualenv` command.
$ git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
This will install the latest development version of pyenv-virtualenv into
the `~/.pyenv/plugins/pyenv-virtualenv` directory.
**Important note:** If you installed pyenv into a non-standard directory, make sure that you clone this
repo into the 'plugins' directory of wherever you installed into.
@@ -28,6 +24,21 @@ From inside that directory you can:
- Check out a specific release tag.
- Get the latest development release by running `git pull` to download the latest changes.
1. **Check out pyenv-virtualenv into plugin directory**
$ git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
2. **Add `pyenv virtualenv-init` to your shell** to enable activation of virtualenv
$ echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
**Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`.
3. **Restart your shell to the enable pyenv-virtualenv**
$ exec "$SHELL"
### Installing with Homebrew (for OS X users)
Mac OS X users can install pyenv-virtualenv with the
@@ -38,11 +49,18 @@ installed, you will also be able to use the `pyenv virtualenv` command.
*This is recommended method of installation if you installed pyenv
with Homebrew.*
brew install pyenv-virtualenv
```
$ brew install pyenv-virtualenv
```
Or, if you would like to install the latest development release:
brew install --HEAD pyenv-virtualenv
```
$ brew install --HEAD pyenv-virtualenv
```
After installation, you'll still need to add `eval "$(pyenv virtualenv-init -)"` to your
profile (as stated in the caveats). You'll only ever have to do this once.
## Usage
@@ -53,10 +71,12 @@ To create a virtualenv for the Python version use with pyenv, run
`pyenv virtualenv`, specifying the Python version you want and the name
of the virtualenv directory. For example,
$ pyenv virtualenv 2.7.6 my-virtual-env-2.7.6
```
$ pyenv virtualenv 2.7.7 my-virtual-env-2.7.7
```
will create a virtualenv based on Python 2.7.6
under `~/.pyenv/versions` in a folder called `my-virtual-env-2.7.6`.
will create a virtualenv based on Python 2.7.7
under `~/.pyenv/versions` in a folder called `my-virtual-env-2.7.7`.
### Create virtualenv from current version
@@ -65,37 +85,29 @@ If there is only one argument is given to `pyenv virtualenv`,
virtualenv will be created with given name based on current
version.
$ pyenv version
3.3.3 (set by /home/yyuu/.pyenv/version)
$ pyenv virtualenv venv33
```
$ pyenv version
3.4.1 (set by /home/yyuu/.pyenv/version)
$ pyenv virtualenv venv34
```
### List existing virtualenvs
`pyenv virtualenvs` shows you the list of existing virtualenvs.
$ pyenv shell venv27
$ pyenv virtualenvs
* venv27 (created from /home/yyuu/.pyenv/versions/2.7.6)
venv33 (created from /home/yyuu/.pyenv/versions/3.3.3)
```
$ pyenv shell venv27
$ pyenv virtualenvs
* venv27 (created from /home/yyuu/.pyenv/versions/2.7.7)
venv34 (created from /home/yyuu/.pyenv/versions/3.4.1)
```
### Activate virtualenv
Some external tools (e.g. [jedi](https://github.com/davidhalter/jedi)) might require you to `activate` the virtualenv.
`pyenv activate` lets you to activate the virtualenv into your shell.
$ pyenv activate venv27
`pyenv activate` acts almost like following commands.
$ pyenv shell venv27
$ source "$(pyenv prefix venv27)/bin/activate"
You can deactivate the activate'd virtualenv by `pyenv deactivate`.
$ pyenv deactivate
The `pyenv-virtualenv` will automatically activate/deactivate the virtualenv if the `eval "$(pyenv virtualenv-init -)"` is properly configured in your shell.
### Special environment variables
@@ -116,6 +128,22 @@ You can set certain environment variables to control the pyenv-virtualenv.
## Version History
#### 20140614
* Add `pyenv virtualenv-init` to enable auto-activation feature (#24)
* Create symlinks for executables with version suffix (yyuu/pyenv#182)
#### 20140602
* Use new style GH raw url to avoid redirects (raw.github.com -> raw.githubusercontent.com)
* Repaired virtualenv activation and deactivation for the fish shell (#23)
#### 20140421
* Display error if `pyenv activate` was invoked as a command
* Fix completion of `pyenv activate` (#15)
* Use `virtualenv` instead of `pyvenv` if `-p` has given (yyuu/pyenv#158)
#### 20140123
* Add `activate` and `deactivate` to make `pyenv-virtualenv` work with [jedi](https://github.com/davidhalter/jedi) (#9)

32
bin/pyenv-activate Executable file
View File

@@ -0,0 +1,32 @@
#!/usr/bin/env bash
#
# Summary: Activate virtual environment
#
# Usage: pyenv activate <virtualenv>
# pyenv activate --unset
#
# Activate a Python virtualenv environment in current shell.
# This acts almost as same as `pyenv shell`, but this invokes the `activate`
# script in your shell.
#
# <virtualenv> should be a string matching a Python version known to pyenv.
set -e
[ -n "$PYENV_DEBUG" ] && set -x
# Provide pyenv completions
if [ "$1" = "--complete" ]; then
echo --unset
exec pyenv-virtualenvs --bare
fi
{ printf "\x1B[31;1m"
echo
echo "Failed to activate virtualenv."
echo
echo "Perhaps pyenv-virtualenv has not been loaded into your shell properly."
echo "Please restart current shell and try again."
echo
printf "\x1B[0m"
} 1>&2
exit 1

21
bin/pyenv-deactivate Executable file
View File

@@ -0,0 +1,21 @@
#!/usr/bin/env bash
#
# Summary: Deactivate virtual environment
#
# Usage: pyenv deactivate
#
# Deactivate a Python virtual environment.
set -e
[ -n "$PYENV_DEBUG" ] && set -x
{ printf "\x1B[31;1m"
echo
echo "Failed to deactivate virtualenv."
echo
echo "Perhaps pyenv-virtualenv has not been loaded into your shell properly."
echo "Please restart current shell and try again."
echo
printf "\x1B[0m"
} 1>&2
exit 1

View File

@@ -26,9 +26,8 @@ if [ "$1" = "--unset" ]; then
fi
versions=("$@")
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
if [ -z "$versions" ]; then
no_shell=1
OLDIFS="$IFS"
IFS=: versions=($(pyenv-version-name))
IFS="$OLDIFS"
@@ -41,7 +40,34 @@ fi
pyenv-virtualenv-prefix "${versions}" 1>/dev/null
echo "pyenv shell \"${versions}\""
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
case "$shell" in
bash )
profile="$HOME/.bash_profile"
;;
zsh )
profile="$HOME/.zshrc"
;;
ksh )
profile="$HOME/.profile"
;;
fish )
profile="$HOME/.config/fish/config.fish"
;;
* )
profile="$HOME/.profile"
;;
esac
# Display setup instruction if 'pyenv virtualenv-init -' is not found in "$profile"
if [ -f "$profile" ] && grep -q 'pyenv init -' "$profile" && ! grep -q 'pyenv virtualenv-init -' "$profile"; then
pyenv-virtualenv-init >&2 || true
fi
if [ -z "$no_shell" ]; then
echo "pyenv shell \"${versions}\";"
fi
case "$shell" in
fish ) echo ". \"$(pyenv-prefix "${versions}")/bin/activate.fish\"" ;;
* ) echo "source \"$(pyenv-prefix "${versions}")/bin/activate\"" ;;

View File

@@ -14,4 +14,3 @@ case "$shell" in
fish ) echo "functions -q deactivate; and deactivate";;
* ) echo "declare -f deactivate 1>/dev/null 2>&1 && deactivate";;
esac
echo "pyenv shell --unset"

View File

@@ -11,7 +11,7 @@
# -f/--force Install even if the version appears to be installed already
#
PYENV_VIRTUALENV_VERSION="20140123"
PYENV_VIRTUALENV_VERSION="20140614"
set -e
[ -n "$PYENV_DEBUG" ] && set -x
@@ -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
}
@@ -181,9 +181,9 @@ install_pip() {
else
[ -n "${GET_PIP_URL}" ] || {
if [ -n "${PIP_VERSION}" ]; then
GET_PIP_URL="https://raw.github.com/pypa/pip/${PIP_VERSION}/contrib/get-pip.py"
GET_PIP_URL="https://raw.githubusercontent.com/pypa/pip/${PIP_VERSION}/contrib/get-pip.py"
else
GET_PIP_URL="https://raw.github.com/pypa/pip/master/contrib/get-pip.py"
GET_PIP_URL="https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py"
fi
}
if [ -n "$VERBOSE" ]; then
@@ -202,22 +202,35 @@ install_virtualenv() {
ensurepip() {
local version="$1"
if PYENV_VERSION="${version}" pyenv-exec python -m ensurepip 2>/dev/null; then
local PREFIX_PATH="$(pyenv-prefix "${version}")"
if [ ! -e "${PREFIX_PATH}/bin/pip" ]; then
local pip="$(PYENV_VERSION="${version}" pyenv-exec python -c 'import sys;v=sys.version_info;sys.stdout.write("pip%d.%d"%(v[0],v[1]))')"
if [ -e "${PREFIX_PATH}/bin/${pip}" ]; then
( cd "${PREFIX_PATH}/bin" && ln -fs "${pip}" "pip" )
fi
fi
else
PYENV_VERSION="${version}" pyenv-exec python -m ensurepip 2>/dev/null || {
PYENV_VERSION="${version}" pyenv-exec python -c "import setuptools" 1>/dev/null 2>&1 || {
install_setuptools "${version}"
} 1>&2
PYENV_VERSION="${version}" pyenv-which pip 1>/dev/null 2>&1 || {
install_pip "${version}"
} 1>&2
fi
}
}
create_symlinks() {
local version="$1"
local suffix="$(PYENV_VERSION="${version}" pyenv-exec python -c 'import sys;v=sys.version_info;sys.stdout.write("%d.%d"%(v[0],v[1]))')"
local file link
shopt -s nullglob
for file in "${VIRTUALENV_PATH}/bin"/*; do
if [[ "${file##*/}" == *"${suffix}" ]]; then
if [[ "${file}" == *"-${suffix}" ]]; then
link="${file%%-${suffix}}"
else
link="${file%%${suffix}}"
fi
if [ ! -e "${link}" ]; then
( cd "${file%/*}" && ln -fs "${file##*/}" "${link##*/}" )
fi
fi
done
shopt -u nullglob
}
prepare_upgrade() {
@@ -253,6 +266,7 @@ fi
VIRTUALENV_OPTIONS=()
unset FORCE
unset VIRTUALENV_PYTHON
unset QUIET
unset UPGRADE
unset VERBOSE
@@ -266,8 +280,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 +298,11 @@ for option in "${OPTIONS[@]}"; do
exit 0
;;
* ) # virtualenv long options
VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--$option"
if [[ "$option" == "python="* ]]; then
VIRTUALENV_PYTHON="${option#python=}"
else
VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--$option"
fi
;;
esac
done
@@ -338,6 +356,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
@@ -414,6 +435,8 @@ if [ -n "$UPGRADE" ]; then
upgrade "${VIRTUALENV_NAME}" "${VIRTUALENV_PATH}" || STATUS="$?"
fi
create_symlinks "${VIRTUALENV_NAME}"
# Execute `after_virtualenv` hooks
for hook in "${after_hooks[@]}"; do eval "$hook"; done

112
bin/pyenv-virtualenv-init Executable file
View File

@@ -0,0 +1,112 @@
#!/usr/bin/env bash
# Summary: Configure the shell environment for pyenv-virtualenv
# Usage: eval "$(pyenv virtualenv-init - [<shell>])"
#
# Automatically activates a Python virtualenv environment based on current
# pyenv version.
#
set -e
[ -n "$PYENV_DEBUG" ] && set -x
print=""
for args in "$@"
do
if [ "$args" = "-" ]; then
print=1
shift
fi
done
shell="$1"
if [ -z "$shell" ]; then
shell="$(ps c -p "$PPID" -o 'ucomm=' 2>/dev/null || true)"
shell="${shell##-}"
shell="${shell%% *}"
shell="$(basename "${shell:-$SHELL}")"
fi
if [ -z "$print" ]; then
case "$shell" in
bash )
profile='~/.bash_profile'
;;
zsh )
profile='~/.zshrc'
;;
ksh )
profile='~/.profile'
;;
fish )
profile='~/.config/fish/config.fish'
;;
* )
profile='your profile'
;;
esac
{ echo "# Load pyenv-virtualenv automatically by adding"
echo "# the following to ${profile}:"
echo
case "$shell" in
fish )
echo 'status --is-interactive; and . (pyenv virtualenv-init -|psub)'
;;
* )
echo 'eval "$(pyenv virtualenv-init -)"'
;;
esac
echo
} >&2
exit 1
fi
case "$shell" in
bash )
cat <<EOS
_pyenv_virtualenv_hook() {
if [[ "\$(pyenv version-name)" == "system" ]]; then
pyenv deactivate || true;
elif [[ "\$VIRTUAL_ENV" != "\$(pyenv prefix)" ]]; then
pyenv deactivate || true;
pyenv activate 2>/dev/null || true
fi
};
if ! [[ "\$PROMPT_COMMAND" =~ _pyenv_virtualenv_hook ]]; then
PROMPT_COMMAND="_pyenv_virtualenv_hook;\$PROMPT_COMMAND";
fi
EOS
;;
fish )
cat <<EOS
function _pyenv_virtualenv_hook --on-event fish_prompt;
if [ (pyenv version-name) = "system" ]
eval (pyenv sh-deactivate); or true
else if [ "\$VIRTUAL_ENV" != (pyenv prefix) ]
eval (pyenv sh-deactivate); or true
eval (pyenv sh-activate 2>/dev/null); or true
end
end
EOS
;;
zsh )
cat <<EOS
_pyenv_virtualenv_hook() {
if [[ "\$(pyenv version-name)" == "system" ]]; then
pyenv deactivate || true
elif [[ "\$VIRTUAL_ENV" != "\$(pyenv prefix)" ]]; then
pyenv deactivate || true
pyenv activate 2>/dev/null || true
fi
}
typeset -a precmd_functions
if [[ -z \$precmd_functions[(r)_pyenv_virtualenv_hook] ]]; then
precmd_functions+=_pyenv_virtualenv_hook;
fi
EOS
;;
* )
# FIXME: what should i do here??
;;
esac

View File

@@ -3,6 +3,7 @@
load test_helper
setup() {
export HOME="${TMP}"
export PYENV_ROOT="${TMP}/pyenv"
}
@@ -19,7 +20,6 @@ setup() {
assert_success
assert_output <<EOS
pyenv shell "venv"
source "${PYENV_ROOT}/versions/venv/bin/activate"
EOS
}
@@ -37,7 +37,6 @@ EOS
assert_success
assert_output <<EOS
pyenv shell "venv"
. "${PYENV_ROOT}/versions/venv/bin/activate.fish"
EOS
}
@@ -53,7 +52,7 @@ EOS
assert_success
assert_output <<EOS
pyenv shell "venv27"
pyenv shell "venv27";
source "${PYENV_ROOT}/versions/venv27/bin/activate"
EOS
}
@@ -85,3 +84,9 @@ EOS
pyenv-virtualenv: cannot activate multiple versions at once: venv venv27
EOS
}
@test "should fail if activate is invoked as a command" {
run pyenv-activate
assert_failure
}

View File

@@ -12,7 +12,6 @@ setup() {
assert_success
assert_output <<EOS
declare -f deactivate 1>/dev/null 2>&1 && deactivate
pyenv shell --unset
EOS
}
@@ -22,6 +21,11 @@ EOS
assert_success
assert_output <<EOS
functions -q deactivate; and deactivate
pyenv shell --unset
EOS
}
@test "should fail if deactivate is invoked as a command" {
run pyenv-deactivate
assert_failure
}

44
test/init.bats Normal file
View File

@@ -0,0 +1,44 @@
#!/usr/bin/env bats
load test_helper
@test "detect parent shell" {
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
SHELL=/bin/false run pyenv-virtualenv-init -
assert_success
assert_output_contains ' PROMPT_COMMAND="_pyenv_virtualenv_hook;$PROMPT_COMMAND";'
}
@test "sh-compatible instructions" {
run pyenv-virtualenv-init bash
assert [ "$status" -eq 1 ]
assert_output_contains 'eval "$(pyenv virtualenv-init -)"'
run pyenv-virtualenv-init zsh
assert [ "$status" -eq 1 ]
assert_output_contains 'eval "$(pyenv virtualenv-init -)"'
}
@test "fish instructions" {
run pyenv-virtualenv-init fish
assert [ "$status" -eq 1 ]
assert_output_contains 'status --is-interactive; and . (pyenv virtualenv-init -|psub)'
}
@test "outputs bash-specific syntax" {
run pyenv-virtualenv-init - bash
assert_success
assert_output_contains ' PROMPT_COMMAND="_pyenv_virtualenv_hook;$PROMPT_COMMAND";'
}
@test "outputs fish-specific syntax" {
run pyenv-virtualenv-init - fish
assert_success
assert_output_contains 'function _pyenv_virtualenv_hook --on-event fish_prompt;'
}
@test "outputs zsh-specific syntax" {
run pyenv-virtualenv-init - zsh
assert_success
assert_output_contains ' precmd_functions+=_pyenv_virtualenv_hook;'
}

View File

@@ -9,9 +9,12 @@ load test_helper
cd usr
assert [ -x bin/pyenv-activate ]
assert [ -x bin/pyenv-deactivate ]
assert [ -x bin/pyenv-sh-activate ]
assert [ -x bin/pyenv-sh-deactivate ]
assert [ -x bin/pyenv-virtualenv ]
assert [ -x bin/pyenv-virtualenv-init ]
assert [ -x bin/pyenv-virtualenv-prefix ]
assert [ -x bin/pyenv-virtualenvs ]
}

View File

@@ -35,19 +35,14 @@ remove_executable() {
@test "use pyvenv if virtualenv is not available" {
stub_pyenv "3.4.0"
stub pyenv-which "virtualenv : false" \
"pyvenv : echo '${PYENV_ROOT}/versions/bin/pyvenv'"
stub pyenv-exec "echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\"" \
"bin=\"${PYENV_ROOT}/versions/venv/bin\";mkdir -p \"\$bin\";touch \"\$bin/pip3.4\";echo PYENV_VERSION=\${PYENV_VERSION} ensurepip" \
"echo pip3.4"
stub pyenv-prefix "venv : echo '${PYENV_ROOT}/versions/venv'"
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 "bin=\"${PYENV_ROOT}/versions/venv/bin\";mkdir -p \"\$bin\";touch \"\$bin/pip3.4\";echo PYENV_VERSION=\${PYENV_VERSION} ensurepip"
stub pyenv-exec "echo 3.4"
run pyenv-virtualenv venv
unstub_pyenv
unstub pyenv-which
unstub pyenv-exec
assert_success
assert_output <<OUT
PYENV_VERSION=3.4.0 pyvenv ${PYENV_ROOT}/versions/venv
@@ -55,39 +50,41 @@ PYENV_VERSION=venv ensurepip
rehashed
OUT
assert [ -e "${PYENV_ROOT}/versions/venv/bin/pip" ]
}
@test "not use pyvenv if virtualenv is available" {
stub_pyenv "3.4.0"
stub pyenv-which "virtualenv : echo '${PYENV_ROOT}/versions/bin/virtualenv'" \
"pyvenv : echo '${PYENV_ROOT}/versions/bin/pyvenv"
stub pyenv-exec "echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
run pyenv-virtualenv venv
unstub_pyenv
unstub pyenv-which
unstub pyenv-exec
}
@test "not use pyvenv if virtualenv is available" {
stub_pyenv "3.4.0"
stub pyenv-which "virtualenv : echo '${PYENV_ROOT}/versions/bin/virtualenv'"
stub pyenv-which "pyvenv : echo '${PYENV_ROOT}/versions/bin/pyvenv"
stub pyenv-exec "echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
stub pyenv-exec "echo 3.4"
run pyenv-virtualenv venv
assert_success
assert_output <<OUT
PYENV_VERSION=3.4.0 virtualenv ${PYENV_ROOT}/versions/venv
rehashed
OUT
}
@test "install virtualenv if pyvenv is not avaialble" {
stub_pyenv "3.2.1"
stub pyenv-which "virtualenv : false" \
"pyvenv : false"
stub pyenv-exec "echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\"" \
"echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
run pyenv-virtualenv venv
unstub_pyenv
unstub pyenv-which
unstub pyenv-exec
}
@test "install virtualenv if pyvenv is not avaialble" {
stub_pyenv "3.2.1"
stub pyenv-which "virtualenv : false"
stub pyenv-which "pyvenv : false"
stub pyenv-exec "echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
stub pyenv-exec "echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
stub pyenv-exec "echo 3.2"
run pyenv-virtualenv venv
assert_success
assert_output <<OUT
@@ -95,20 +92,65 @@ PYENV_VERSION=3.2.1 pip install virtualenv
PYENV_VERSION=3.2.1 virtualenv ${PYENV_ROOT}/versions/venv
rehashed
OUT
}
@test "install virtualenv with unsetting troublesome pip options" {
stub_pyenv "3.2.1"
stub pyenv-which "virtualenv : false" \
"pyvenv : false"
stub pyenv-exec "echo PIP_REQUIRE_VENV=\${PIP_REQUIRE_VENV} PYENV_VERSION=\${PYENV_VERSION} \"\$@\"" \
"echo PIP_REQUIRE_VENV=\${PIP_REQUIRE_VENV} PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
PIP_REQUIRE_VENV="true" run pyenv-virtualenv venv
unstub_pyenv
unstub pyenv-which
unstub pyenv-exec
}
@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} \"\$@\""
stub pyenv-exec "echo 3.4"
run pyenv-virtualenv -p python3 venv
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
unstub_pyenv
unstub pyenv-which
unstub pyenv-exec
}
@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} \"\$@\""
stub pyenv-exec "echo 3.4"
run pyenv-virtualenv --python=python3 venv
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
unstub_pyenv
unstub pyenv-which
unstub pyenv-exec
}
@test "install virtualenv with unsetting troublesome pip options" {
stub_pyenv "3.2.1"
stub pyenv-which "virtualenv : false"
stub pyenv-which "pyvenv : false"
stub pyenv-exec "echo PIP_REQUIRE_VENV=\${PIP_REQUIRE_VENV} PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
stub pyenv-exec "echo PIP_REQUIRE_VENV=\${PIP_REQUIRE_VENV} PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
stub pyenv-exec "echo 3.2"
PIP_REQUIRE_VENV="true" run pyenv-virtualenv venv
assert_success
assert_output <<OUT
@@ -116,26 +158,27 @@ PIP_REQUIRE_VENV= PYENV_VERSION=3.2.1 pip install virtualenv
PIP_REQUIRE_VENV= PYENV_VERSION=3.2.1 virtualenv ${PYENV_ROOT}/versions/venv
rehashed
OUT
}
@test "install pip without using ensurepip" {
stub_pyenv "3.3.0"
stub pyenv-which "virtualenv : false" \
"pyvenv : echo '${PYENV_ROOT}/versions/bin/pyvenv'" \
"pip : echo no pip; false"
stub pyenv-exec "echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\"" \
"echo PYENV_VERSION=\${PYENV_VERSION} no ensurepip; false" \
"echo PYENV_VERSION=\${PYENV_VERSION} no setuptools; false" \
"echo PYENV_VERSION=\${PYENV_VERSION} setuptools" \
"bin=\"${PYENV_ROOT}/versions/venv/bin\";mkdir -p \"\$bin\";touch \"\$bin/pip\";echo PYENV_VERSION=\${PYENV_VERSION} pip"
stub curl "echo ez_setup.py" \
"echo get_pip.py"
run pyenv-virtualenv venv
unstub_pyenv
unstub pyenv-which
unstub pyenv-exec
}
@test "install pip without using ensurepip" {
stub_pyenv "3.3.0"
stub pyenv-which "virtualenv : false"
stub pyenv-which "pyvenv : echo '${PYENV_ROOT}/versions/bin/pyvenv'"
stub pyenv-which "pip : echo no pip; false"
stub pyenv-exec "echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
stub pyenv-exec "echo PYENV_VERSION=\${PYENV_VERSION} no ensurepip; false"
stub pyenv-exec "echo PYENV_VERSION=\${PYENV_VERSION} no setuptools; false"
stub pyenv-exec "echo PYENV_VERSION=\${PYENV_VERSION} setuptools"
stub pyenv-exec "bin=\"${PYENV_ROOT}/versions/venv/bin\";mkdir -p \"\$bin\";touch \"\$bin/pip\";echo PYENV_VERSION=\${PYENV_VERSION} pip"
stub pyenv-exec "echo 3.3"
stub curl "echo ez_setup.py"
stub curl "echo get_pip.py"
run pyenv-virtualenv venv
assert_success
assert_output <<OUT
@@ -146,4 +189,8 @@ PYENV_VERSION=venv pip
rehashed
OUT
assert [ -e "${PYENV_ROOT}/versions/venv/bin/pip" ]
unstub_pyenv
unstub pyenv-which
unstub pyenv-exec
}

View File

@@ -4,7 +4,7 @@ load test_helper
setup() {
export PYENV_ROOT="${TMP}/pyenv"
export PYENV_VIRTUALENV_VERSION="20140123"
export PYENV_VIRTUALENV_VERSION="20140614"
}
@test "display virtualenv version" {

View File

@@ -9,8 +9,8 @@ setup() {
stub_pyenv() {
export PYENV_VERSION="$1"
stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/\${PYENV_VERSION}'"
stub pyenv-which "virtualenv : echo '${PYENV_ROOT}/versions/bin/virtualenv'" \
"pyvenv : false"
stub pyenv-which "virtualenv : echo '${PYENV_ROOT}/versions/bin/virtualenv'"
stub pyenv-which "pyvenv : false"
stub pyenv-hooks "virtualenv : echo"
stub pyenv-rehash " : echo rehashed"
}
@@ -26,69 +26,73 @@ unstub_pyenv() {
@test "create virtualenv from given version" {
stub_pyenv "3.2.1"
stub pyenv-exec "echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
stub pyenv-exec "echo 3.2"
run pyenv-virtualenv "3.2.1" "venv"
unstub_pyenv
unstub pyenv-exec
assert_success
assert_output <<OUT
PYENV_VERSION=3.2.1 virtualenv ${PYENV_ROOT}/versions/venv
rehashed
OUT
unstub_pyenv
unstub pyenv-exec
}
@test "create virtualenv from current version" {
stub_pyenv "3.2.1"
stub pyenv-version-name "echo \${PYENV_VERSION}"
stub pyenv-exec "echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
stub pyenv-exec "echo 3.2"
run pyenv-virtualenv venv
unstub_pyenv
unstub pyenv-version-name
unstub pyenv-exec
assert_success
assert_output <<OUT
PYENV_VERSION=3.2.1 virtualenv ${PYENV_ROOT}/versions/venv
rehashed
OUT
unstub_pyenv
unstub pyenv-version-name
unstub pyenv-exec
}
@test "create virtualenv with short options" {
stub_pyenv "3.2.1"
stub pyenv-version-name "echo \${PYENV_VERSION}"
stub pyenv-exec "echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
stub pyenv-exec "echo 3.2"
run pyenv-virtualenv -v -p python venv
unstub_pyenv
unstub pyenv-version-name
unstub pyenv-exec
assert_success
assert_output <<OUT
PYENV_VERSION=3.2.1 virtualenv --verbose --python=python ${PYENV_ROOT}/versions/venv
rehashed
OUT
unstub_pyenv
unstub pyenv-version-name
unstub pyenv-exec
}
@test "create virtualenv with long options" {
stub_pyenv "3.2.1"
stub pyenv-version-name "echo \${PYENV_VERSION}"
stub pyenv-exec "echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
stub pyenv-exec "echo 3.2"
run pyenv-virtualenv --verbose --python=python venv
unstub_pyenv
unstub pyenv-version-name
unstub pyenv-exec
assert_success
assert_output <<OUT
PYENV_VERSION=3.2.1 virtualenv --verbose --python=python ${PYENV_ROOT}/versions/venv
rehashed
OUT
unstub_pyenv
unstub pyenv-version-name
unstub pyenv-exec
}