13 Commits

Author SHA1 Message Date
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
10 changed files with 159 additions and 18 deletions

View File

@@ -18,6 +18,7 @@ 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
$ exec "$SHELL"
This will install the latest development version of pyenv-virtualenv into
the `~/.pyenv/plugins/pyenv-virtualenv` directory.
@@ -88,14 +89,28 @@ Some external tools (e.g. [jedi](https://github.com/davidhalter/jedi)) might req
$ pyenv activate venv27
`pyenv activate` acts almost like following commands.
The activate'd virtualenv will be persisted as _shell_ version.
$ pyenv shell venv27
$ source "$(pyenv prefix venv27)/bin/activate"
You can deactivate the activate'd virtualenv by `pyenv deactivate`.
### Deactivate virtualenv
You can `deactivate` the activate'd virtualenv by `pyenv deactivate`.
$ pyenv deactivate
Or, there is an alias in `activate` command.
This is prepared for similality between other `pyenv` commands like `shell` and `local`.
$ pyenv activate --unset
`pyenv deactivate` acts almost like following commands.
You can also use virtualenv's `deactivate` in place of `pyenv deactivate`,
but be careful with the _shell_ version because it will be persisted even if `deactivate` has invoked.
$ deactivate
$ pyenv shell --unset
### Special environment variables
@@ -116,6 +131,17 @@ You can set certain environment variables to control the pyenv-virtualenv.
## Version History
#### 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

@@ -41,7 +41,7 @@ fi
pyenv-virtualenv-prefix "${versions}" 1>/dev/null
echo "pyenv shell \"${versions}\""
echo "pyenv shell \"${versions}\";"
case "$shell" in
fish ) echo ". \"$(pyenv-prefix "${versions}")/bin/activate.fish\"" ;;
* ) echo "source \"$(pyenv-prefix "${versions}")/bin/activate\"" ;;

View File

@@ -11,7 +11,7 @@ set -e
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
case "$shell" in
fish ) echo "functions -q deactivate; and deactivate";;
* ) echo "declare -f deactivate 1>/dev/null 2>&1 && deactivate";;
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="20140602"
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
@@ -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
VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--$option"
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

@@ -19,7 +19,7 @@ setup() {
assert_success
assert_output <<EOS
pyenv shell "venv"
pyenv shell "venv";
source "${PYENV_ROOT}/versions/venv/bin/activate"
EOS
}
@@ -37,7 +37,7 @@ EOS
assert_success
assert_output <<EOS
pyenv shell "venv"
pyenv shell "venv";
. "${PYENV_ROOT}/versions/venv/bin/activate.fish"
EOS
}
@@ -53,7 +53,7 @@ EOS
assert_success
assert_output <<EOS
pyenv shell "venv27"
pyenv shell "venv27";
source "${PYENV_ROOT}/versions/venv27/bin/activate"
EOS
}
@@ -85,3 +85,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

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

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" \

View File

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