mirror of
https://github.com/pyenv/pyenv-virtualenv.git
synced 2025-11-08 11:33:55 -05:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a52f9fb5d | ||
|
|
0ca01826e8 | ||
|
|
4fa9c7b220 | ||
|
|
2571a2b973 | ||
|
|
95fa7a35ad | ||
|
|
47cd86a165 | ||
|
|
d9c3f9a2f5 | ||
|
|
6bc0253d17 | ||
|
|
c184c01174 | ||
|
|
55189357e2 | ||
|
|
9544c8b178 | ||
|
|
bcb7abdf93 | ||
|
|
5953ddaf64 | ||
|
|
2ab9483116 |
@@ -125,11 +125,10 @@ You can also activate and deactivate a pyenv virtualenv manually:
|
||||
Removing the directory in `~/.pyenv/versions` will delete the virtualenv, or you can run:
|
||||
|
||||
pyenv uninstall my-virtual-env
|
||||
|
||||
|
||||
### virtualenv and pyvenv
|
||||
|
||||
There is a [venv](http://docs.python.jp/3/library/venv.html) module available
|
||||
There is a [venv](http://docs.python.org/3/library/venv.html) module available
|
||||
for CPython 3.3 and newer.
|
||||
It provides a command-line tool `pyvenv` which is the successor of `virtualenv`
|
||||
and distributed by default.
|
||||
@@ -157,6 +156,12 @@ You can set certain environment variables to control pyenv-virtualenv.
|
||||
|
||||
## Version History
|
||||
|
||||
#### 20150526
|
||||
|
||||
* Use `typeset -g` with `precmd_functions` (#75)
|
||||
* activate: display setup instructions only with `PYENV_VIRTUALENV_INIT=0` (#78)
|
||||
* Ignore failure of pyenv activate (#68)
|
||||
|
||||
#### 20150119
|
||||
|
||||
* Ignore errors from `pyenv-version-name` since it might fail if there is configuration error (yyuu/pyenv#291)
|
||||
|
||||
@@ -68,27 +68,11 @@ if ! pyenv-virtualenv-prefix "${versions}" 1>/dev/null 2>&1; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
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
|
||||
shell="${PYENV_SHELL:-${SHELL##*/}}"
|
||||
|
||||
# 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
|
||||
# Display setup instruction, if pyenv-virtualenv has not been initialized.
|
||||
# if 'pyenv virtualenv-init -' is not found in "$profile"
|
||||
if [ -z "$PYENV_VIRTUALENV_INIT" ]; then
|
||||
pyenv-virtualenv-init >&2 || true
|
||||
fi
|
||||
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
#
|
||||
# Summary: Create a Python virtualenv using the pyenv-virtualenv plugin
|
||||
#
|
||||
# Usage: pyenv virtualenv [-f|--force] [VIRTUALENV_OPTIONS] <version> <virtualenv-name>
|
||||
# Usage: pyenv virtualenv [-f|--force] [VIRTUALENV_OPTIONS] [version] <virtualenv-name>
|
||||
# pyenv virtualenv --version
|
||||
# pyenv virtualenv --help
|
||||
#
|
||||
# -f/--force Install even if the version appears to be installed already
|
||||
#
|
||||
|
||||
PYENV_VIRTUALENV_VERSION="20150119"
|
||||
PYENV_VIRTUALENV_VERSION="20150526"
|
||||
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
@@ -283,7 +283,7 @@ fi
|
||||
# Set VERSION_NAME as default version in this script
|
||||
export PYENV_VERSION="${VERSION_NAME}"
|
||||
|
||||
# Source version must exists before creating virtualenv
|
||||
# Source version must exist before creating virtualenv.
|
||||
pyenv-prefix 1>/dev/null 2>&1 || usage 1
|
||||
|
||||
if [ -z "$TMPDIR" ]; then
|
||||
@@ -328,12 +328,12 @@ else
|
||||
fi
|
||||
fi
|
||||
|
||||
# Unset environment variables which starts with `VIRTUALENV_`.
|
||||
# Unset environment variables which start with `VIRTUALENV_`.
|
||||
# These variables are reserved for virtualenv.
|
||||
unset VIRTUALENV_VERSION
|
||||
|
||||
|
||||
# Download specified version of ez_setup.py/get-pip.py
|
||||
# Download specified version of ez_setup.py/get-pip.py.
|
||||
if [ -n "${SETUPTOOLS_VERSION}" ]; then
|
||||
EZ_SETUP_URL="https://bitbucket.org/pypa/setuptools/raw/${SETUPTOOLS_VERSION}/ez_setup.py"
|
||||
fi
|
||||
@@ -396,19 +396,19 @@ trap cleanup SIGINT
|
||||
|
||||
# Invoke virtualenv and record exit status in $STATUS.
|
||||
STATUS=0
|
||||
# virtualenv may download distribute/setuptools in current directory.
|
||||
# change to cache directory to reuse them between invocation.
|
||||
# virtualenv may download distribute/setuptools into the current directory.
|
||||
# Change to cache directory to reuse them between invocations.
|
||||
mkdir -p "${PYENV_VIRTUALENV_CACHE_PATH}"
|
||||
cd "${PYENV_VIRTUALENV_CACHE_PATH}"
|
||||
venv $QUIET $VERBOSE "${VIRTUALENV_OPTIONS[@]}" "${VIRTUALENV_PATH}" || STATUS="$?"
|
||||
|
||||
## Install setuptools and pip
|
||||
## Install setuptools and pip.
|
||||
PYENV_VERSION="${VIRTUALENV_NAME}" build_package_ensurepip
|
||||
|
||||
## Migrate previously installed packages from requirements.txt
|
||||
## Migrate previously installed packages from requirements.txt.
|
||||
PYENV_VERSION="${VIRTUALENV_NAME}" install_requirements || true
|
||||
|
||||
# Execute `after_virtualenv` hooks
|
||||
# Execute `after_virtualenv` hooks.
|
||||
for hook in "${after_hooks[@]}"; do eval "$hook"; done
|
||||
|
||||
# Run `pyenv-rehash` after a successful installation.
|
||||
|
||||
@@ -18,7 +18,7 @@ do
|
||||
fi
|
||||
done
|
||||
|
||||
shell="$1"
|
||||
shell="${1:-$PYENV_SHELL}"
|
||||
if [ -z "$shell" ]; then
|
||||
shell="$(ps c -p "$PPID" -o 'ucomm=' 2>/dev/null || true)"
|
||||
shell="${shell##-}"
|
||||
@@ -92,7 +92,7 @@ function _pyenv_virtualenv_hook --on-event fish_prompt;
|
||||
end
|
||||
else
|
||||
if [ -z "\$VIRTUAL_ENV" ]; and [ "\$PYENV_DEACTIVATE" != "\$PYENV_PREFIX" ]
|
||||
pyenv activate --no-error --verbose
|
||||
pyenv activate --no-error --verbose; or true
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -128,7 +128,7 @@ if [[ "$shell" != "fish" ]]; then
|
||||
fi
|
||||
else
|
||||
if [ -z "\$VIRTUAL_ENV" ] && [ "\$PYENV_DEACTIVATE" != "\$(pyenv prefix 2>/dev/null || true)" ]; then
|
||||
pyenv activate --no-error --verbose
|
||||
pyenv activate --no-error --verbose || true
|
||||
fi
|
||||
fi
|
||||
};
|
||||
@@ -144,7 +144,7 @@ EOS
|
||||
;;
|
||||
zsh )
|
||||
cat <<EOS
|
||||
typeset -a precmd_functions
|
||||
typeset -g -a precmd_functions
|
||||
if [[ -z \$precmd_functions[(r)_pyenv_virtualenv_hook] ]]; then
|
||||
precmd_functions+=_pyenv_virtualenv_hook;
|
||||
fi
|
||||
|
||||
@@ -65,6 +65,11 @@ EOS
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
# Load pyenv-virtualenv automatically by adding
|
||||
# the following to ~/.bash_profile:
|
||||
|
||||
eval "\$(pyenv virtualenv-init -)"
|
||||
|
||||
pyenv shell "venv";
|
||||
export PYENV_ACTIVATE_SHELL=1;
|
||||
unset PYENV_DEACTIVATE;
|
||||
@@ -109,6 +114,11 @@ EOS
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
# Load pyenv-virtualenv automatically by adding
|
||||
# the following to ~/.config/fish/config.fish:
|
||||
|
||||
status --is-interactive; and . (pyenv virtualenv-init -|psub)
|
||||
|
||||
pyenv shell "venv";
|
||||
setenv PYENV_ACTIVATE_SHELL 1;
|
||||
set -e PYENV_DEACTIVATE;
|
||||
@@ -151,6 +161,11 @@ EOS
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
# Load pyenv-virtualenv automatically by adding
|
||||
# the following to ~/.bash_profile:
|
||||
|
||||
eval "\$(pyenv virtualenv-init -)"
|
||||
|
||||
pyenv shell "venv27";
|
||||
export PYENV_ACTIVATE_SHELL=1;
|
||||
unset PYENV_DEACTIVATE;
|
||||
@@ -193,6 +208,11 @@ EOS
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
# Load pyenv-virtualenv automatically by adding
|
||||
# the following to ~/.config/fish/config.fish:
|
||||
|
||||
status --is-interactive; and . (pyenv virtualenv-init -|psub)
|
||||
|
||||
pyenv shell "venv27";
|
||||
setenv PYENV_ACTIVATE_SHELL 1;
|
||||
set -e PYENV_DEACTIVATE;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
load test_helper
|
||||
|
||||
@test "detect parent shell" {
|
||||
unset PYENV_SHELL
|
||||
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
|
||||
SHELL=/bin/false run pyenv-virtualenv-init -
|
||||
assert_success
|
||||
@@ -47,7 +48,7 @@ _pyenv_virtualenv_hook() {
|
||||
fi
|
||||
else
|
||||
if [ -z "\$VIRTUAL_ENV" ] && [ "\$PYENV_DEACTIVATE" != "\$(pyenv prefix 2>/dev/null || true)" ]; then
|
||||
pyenv activate --no-error --verbose
|
||||
pyenv activate --no-error --verbose || true
|
||||
fi
|
||||
fi
|
||||
};
|
||||
@@ -80,7 +81,7 @@ function _pyenv_virtualenv_hook --on-event fish_prompt;
|
||||
end
|
||||
else
|
||||
if [ -z "\$VIRTUAL_ENV" ]; and [ "\$PYENV_DEACTIVATE" != "\$PYENV_PREFIX" ]
|
||||
pyenv activate --no-error --verbose
|
||||
pyenv activate --no-error --verbose; or true
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -109,11 +110,11 @@ _pyenv_virtualenv_hook() {
|
||||
fi
|
||||
else
|
||||
if [ -z "\$VIRTUAL_ENV" ] && [ "\$PYENV_DEACTIVATE" != "\$(pyenv prefix 2>/dev/null || true)" ]; then
|
||||
pyenv activate --no-error --verbose
|
||||
pyenv activate --no-error --verbose || true
|
||||
fi
|
||||
fi
|
||||
};
|
||||
typeset -a precmd_functions
|
||||
typeset -g -a precmd_functions
|
||||
if [[ -z \$precmd_functions[(r)_pyenv_virtualenv_hook] ]]; then
|
||||
precmd_functions+=_pyenv_virtualenv_hook;
|
||||
fi
|
||||
|
||||
@@ -4,7 +4,7 @@ load test_helper
|
||||
|
||||
setup() {
|
||||
export PYENV_ROOT="${TMP}/pyenv"
|
||||
export PYENV_VIRTUALENV_VERSION="20150119"
|
||||
export PYENV_VIRTUALENV_VERSION="20150526"
|
||||
}
|
||||
|
||||
@test "display virtualenv version" {
|
||||
|
||||
Reference in New Issue
Block a user