2019-04-23 10:23:33 -04:00
|
|
|
#!/usr/bin/env bash
|
2013-01-18 03:41:41 -05:00
|
|
|
# Summary: Show the current Python version
|
2012-08-31 02:23:41 -04:00
|
|
|
set -e
|
|
|
|
[ -n "$PYENV_DEBUG" ] && set -x
|
|
|
|
|
2014-01-02 08:26:22 -05:00
|
|
|
if [ -z "$PYENV_VERSION" ]; then
|
2012-08-31 02:23:41 -04:00
|
|
|
PYENV_VERSION_FILE="$(pyenv-version-file)"
|
2014-01-02 12:05:40 -05:00
|
|
|
PYENV_VERSION="$(pyenv-version-file-read "$PYENV_VERSION_FILE" || true)"
|
2012-08-31 02:23:41 -04:00
|
|
|
fi
|
|
|
|
|
2016-03-01 20:39:52 -05:00
|
|
|
OLDIFS="$IFS"
|
|
|
|
IFS=$'\n' scripts=(`pyenv-hooks version-name`)
|
|
|
|
IFS="$OLDIFS"
|
|
|
|
for script in "${scripts[@]}"; do
|
|
|
|
source "$script"
|
|
|
|
done
|
|
|
|
|
2014-01-02 12:05:40 -05:00
|
|
|
if [ -z "$PYENV_VERSION" ] || [ "$PYENV_VERSION" = "system" ]; then
|
2012-08-31 02:23:41 -04:00
|
|
|
echo "system"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2013-01-18 04:57:08 -05:00
|
|
|
version_exists() {
|
|
|
|
local version="$1"
|
2013-02-06 02:05:29 -05:00
|
|
|
[ -d "${PYENV_ROOT}/versions/${version}" ]
|
2013-01-18 04:57:08 -05:00
|
|
|
}
|
|
|
|
|
2014-01-02 12:05:40 -05:00
|
|
|
versions=()
|
|
|
|
OLDIFS="$IFS"
|
|
|
|
{ IFS=:
|
2014-12-11 12:47:09 -05:00
|
|
|
any_not_installed=0
|
2014-01-02 12:05:40 -05:00
|
|
|
for version in ${PYENV_VERSION}; do
|
2024-09-10 11:51:55 -04:00
|
|
|
# Remove the explicit 'python-' prefix from versions like 'python-3.12'.
|
|
|
|
normalised_version="${version#python-}"
|
|
|
|
if version_exists "${normalised_version}" || [ "$version" = "system" ]; then
|
|
|
|
versions=("${versions[@]}" "${normalised_version}")
|
|
|
|
elif resolved_version="$(pyenv-latest -b "${normalised_version}")"; then
|
2022-10-29 20:38:40 -04:00
|
|
|
versions=("${versions[@]}" "${resolved_version}")
|
2014-01-02 12:05:40 -05:00
|
|
|
else
|
2015-11-20 23:13:52 -05:00
|
|
|
echo "pyenv: version \`$version' is not installed (set by $(pyenv-version-origin))" >&2
|
2014-12-11 12:47:09 -05:00
|
|
|
any_not_installed=1
|
2014-01-02 12:05:40 -05:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
IFS="$OLDIFS"
|
2012-08-31 02:23:41 -04:00
|
|
|
|
2014-01-02 12:05:40 -05:00
|
|
|
OLDIFS="$IFS"
|
|
|
|
{ IFS=:
|
|
|
|
echo "${versions[*]}"
|
|
|
|
}
|
|
|
|
IFS="$OLDIFS"
|
2014-12-11 12:47:09 -05:00
|
|
|
|
|
|
|
if [ "$any_not_installed" = 1 ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|