mirror of
https://github.com/pyenv/pyenv-virtualenv.git
synced 2025-11-08 11:33:55 -05:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
579f4784c8 | ||
|
|
a8940e2f85 | ||
|
|
2cab533652 | ||
|
|
5033c3ba0d | ||
|
|
a958640776 | ||
|
|
503a51564e | ||
|
|
1db565b67c |
23
README.md
23
README.md
@@ -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,12 @@ You can set certain environment variables to control the pyenv-virtualenv.
|
||||
|
||||
## Version History
|
||||
|
||||
#### 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
32
bin/pyenv-activate
Executable 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
21
bin/pyenv-deactivate
Executable 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
|
||||
@@ -11,7 +11,7 @@
|
||||
# -f/--force Install even if the version appears to be installed already
|
||||
#
|
||||
|
||||
PYENV_VIRTUALENV_VERSION="20140123"
|
||||
PYENV_VIRTUALENV_VERSION="20140421"
|
||||
|
||||
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
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -25,3 +25,9 @@ functions -q deactivate; and deactivate
|
||||
pyenv shell --unset
|
||||
EOS
|
||||
}
|
||||
|
||||
@test "should fail if deactivate is invoked as a command" {
|
||||
run pyenv-deactivate
|
||||
|
||||
assert_failure
|
||||
}
|
||||
|
||||
@@ -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" \
|
||||
|
||||
@@ -4,7 +4,7 @@ load test_helper
|
||||
|
||||
setup() {
|
||||
export PYENV_ROOT="${TMP}/pyenv"
|
||||
export PYENV_VIRTUALENV_VERSION="20140123"
|
||||
export PYENV_VIRTUALENV_VERSION="20140421"
|
||||
}
|
||||
|
||||
@test "display virtualenv version" {
|
||||
|
||||
Reference in New Issue
Block a user