14 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
7 changed files with 51 additions and 41 deletions

View File

@@ -126,10 +126,9 @@ Removing the directory in `~/.pyenv/versions` will delete the virtualenv, or you
pyenv uninstall my-virtual-env pyenv uninstall my-virtual-env
### virtualenv and pyvenv ### 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. for CPython 3.3 and newer.
It provides a command-line tool `pyvenv` which is the successor of `virtualenv` It provides a command-line tool `pyvenv` which is the successor of `virtualenv`
and distributed by default. and distributed by default.
@@ -157,6 +156,12 @@ You can set certain environment variables to control pyenv-virtualenv.
## Version History ## 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 #### 20150119
* Ignore errors from `pyenv-version-name` since it might fail if there is configuration error (yyuu/pyenv#291) * Ignore errors from `pyenv-version-name` since it might fail if there is configuration error (yyuu/pyenv#291)

View File

@@ -68,27 +68,11 @@ if ! pyenv-virtualenv-prefix "${versions}" 1>/dev/null 2>&1; then
exit 1 exit 1
fi fi
shell="$(basename "${PYENV_SHELL:-$SHELL}")" shell="${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
# Display setup instruction if 'pyenv virtualenv-init -' is not found in "$profile" # Display setup instruction, if pyenv-virtualenv has not been initialized.
if [ -f "$profile" ] && grep -q 'pyenv init -' "$profile" && ! grep -q 'pyenv virtualenv-init -' "$profile"; then # if 'pyenv virtualenv-init -' is not found in "$profile"
if [ -z "$PYENV_VIRTUALENV_INIT" ]; then
pyenv-virtualenv-init >&2 || true pyenv-virtualenv-init >&2 || true
fi fi

View File

@@ -2,14 +2,14 @@
# #
# Summary: Create a Python virtualenv using the pyenv-virtualenv plugin # 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 --version
# pyenv virtualenv --help # pyenv virtualenv --help
# #
# -f/--force Install even if the version appears to be installed already # -f/--force Install even if the version appears to be installed already
# #
PYENV_VIRTUALENV_VERSION="20150119" PYENV_VIRTUALENV_VERSION="20150526"
set -e set -e
[ -n "$PYENV_DEBUG" ] && set -x [ -n "$PYENV_DEBUG" ] && set -x
@@ -283,7 +283,7 @@ fi
# Set VERSION_NAME as default version in this script # Set VERSION_NAME as default version in this script
export PYENV_VERSION="${VERSION_NAME}" 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 pyenv-prefix 1>/dev/null 2>&1 || usage 1
if [ -z "$TMPDIR" ]; then if [ -z "$TMPDIR" ]; then
@@ -328,12 +328,12 @@ else
fi fi
fi fi
# Unset environment variables which starts with `VIRTUALENV_`. # Unset environment variables which start with `VIRTUALENV_`.
# These variables are reserved for virtualenv. # These variables are reserved for virtualenv.
unset VIRTUALENV_VERSION 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 if [ -n "${SETUPTOOLS_VERSION}" ]; then
EZ_SETUP_URL="https://bitbucket.org/pypa/setuptools/raw/${SETUPTOOLS_VERSION}/ez_setup.py" EZ_SETUP_URL="https://bitbucket.org/pypa/setuptools/raw/${SETUPTOOLS_VERSION}/ez_setup.py"
fi fi
@@ -396,19 +396,19 @@ trap cleanup SIGINT
# Invoke virtualenv and record exit status in $STATUS. # Invoke virtualenv and record exit status in $STATUS.
STATUS=0 STATUS=0
# virtualenv may download distribute/setuptools in current directory. # virtualenv may download distribute/setuptools into the current directory.
# change to cache directory to reuse them between invocation. # Change to cache directory to reuse them between invocations.
mkdir -p "${PYENV_VIRTUALENV_CACHE_PATH}" mkdir -p "${PYENV_VIRTUALENV_CACHE_PATH}"
cd "${PYENV_VIRTUALENV_CACHE_PATH}" cd "${PYENV_VIRTUALENV_CACHE_PATH}"
venv $QUIET $VERBOSE "${VIRTUALENV_OPTIONS[@]}" "${VIRTUALENV_PATH}" || STATUS="$?" venv $QUIET $VERBOSE "${VIRTUALENV_OPTIONS[@]}" "${VIRTUALENV_PATH}" || STATUS="$?"
## Install setuptools and pip ## Install setuptools and pip.
PYENV_VERSION="${VIRTUALENV_NAME}" build_package_ensurepip 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 PYENV_VERSION="${VIRTUALENV_NAME}" install_requirements || true
# Execute `after_virtualenv` hooks # Execute `after_virtualenv` hooks.
for hook in "${after_hooks[@]}"; do eval "$hook"; done for hook in "${after_hooks[@]}"; do eval "$hook"; done
# Run `pyenv-rehash` after a successful installation. # Run `pyenv-rehash` after a successful installation.

View File

@@ -18,7 +18,7 @@ do
fi fi
done done
shell="$1" shell="${1:-$PYENV_SHELL}"
if [ -z "$shell" ]; then if [ -z "$shell" ]; then
shell="$(ps c -p "$PPID" -o 'ucomm=' 2>/dev/null || true)" shell="$(ps c -p "$PPID" -o 'ucomm=' 2>/dev/null || true)"
shell="${shell##-}" shell="${shell##-}"
@@ -92,7 +92,7 @@ function _pyenv_virtualenv_hook --on-event fish_prompt;
end end
else else
if [ -z "\$VIRTUAL_ENV" ]; and [ "\$PYENV_DEACTIVATE" != "\$PYENV_PREFIX" ] if [ -z "\$VIRTUAL_ENV" ]; and [ "\$PYENV_DEACTIVATE" != "\$PYENV_PREFIX" ]
pyenv activate --no-error --verbose pyenv activate --no-error --verbose; or true
end end
end end
end end
@@ -128,7 +128,7 @@ if [[ "$shell" != "fish" ]]; then
fi fi
else else
if [ -z "\$VIRTUAL_ENV" ] && [ "\$PYENV_DEACTIVATE" != "\$(pyenv prefix 2>/dev/null || true)" ]; then 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
fi fi
}; };
@@ -144,7 +144,7 @@ EOS
;; ;;
zsh ) zsh )
cat <<EOS cat <<EOS
typeset -a precmd_functions typeset -g -a precmd_functions
if [[ -z \$precmd_functions[(r)_pyenv_virtualenv_hook] ]]; then if [[ -z \$precmd_functions[(r)_pyenv_virtualenv_hook] ]]; then
precmd_functions+=_pyenv_virtualenv_hook; precmd_functions+=_pyenv_virtualenv_hook;
fi fi

