22 Commits

Author SHA1 Message Date
Yamashita Yuu
9a52f9fb5d v20150526
First release after my son's birth....
2015-05-27 00:01:13 +09:00
Yamashita, Yuu
0ca01826e8 Merge pull request #78 from blueyed/shell-no-note-if-init
activate: do not display note if initialized already
2015-05-17 12:23:37 +09:00
Yamashita, Yuu
4fa9c7b220 Merge pull request #75 from blueyed/fix-zsh-typeset-precmd_functions
Use `typeset -g` with `precmd_functions`
2015-05-17 12:12:12 +09:00
Daniel Hahler
2571a2b973 activate: display setup instructions only with PYENV_VIRTUALENV_INIT=0
This fixes displaying the note, in case "init" has been run manually
and/or the init is not in the expected place.

It removes the unnecessary calls to "grep".

pyenv-virtualenv-init will look at `$PYENV_SHELL` now, too.

Tests have been adjusted/fixed.
2015-05-10 17:47:46 +02:00
Daniel Hahler
95fa7a35ad shell: do not use basename, but bash 2015-05-10 17:36:03 +02:00
Yamashita, Yuu
47cd86a165 Merge pull request #74 from blueyed/help-version-is-optional
Usage: version is optional
2015-04-28 17:19:46 +09:00
Yamashita, Yuu
d9c3f9a2f5 Merge pull request #73 from blueyed/fix-comments
minor: fix comments
2015-04-28 17:19:10 +09:00
Daniel Hahler
6bc0253d17 minor: fix comments 2015-04-28 10:17:02 +02:00
Daniel Hahler
c184c01174 Usage: version is optional 2015-04-28 10:13:59 +02:00
Yamashita, Yuu
55189357e2 Merge pull request #72 from sfilipov/patch-1
Link to English venv documentation
2015-04-24 10:15:15 +09:00
Simeon Filipov
9544c8b178 Link to English venv documentation
Currently the link to venv points to the Japanese version of the Python documentation.
Change this link to the English version of the Python documentation.
2015-04-24 01:51:15 +01:00
Yamashita, Yuu
bcb7abdf93 Merge pull request #68 from jawshooah/ignore-error-code
Ignore failure of pyenv activate
2015-03-19 12:18:19 +09:00
Josh Hagins
5953ddaf64 Ignore failure of pyenv activate
When the current pyenv environment is not a virtualenv, this line
exits with a return code of 1. This is annoying for those of us
who report the last return code in our own PROMPT_COMMAND, so
ignore the output of `pyenv activate` if we're not currently using
a virtualenv.
2015-03-18 22:30:19 -04:00
Daniel Hahler
2ab9483116 Use typeset -g with precmd_functions
This makes it possible to use `eval "$(pyenv virtualenv-init -)"` from a
function.
2015-03-14 02:37:14 +01:00
Yamashita Yuu
32e5a73345 v20150119 2015-01-19 00:53:19 +09:00
Yamashita Yuu
0fc9441f09 Anaconda has activate script nevertheless it is not a virtual environment (#65) 2015-01-18 20:15:44 +09:00
Yamashita, Yuu
0fe9aef635 Merge pull request #64 from wwwjfy/master
fix wrong output in test in fish, refs 240a1de
2015-01-06 14:05:52 +09:00
Tony Wang
e04a6f88fe fix wrong output in test in fish, refs 240a1de
"(any command)" is not supported in test in fish, we have to set a
variable and then use that
2015-01-06 11:10:43 +08:00
Yamashita, Yuu
08c2e6aee4 Merge pull request #63 from wwwjfy/master
fix warns for virtualenv-init corner case on fish
2015-01-06 10:20:53 +09:00
Tony Wang
cc7c9d22b5 fix failed tests running under fish 2015-01-05 23:28:14 +08:00
Tony Wang
240a1de6e5 fix warns for virtualenv-init corner case on fish
The situation is when in a directory containing python binary,
`pyenv prefix' will return empty (caused by `pyenv which' returning
"./python"). This change adds quotes for `test', otherwise `test' will
warn about missing argument.
2015-01-05 23:23:43 +08:00
Yamashita Yuu
9d71e67401 Merge branch 'issue61' 2014-12-28 18:50:25 +09:00
8 changed files with 121 additions and 55 deletions

View File

@@ -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,18 @@ 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)
* The _shell_ version set in `activate` should be unset in `deactivate` (#61)
* Anaconda has `activate` script nevertheless it is not a virtual environment (#65)
#### 20141106
* Stop creating after `ensurepip` since it has done by `ensurepip` itself

View File

@@ -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

View File

@@ -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="20141106"
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.

View File

@@ -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##-}"
@@ -75,13 +75,14 @@ case "$shell" in
fish )
cat <<EOS
function _pyenv_virtualenv_hook --on-event fish_prompt;
set -l PYENV_PREFIX (pyenv prefix 2>/dev/null; or true)
if [ -n "\$PYENV_ACTIVATE" ]
if [ (pyenv version-name 2>/dev/null; or true) = "system" ]
if [ "(pyenv version-name 2>/dev/null; or true)" = "system" ]
pyenv deactivate --no-error --verbose
set -e PYENV_DEACTIVATE
return 0
end
if [ "\$PYENV_ACTIVATE" != (pyenv prefix 2>/dev/null; or true) ]
if [ "\$PYENV_ACTIVATE" != "\$PYENV_PREFIX" ]
if pyenv deactivate --no-error --verbose
set -e PYENV_DEACTIVATE
pyenv activate --no-error --verbose; or set -e PYENV_DEACTIVATE
@@ -90,8 +91,8 @@ function _pyenv_virtualenv_hook --on-event fish_prompt;
end
end
else
if [ -z "\$VIRTUAL_ENV" ]; and [ "\$PYENV_DEACTIVATE" != (pyenv prefix 2>/dev/null; or true) ]
pyenv activate --no-error --verbose
if [ -z "\$VIRTUAL_ENV" ]; and [ "\$PYENV_DEACTIVATE" != "\$PYENV_PREFIX" ]
pyenv activate --no-error --verbose; or true
end
end
end
@@ -127,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
};
@@ -143,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

