pyenv.pyenv/libexec/pyenv-exec
Michał 63548e129f
fix libexec/pyenv-exec
Make sure the $LD_LIBRARY_PATH does not have a trailing colon.

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
2026-09-07 19:25:58 +02:00

71 lines
1.9 KiB
Bash
Executable file

#!/usr/bin/env bash
#
# Summary: Run an executable with the selected Python version
#
# Usage: pyenv exec [-E|--environment] <command> [arg1 arg2...]
#
# -E Modify Python runtime environment, such as $PYTHONHOME, for the called executable.
#
# 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 -r requirements.txt
#
# is equivalent to:
# PATH="$PYENV_ROOT/versions/2.7.6/bin:$PATH" pip install -r requirements.txt
set -e
[ -n "$PYENV_DEBUG" ] && set -x
# Provide pyenv completions
if [ "$1" = "--complete" ]; then
echo --environment
exec pyenv-shims --short
fi
unset MODIFY_ENV
if [ "$1" = "-E" ] || [ "$1" = "--environment" ]; then
MODIFY_ENV=true
shift
fi
PYENV_VERSION="$(pyenv-version-name -f)"
PYENV_COMMAND="$1"
if [ -z "$PYENV_COMMAND" ]; then
pyenv-help --usage exec >&2
exit 1
fi
if [[ -n $_PYENV_SHIM_PATH ]]; then
PROGRAM="$(echo "$PYENV_COMMAND" | tr a-z- A-Z_ | sed 's/[^A-Z0-9_]/_/g')"
NR_PYENV_SHIM_PATHS_PROGRAM="_PYENV_SHIM_PATHS_${PROGRAM}"
export -- "$NR_PYENV_SHIM_PATHS_PROGRAM=$_PYENV_SHIM_PATH${!NR_PYENV_SHIM_PATHS_PROGRAM:+:${!NR_PYENV_SHIM_PATHS_PROGRAM}}"
unset PROGRAM NR_PYENV_SHIM_PATHS_PROGRAM
unset _PYENV_SHIM_PATH
fi
PYENV_COMMAND_PATH="$(pyenv-which "$PYENV_COMMAND")"
PYENV_BIN_PATH="${PYENV_COMMAND_PATH%/*}"
export PYENV_VERSION
OLDIFS="$IFS"
IFS=$'\n' scripts=(`pyenv-hooks exec`)
IFS="$OLDIFS"
for script in "${scripts[@]}"; do
source "$script"
done
shift 1
if [ "${PYENV_BIN_PATH#${PYENV_ROOT}}" != "${PYENV_BIN_PATH}" ]; then
# Only add to $PATH for non-system version.
export PATH="${PYENV_BIN_PATH}:${PATH}"
fi
if [ -n "$MODIFY_ENV" ]; then
export PYTHONHOME="$(pyenv-prefix)"
export LD_LIBRARY_PATH="${PYTHONHOME}/lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"
fi
exec "$PYENV_COMMAND_PATH" "$@"