View File

@@ -65,6 +65,11 @@ EOS
assert_success assert_success
assert_output <<EOS assert_output <<EOS
# Load pyenv-virtualenv automatically by adding
# the following to ~/.bash_profile:
eval "\$(pyenv virtualenv-init -)"
pyenv shell "venv"; pyenv shell "venv";
export PYENV_ACTIVATE_SHELL=1; export PYENV_ACTIVATE_SHELL=1;
unset PYENV_DEACTIVATE; unset PYENV_DEACTIVATE;
@@ -109,6 +114,11 @@ EOS
assert_success assert_success
assert_output <<EOS 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"; pyenv shell "venv";
setenv PYENV_ACTIVATE_SHELL 1; setenv PYENV_ACTIVATE_SHELL 1;
set -e PYENV_DEACTIVATE; set -e PYENV_DEACTIVATE;
@@ -151,6 +161,11 @@ EOS
assert_success assert_success
assert_output <<EOS assert_output <<EOS
# Load pyenv-virtualenv automatically by adding
# the following to ~/.bash_profile:
eval "\$(pyenv virtualenv-init -)"
pyenv shell "venv27"; pyenv shell "venv27";
export PYENV_ACTIVATE_SHELL=1; export PYENV_ACTIVATE_SHELL=1;
unset PYENV_DEACTIVATE; unset PYENV_DEACTIVATE;
@@ -193,6 +208,11 @@ EOS
assert_success assert_success
assert_output <<EOS 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"; pyenv shell "venv27";
setenv PYENV_ACTIVATE_SHELL 1; setenv PYENV_ACTIVATE_SHELL 1;
set -e PYENV_DEACTIVATE; set -e PYENV_DEACTIVATE;

View File

@@ -3,6 +3,7 @@
load test_helper load test_helper
@test "detect parent shell" { @test "detect parent shell" {
unset PYENV_SHELL
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
SHELL=/bin/false run pyenv-virtualenv-init - SHELL=/bin/false run pyenv-virtualenv-init -
assert_success assert_success
@@ -47,7 +48,7 @@ _pyenv_virtualenv_hook() {
fi fi
else else
if [ -z "\$VIRTUAL_ENV" ] && [ "\$PYENV_DEACTIVATE" != "\$(pyenv prefix 2>/dev/null || true)" ]; then 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
fi fi
}; };
@@ -80,7 +81,7 @@ function _pyenv_virtualenv_hook --on-event fish_prompt;
end end
else else
if [ -z "\$VIRTUAL_ENV" ]; and [ "\$PYENV_DEACTIVATE" != "\$PYENV_PREFIX" ] if [ -z "\$VIRTUAL_ENV" ]; and [ "\$PYENV_DEACTIVATE" != "\$PYENV_PREFIX" ]
pyenv activate --no-error --verbose pyenv activate --no-error --verbose; or true
end end
end end
end end
@@ -109,11 +110,11 @@ _pyenv_virtualenv_hook() {
fi fi
else else
if [ -z "\$VIRTUAL_ENV" ] && [ "\$PYENV_DEACTIVATE" != "\$(pyenv prefix 2>/dev/null || true)" ]; then 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
fi fi
}; };
typeset -a precmd_functions typeset -g -a precmd_functions
if [[ -z \$precmd_functions[(r)_pyenv_virtualenv_hook] ]]; then if [[ -z \$precmd_functions[(r)_pyenv_virtualenv_hook] ]]; then
precmd_functions+=_pyenv_virtualenv_hook; precmd_functions+=_pyenv_virtualenv_hook;
fi fi

View File

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