View File

@@ -38,8 +38,14 @@ for version in "${versions[@]}"; do
fi
PREFIX="$(pyenv-prefix "${version}")"
if [ -f "${PREFIX}/bin/activate" ]; then
VIRTUALENV_PREFIX_PATH="$(real_prefix "${version}" || base_prefix "${version}" || true)"
VIRTUALENV_PREFIX_PATHS=("${VIRTUALENV_PREFIX_PATHS[@]}" "$VIRTUALENV_PREFIX_PATH")
# Anaconda has `activate` script nevertheless it is not a virtual environment (#65)
if [ -f "${PREFIX}/bin/conda" ]; then
echo "pyenv-virtualenv: version \`${version}' is an anaconda/miniconda" 1>&2
exit 1
else
VIRTUALENV_PREFIX_PATH="$(real_prefix "${version}" || base_prefix "${version}" || true)"
VIRTUALENV_PREFIX_PATHS=("${VIRTUALENV_PREFIX_PATHS[@]}" "$VIRTUALENV_PREFIX_PATH")
fi
else
echo "pyenv-virtualenv: version \`${version}' is not a virtualenv" 1>&2
exit 1

View File

@@ -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;
@@ -123,7 +133,7 @@ EOS
stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
run pyenv-sh-activate "venv27"
PYENV_SHELL="bash" PYENV_VERSION="venv" run pyenv-sh-activate "venv27"
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
@@ -144,7 +154,33 @@ EOS
stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
run pyenv-sh-activate "venv27"
PYENV_SHELL="bash" PYENV_VERSION="venv" run pyenv-sh-activate "venv27"
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
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;
export PYENV_ACTIVATE="${PYENV_ROOT}/versions/venv27";
. "${PYENV_ROOT}/versions/venv27/bin/activate";
EOS
}
@test "activate virtualenv from command-line argument (fish)" {
export PYENV_VIRTUALENV_INIT=1
stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
PYENV_SHELL="fish" PYENV_VERSION="venv" run pyenv-sh-activate "venv27"
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
@@ -152,10 +188,36 @@ EOS
assert_success
assert_output <<EOS
pyenv shell "venv27";
export PYENV_ACTIVATE_SHELL=1;
unset PYENV_DEACTIVATE;
export PYENV_ACTIVATE="${PYENV_ROOT}/versions/venv27";
. "${PYENV_ROOT}/versions/venv27/bin/activate";
setenv PYENV_ACTIVATE_SHELL 1;
set -e PYENV_DEACTIVATE;
setenv PYENV_ACTIVATE "${PYENV_ROOT}/versions/venv27";
. "${PYENV_ROOT}/versions/venv27/bin/activate.fish";
EOS
}
@test "activate virtualenv from command-line argument (fish) (without pyenv-virtualenv-init)" {
export PYENV_VIRTUALENV_INIT=
stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
PYENV_SHELL="fish" PYENV_VERSION="venv" run pyenv-sh-activate "venv27"
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
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;
setenv PYENV_ACTIVATE "${PYENV_ROOT}/versions/venv27";
. "${PYENV_ROOT}/versions/venv27/bin/activate.fish";
EOS
}

View File

@@ -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
};
@@ -63,13 +64,14 @@ EOS
assert_output <<EOS
setenv PYENV_VIRTUALENV_INIT 1;
function _pyenv_virtualenv_hook --on-event fish_prompt;
set -l PYENV_PREFIX (pyenv prefix 2>/dev/null; or true)
if [ -n "\$PYENV_ACTIVATE" ]
if [ (pyenv version-name 2>/dev/null; or true) = "system" ]
if [ "(pyenv version-name 2>/dev/null; or true)" = "system" ]
pyenv deactivate --no-error --verbose
set -e PYENV_DEACTIVATE
return 0
end
if [ "\$PYENV_ACTIVATE" != (pyenv prefix 2>/dev/null; or true) ]
if [ "\$PYENV_ACTIVATE" != "\$PYENV_PREFIX" ]
if pyenv deactivate --no-error --verbose
set -e PYENV_DEACTIVATE
pyenv activate --no-error --verbose; or set -e PYENV_DEACTIVATE
@@ -78,8 +80,8 @@ function _pyenv_virtualenv_hook --on-event fish_prompt;
end
end
else
if [ -z "\$VIRTUAL_ENV" ]; and [ "\$PYENV_DEACTIVATE" != (pyenv prefix 2>/dev/null; or true) ]
pyenv activate --no-error --verbose
if [ -z "\$VIRTUAL_ENV" ]; and [ "\$PYENV_DEACTIVATE" != "\$PYENV_PREFIX" ]
pyenv activate --no-error --verbose; or true
end
end
end
@@ -108,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

View File

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