Merge pull request #108 from yyuu/hook-source-activate

dd a script to hook `source activate` for Anaconda/Miniconda
This commit is contained in:
Yamashita, Yuu
2015-11-06 17:15:12 +09:00
5 changed files with 51 additions and 2 deletions

View File

@@ -9,6 +9,26 @@
set -e set -e
[ -n "$PYENV_DEBUG" ] && set -x [ -n "$PYENV_DEBUG" ] && set -x
resolve_link() {
$(type -p greadlink readlink | head -1) "$1"
}
abs_dirname() {
local cwd="$(pwd)"
local path="$1"
while [ -n "$path" ]; do
cd "${path%/*}"
local name="${path##*/}"
path="$(resolve_link "$name" || true)"
done
pwd
cd "$cwd"
}
PYENV_VIRTUALENV_INSTALL_PREFIX="$(dirname "$(abs_dirname "$0")")"
print="" print=""
for args in "$@" for args in "$@"
do do
@@ -65,10 +85,16 @@ fi
case "$shell" in case "$shell" in
fish ) fish )
echo "setenv PYENV_VIRTUALENV_INIT 1;" cat <<EOS
setenv PATH '${PYENV_VIRTUALENV_ROOT:-${PYENV_VIRTUALENV_INSTALL_PREFIX}}/shims' \$PATH;
setenv PYENV_VIRTUALENV_INIT 1;
EOS
;; ;;
* ) * )
echo "export PYENV_VIRTUALENV_INIT=1;" cat <<EOS
export PATH="${PYENV_VIRTUALENV_ROOT:-${PYENV_VIRTUALENV_INSTALL_PREFIX}}/shims:${PATH}";
export PYENV_VIRTUALENV_INIT=1;
EOS
;; ;;
esac esac

View File

@@ -12,7 +12,10 @@ if [ -z "${PREFIX}" ]; then
fi fi
BIN_PATH="${PREFIX}/bin" BIN_PATH="${PREFIX}/bin"
SHIMS_PATH="${PREFIX}/shims"
mkdir -p "$BIN_PATH" mkdir -p "$BIN_PATH"
mkdir -p "$SHIMS_PATH"
install -p bin/* "$BIN_PATH" install -p bin/* "$BIN_PATH"
install -p shims/* "$SHIMS_PATH"

7
shims/activate Executable file
View File

@@ -0,0 +1,7 @@
#!/usr/bin/env bash
if [[ "$0" != "${BASH_SOURCE}" ]]; then
eval "$(pyenv sh-activate --verbose "$@" || true)"
else
echo "pyenv-virtualenv: activate must be sourced. Run 'source activate envname' instead of 'activate envname'" 1>&2
false
fi

7
shims/deactivate Executable file
View File

@@ -0,0 +1,7 @@
#!/usr/bin/env bash
if [[ "$0" != "${BASH_SOURCE}" ]]; then
eval "$(pyenv sh-deactivate --verbose "$@" || true)"
else
echo "pyenv-virtualenv: deactivate must be sourced. Run 'source deactivate' instead of 'deactivate'" 1>&2
false
fi

View File

@@ -46,9 +46,11 @@ load test_helper
} }
@test "outputs bash-specific syntax" { @test "outputs bash-specific syntax" {
export PYENV_VIRTUALENV_ROOT="${TMP}/pyenv/plugins/pyenv-virtualenv"
run pyenv-virtualenv-init - bash run pyenv-virtualenv-init - bash
assert_success assert_success
assert_output <<EOS assert_output <<EOS
export PATH="${TMP}/pyenv/plugins/pyenv-virtualenv/shims:${PATH}";
export PYENV_VIRTUALENV_INIT=1; export PYENV_VIRTUALENV_INIT=1;
_pyenv_virtualenv_hook() { _pyenv_virtualenv_hook() {
local ret=\$? local ret=\$?
@@ -80,9 +82,11 @@ EOS
} }
@test "outputs fish-specific syntax" { @test "outputs fish-specific syntax" {
export PYENV_VIRTUALENV_ROOT="${TMP}/pyenv/plugins/pyenv-virtualenv"
run pyenv-virtualenv-init - fish run pyenv-virtualenv-init - fish
assert_success assert_success
assert_output <<EOS assert_output <<EOS
setenv PATH '${TMP}/pyenv/plugins/pyenv-virtualenv/shims' \$PATH;
setenv PYENV_VIRTUALENV_INIT 1; setenv PYENV_VIRTUALENV_INIT 1;
function _pyenv_virtualenv_hook --on-event fish_prompt; function _pyenv_virtualenv_hook --on-event fish_prompt;
set -l PYENV_PREFIX (pyenv prefix 2>/dev/null; or true) set -l PYENV_PREFIX (pyenv prefix 2>/dev/null; or true)
@@ -112,9 +116,11 @@ EOS
} }
@test "outputs zsh-specific syntax" { @test "outputs zsh-specific syntax" {
export PYENV_VIRTUALENV_ROOT="${TMP}/pyenv/plugins/pyenv-virtualenv"
run pyenv-virtualenv-init - zsh run pyenv-virtualenv-init - zsh
assert_success assert_success
assert_output <<EOS assert_output <<EOS
export PATH="${TMP}/pyenv/plugins/pyenv-virtualenv/shims:${PATH}";
export PYENV_VIRTUALENV_INIT=1; export PYENV_VIRTUALENV_INIT=1;
_pyenv_virtualenv_hook() { _pyenv_virtualenv_hook() {
local ret=\$? local ret=\$?