diff --git a/plugins/python-build/bin/pyenv-install b/plugins/python-build/bin/pyenv-install index 7d585aff..fcd56f93 100755 --- a/plugins/python-build/bin/pyenv-install +++ b/plugins/python-build/bin/pyenv-install @@ -184,22 +184,23 @@ fi # PyPy requires existing Python 2.x to build if [[ "${VERSION_NAME}" == "pypy-"*"-src" ]]; then - PYENV_VERSION="$(pyenv-whence "python2.7" 2>/dev/null | tail -n 1 || true)" - if [ -n "${PYENV_VERSION}" ]; then - export PYENV_VERSION - else - PYENV_VERSION="$(pyenv-whence "python2.6" 2>/dev/null | tail -n 1 || true)" - if [ -n "${PYENV_VERSION}" ]; then - export PYENV_VERSION - else - PYENV_VERSION="$(pyenv-whence "python2.5" 2>/dev/null | tail -n 1 || true)" - if [ -n "${PYENV_VERSION}" ]; then - export PYENV_VERSION - else - echo "pyenv-install: $VERSION_NAME requires CPython 2.[567] to build" >^2 - exit 1 + if [ -z "$PYENV_RPYTHON_VERSION" ]; then + for version in $(pyenv-versions --bare | sort -r); do + if [[ "$version" == 2.[567] ]] || [[ "$version" == 2.[567].* ]]; then + PYENV_RPYTHON_VERSION="$version" fi + done + fi + if [ -n "$PYENV_RPYTHON_VERSION" ]; then + if PYENV_VERSION="$PYENV_RPYTHON_VERSION" pyenv-exec python -c 'import curses' 1>/dev/null 2>&1; then + export PYENV_VERSION="$PYENV_RPYTHON_VERSION" + else + echo "pyenv-install: $VERSION_NAME: PyPy requires \`curses' in $PYENV_RPYTHON_VERSION to build from source." >&2 + exit 1 fi + else + echo "pyenv-install: $VERSION_NAME: PyPy requires Python 2.5, 2.6 or 2.7 to build from source." >&2 + exit 1 fi fi