pyenv/libexec/pyenv-exec
Casey McGinty 83e5459cfb Remove shebang lines from scripts for performance
All scripts in libexec/ (excluding pyenv) are called through pyenv,
therefore the shebang lines are not necessary. On some systems this
provides a measurable increase in performance of the shell prompt.

Related to pyenv/pyenv-virtualenv#259
2019-03-07 22:15:14 +01:00

45 lines
1.2 KiB
Text
Executable file

# 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.
#
# For example, if the currently selected Python version is 2.7.6:
# pyenv exec pip install -rrequirements.txt
#
# is equivalent to:
# PATH="$PYENV_ROOT/versions/2.7.6/bin:$PATH" pip install -rrequirements.txt
set -e
[ -n "$PYENV_DEBUG" ] && set -x
# Provide pyenv completions
if [ "$1" = "--complete" ]; then
exec pyenv-shims --short
fi
PYENV_VERSION="$(pyenv-version-name)"
PYENV_COMMAND="$1"
if [ -z "$PYENV_COMMAND" ]; then
pyenv-help --usage exec >&2
exit 1
fi
export PYENV_VERSION
PYENV_COMMAND_PATH="$(pyenv-which "$PYENV_COMMAND")"
PYENV_BIN_PATH="${PYENV_COMMAND_PATH%/*}"
OLDIFS="$IFS"
IFS=$'\n' scripts=(`pyenv-hooks exec`)
IFS="$OLDIFS"
for script in "${scripts[@]}"; do
source "$script"
done
shift 1
# CPython's `sys.executable` requires the `PYENV_BIN_PATH` to be at the top of the `PATH`.
# https://github.com/pyenv/pyenv/issues/98
export PATH="${PYENV_BIN_PATH}:${PATH}"
exec -a "$PYENV_COMMAND" "$PYENV_COMMAND_PATH" "$@"