#!/usr/bin/env bash
# Summary: Explain how the current Python version is set
set -euo pipefail
[ -n "${PYENV_DEBUG:-}" ] && set -x

PYENV_VERSION_ORIGIN=

OLDIFS="$IFS"
IFS=$'\n' scripts=(`pyenv-hooks version-origin`)
IFS="$OLDIFS"
# bash < 4.4 (incl. macOS's 3.2) treats an empty array as unbound under set -u,
# and hooks are third-party code, so relax nounset while sourcing them
set +u
for script in "${scripts[@]}"; do
  source "$script"
done
set -u

if [[ -n ${PYENV_VERSION_ORIGIN:-} ]]; then
  echo "$PYENV_VERSION_ORIGIN"
elif [[ -n ${PYENV_VERSION:-} ]]; then
  echo "PYENV_VERSION environment variable"
else
  pyenv-version-file
fi
