2012-08-31 02:23:41 -04:00
|
|
|
#!/usr/bin/env bash
|
2013-01-18 03:41:41 -05:00
|
|
|
#
|
|
|
|
# Summary: Run an executable with the selected Python version
|
|
|
|
#
|
|
|
|
# Usage: pyenv exec <command> [arg1 arg2...]
|
|
|
|
#
|
|
|
|
# Runs an executable by first preparing PATH so that the selected Python
|
|
|
|
# version's `bin' directory is at the front.
|
|
|
|
#
|
2014-01-02 08:26:22 -05:00
|
|
|
# For example, if the currently selected Python version is 2.7.6:
|
2013-01-18 03:41:41 -05:00
|
|
|
# pyenv exec pip install -rrequirements.txt
|
|
|
|
#
|
|
|
|
# is equivalent to:
|
2014-01-02 08:26:22 -05:00
|
|
|
# PATH="$PYENV_ROOT/versions/2.7.6/bin:$PATH" pip install -rrequirements.txt
|
2013-01-18 03:41:41 -05:00
|
|
|
|
2012-08-31 02:23:41 -04:00
|
|
|
set -e
|
|
|
|
[ -n "$PYENV_DEBUG" ] && set -x
|
|
|
|
|
|
|
|
# Provide pyenv completions
|
|
|
|
if [ "$1" = "--complete" ]; then
|
2014-11-30 10:20:53 -05:00
|
|
|
exec pyenv-shims --short
|
2012-08-31 02:23:41 -04:00
|
|
|
fi
|
|
|
|
|
2014-01-02 08:26:22 -05:00
|
|
|
PYENV_VERSION="$(pyenv-version-name)"
|
2012-08-31 02:23:41 -04:00
|
|
|
PYENV_COMMAND="$1"
|
2013-01-18 03:41:41 -05:00
|
|
|
|
2012-08-31 02:23:41 -04:00
|
|
|
if [ -z "$PYENV_COMMAND" ]; then
|
2013-01-18 03:41:41 -05:00
|
|
|
pyenv-help --usage exec >&2
|
2012-08-31 02:23:41 -04:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-01-02 08:26:22 -05:00
|
|
|
export PYENV_VERSION
|
2012-08-31 02:23:41 -04:00
|
|
|
PYENV_COMMAND_PATH="$(pyenv-which "$PYENV_COMMAND")"
|
|
|
|
PYENV_BIN_PATH="${PYENV_COMMAND_PATH%/*}"
|
|
|
|
|
2014-01-02 08:26:22 -05:00
|
|
|
OLDIFS="$IFS"
|
2014-01-02 08:49:23 -05:00
|
|
|
IFS=$'\n' scripts=(`pyenv-hooks exec`)
|
2014-01-02 08:26:22 -05:00
|
|
|
IFS="$OLDIFS"
|
|
|
|
for script in "${scripts[@]}"; do
|
2012-08-31 02:23:41 -04:00
|
|
|
source "$script"
|
|
|
|
done
|
|
|
|
|
|
|
|
shift 1
|
2014-01-09 19:07:49 -05:00
|
|
|
# CPython's `sys.executable` requires the `PYENV_BIN_PATH` to be at the top of the `PATH`.
|
|
|
|
# https://github.com/yyuu/pyenv/issues/98
|
|
|
|
export PATH="${PYENV_BIN_PATH}:${PATH}"
|
2012-08-31 02:23:41 -04:00
|
|
|
exec -a "$PYENV_COMMAND" "$PYENV_COMMAND_PATH" "$@"
|