diff --git a/libexec/pyenv-local b/libexec/pyenv-local index 8bb40fab..529cbf01 100755 --- a/libexec/pyenv-local +++ b/libexec/pyenv-local @@ -38,13 +38,14 @@ versions=($@) if [ "$versions" = "--unset" ]; then rm -f .python-version .pyenv-version elif [ -n "$versions" ]; then - if [ "$(PYENV_VERSION= pyenv-version-origin)" -ef .pyenv-version ]; then + previous_file="$(PYENV_VERSION= pyenv-version-origin || true)" + pyenv-version-file-write .python-version "${versions[@]}" + if [ "$previous_file" -ef .pyenv-version ]; then rm -f .pyenv-version { echo "pyenv: removed existing \`.pyenv-version' file and migrated" echo " local version specification to \`.python-version' file" } >&2 fi - pyenv-version-file-write .python-version "${versions[@]}" else OLDIFS="$IFS" IFS=: versions=($( diff --git a/libexec/pyenv-prefix b/libexec/pyenv-prefix index 64f6f391..a25ff030 100755 --- a/libexec/pyenv-prefix +++ b/libexec/pyenv-prefix @@ -16,32 +16,38 @@ if [ "$1" = "--complete" ]; then fi if [ -n "$1" ]; then - versions=($@) OLDIFS="$IFS" - IFS=: PYENV_VERSION="${versions[*]}" - IFS="$OLDIFS" - export PYENV_VERSION -else - OLDIFS="$IFS" - IFS=: versions=($(pyenv-version-name)) + { IFS=: + export PYENV_VERSION="$*" + } IFS="$OLDIFS" +elif [ -z "$PYENV_VERSION" ]; then + PYENV_VERSION="$(pyenv-version-name)" fi PYENV_PREFIX_PATHS=() -for version in "${versions[@]}"; do - if [ "$version" = "system" ]; then - PYTHON_PATH="$(PYENV_VERSION="${version}" pyenv-which python || true)" - PYENV_PREFIX_PATH="${PYTHON_PATH%/bin/*}" - else - PYENV_PREFIX_PATH="${PYENV_ROOT}/versions/${version}" - fi - if [ -d "$PYENV_PREFIX_PATH" ]; then - PYENV_PREFIX_PATHS=("${PYENV_PREFIX_PATHS[@]}" "$PYENV_PREFIX_PATH") - else - echo "pyenv: version \`${version}' not installed" >&2 - exit 1 - fi -done +OLDIFS="$IFS" +{ IFS=: + for version in ${PYENV_VERSION}; do + if [ "$version" = "system" ]; then + if PYTHON_PATH="$(pyenv-which python 2>/dev/null)"; then + PYENV_PREFIX_PATH="${PYTHON_PATH%/bin/*}" + else + echo "pyenv: system version not found in PATH" >&2 + exit 1 + fi + else + PYENV_PREFIX_PATH="${PYENV_ROOT}/versions/${version}" + fi + if [ -d "$PYENV_PREFIX_PATH" ]; then + PYENV_PREFIX_PATHS=("${PYENV_PREFIX_PATHS[@]}" "$PYENV_PREFIX_PATH") + else + echo "pyenv: version \`${version}' not installed" >&2 + exit 1 + fi + done +} +IFS="$OLDIFS" OLDIFS="$IFS" { IFS=: diff --git a/libexec/pyenv-version-file-write b/libexec/pyenv-version-file-write index 6441909e..5ec01b6c 100755 --- a/libexec/pyenv-version-file-write +++ b/libexec/pyenv-version-file-write @@ -5,7 +5,7 @@ set -e [ -n "$PYENV_DEBUG" ] && set -x PYENV_VERSION_FILE="$1" -shift +shift || true versions=("$@") if [ -z "$versions" ] || [ -z "$PYENV_VERSION_FILE" ]; then diff --git a/libexec/pyenv-version-name b/libexec/pyenv-version-name index 368ccb97..c15178e2 100755 --- a/libexec/pyenv-version-name +++ b/libexec/pyenv-version-name @@ -5,18 +5,10 @@ set -e if [ -z "$PYENV_VERSION" ]; then PYENV_VERSION_FILE="$(pyenv-version-file)" - OLDIFS="$IFS" - IFS=: versions=($(pyenv-version-file-read "$PYENV_VERSION_FILE" || true)) - IFS=: PYENV_VERSION="${versions[*]}" - IFS="$OLDIFS" - export PYENV_VERSION -else - OLDIFS="$IFS" - IFS=: versions=($(echo "${PYENV_VERSION}")) - IFS="$OLDIFS" + PYENV_VERSION="$(pyenv-version-file-read "$PYENV_VERSION_FILE" || true)" fi -if [ -z "$versions" ] || [ "$versions" = "system" ]; then +if [ -z "$PYENV_VERSION" ] || [ "$PYENV_VERSION" = "system" ]; then echo "system" exit fi @@ -26,11 +18,27 @@ version_exists() { [ -d "${PYENV_ROOT}/versions/${version}" ] } -for version in "${versions[@]}"; do - if [ "$version" != "system" ] && ! version_exists "$version"; then - echo "pyenv: version \`$version' is not installed" >&2 - exit 1 - fi -done +versions=() +OLDIFS="$IFS" +{ IFS=: + for version in ${PYENV_VERSION}; do + if version_exists "$version" || [ "$version" = "system" ]; then + versions=("${versions[@]}" "${version}") + elif version_exists "${version#python-}"; then + { echo "warning: ignoring extraneous \`python-' prefix in version \`${version}'" + echo " (set by $(pyenv-version-origin))" + } >&2 + versions=("${versions[@]}" "${version#python-}") + else + echo "pyenv: version \`$version' is not installed" >&2 + exit 1 + fi + done +} +IFS="$OLDIFS" -echo "${PYENV_VERSION}" +OLDIFS="$IFS" +{ IFS=: + echo "${versions[*]}" +} +IFS="$OLDIFS" diff --git a/test/exec.bats b/test/exec.bats index c81db709..817d1aee 100644 --- a/test/exec.bats +++ b/test/exec.bats @@ -29,8 +29,8 @@ create_executable() { run pyenv-completions exec assert_success assert_output < my-version <<<"1.9.3-p194@tag 1.8.7 hi" run pyenv-version-file-read my-version - assert_success "1.9.3-p194@tag" + assert_success "1.9.3-p194@tag:1.8.7:hi" } @test "loads only the first line in file" { @@ -47,7 +47,7 @@ setup() { 1.9.3 two IN run pyenv-version-file-read my-version - assert_success "1.8.7" + assert_success "1.8.7:one:1.9.3:two" } @test "ignores leading blank lines" {