From 7daf896739ff1c11bf9a27437e905ee32ae0cb2d Mon Sep 17 00:00:00 2001 From: Bjorn Neergaard Date: Fri, 13 Apr 2018 16:26:06 -0600 Subject: [PATCH] Remove deprecated version parser; refactor to add quotes and remove useless code --- bin/get-version-from-legacy-file | 13 ------------- bin/install | 25 ++++++++++++++----------- bin/list-all | 4 ++-- bin/utils.sh | 4 ++++ 4 files changed, 20 insertions(+), 26 deletions(-) delete mode 100755 bin/get-version-from-legacy-file diff --git a/bin/get-version-from-legacy-file b/bin/get-version-from-legacy-file deleted file mode 100755 index e423a07..0000000 --- a/bin/get-version-from-legacy-file +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -get_legacy_version() { - local current_directory="$1" - local python_version_file="$current_directory/.python-version" - - # Get version from .python-version file. .python-version is used by pyenv - if [ -f "$python_version_file" ]; then - cat "$python_version_file" - fi -} - -get_legacy_version "$1" diff --git a/bin/install b/bin/install index c16eecb..2439a44 100755 --- a/bin/install +++ b/bin/install @@ -1,20 +1,23 @@ #!/usr/bin/env bash -source $(dirname $0)/utils.sh +set -e + +source "$(dirname "$0")"/utils.sh install_python() { - local version="$1" - local install_path="$2" + local install_type=$1 + local version=$2 + local install_path=$3 - local tmp_dir="$(mktemp -d -t asdf-python.XXX)" + if [ "$install_type" != "version" ]; then + echoerr "Cannot install specific ref from source, sorry." + echoerr "For a list of available versions, see \`asdf list-all python\`." + exit 1 + fi - ensure_python_build_installed - - ASDF_CONCURRENCY="${ASDF_CONCURRENCY:-1}" echo "python-build $version $install_path" - MAKE_OPTS="$MAKE_OPTS -j$ASDF_CONCURRENCY" TMP_DIR="$tmp_dir" $(python_build_path) $version $install_path - echo "Cleaning up" - rm -rf "$tmp_dir" + $(python_build_path) "$version" "$install_path" } -install_python $ASDF_INSTALL_VERSION $ASDF_INSTALL_PATH +ensure_python_build_installed +install_python "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH" diff --git a/bin/list-all b/bin/list-all index 0f12fee..5129e40 100755 --- a/bin/list-all +++ b/bin/list-all @@ -1,11 +1,11 @@ #!/usr/bin/env bash -source $(dirname $0)/utils.sh +source "$(dirname "$0")/utils.sh" list_all() { ensure_python_build_installed + $(python_build_path) --definitions | tr '\n' ' ' - rm -rf "$tmp_download_dir" } list_all diff --git a/bin/utils.sh b/bin/utils.sh index 50b9d06..b7913a8 100755 --- a/bin/utils.sh +++ b/bin/utils.sh @@ -1,3 +1,7 @@ +echoerr() { + printf "\033[0;31m%s\033[0m" "$1" >&2 +} + ensure_python_build_installed() { if [ ! -f "$(python_build_path)" ]; then download_python_build