diff --git a/bin/check-python b/bin/check-python index 6e3d09c..052853d 100755 --- a/bin/check-python +++ b/bin/check-python @@ -10,32 +10,32 @@ PYTHON_MINIMUM_MINOR=4 PYTHON3_REF=$(which python3 | grep "/python3") PYTHON_REF=$(which python | grep "/python") -error_msg(){ - echo "NoPython" +error_msg() { + echo "NoPython" } -python_ref(){ - local my_ref=$1 - echo $($my_ref -c 'import platform; major, minor, patch = platform.python_version_tuple(); print(major); print(minor);') +python_ref() { + local my_ref=$1 + echo $($my_ref -c 'import platform; major, minor, patch = platform.python_version_tuple(); print(major); print(minor);') } # Print success_msg/error_msg according to the provided minimum required versions -check_version(){ - local major=$1 - local minor=$2 - local python_ref=$3 - [[ $major -ge $PYTHON_MINIMUM_MAJOR && $minor -ge $PYTHON_MINIMUM_MINOR ]] && echo $python_ref || error_msg +check_version() { + local major=$1 + local minor=$2 + local python_ref=$3 + [[ $major -ge $PYTHON_MINIMUM_MAJOR && $minor -ge $PYTHON_MINIMUM_MINOR ]] && echo $python_ref || error_msg } # Logic if [[ ! -z $PYTHON3_REF ]]; then - version=($(python_ref python3)) - check_version ${version[0]} ${version[1]} $PYTHON3_REF + version=($(python_ref python3)) + check_version ${version[0]} ${version[1]} $PYTHON3_REF elif [[ ! -z $PYTHON_REF ]]; then - # Didn't find python3, let's try python - version=($(python_ref python)) - check_version ${version[0]} ${version[1]} $PYTHON_REF + # Didn't find python3, let's try python + version=($(python_ref python)) + check_version ${version[0]} ${version[1]} $PYTHON_REF else - # Python is not installed at all - error_msg + # Python is not installed at all + error_msg fi diff --git a/bin/install b/bin/install index a5a02ca..aa817e2 100755 --- a/bin/install +++ b/bin/install @@ -6,8 +6,8 @@ __dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PYTHON_REF=$(source ${__dir}/check-python) if [[ "$PYTHON_REF" == "NoPython" ]]; then - echo "Python3.4+ is not installed." - exit + echo "Python3.4+ is not installed." + exit fi # create and activate virtual environment @@ -24,12 +24,12 @@ mkdir $ASDF_INSTALL_PATH/asdf_bin declare -a executables=("pipenv" "pipenv-resolver") for filename in "${executables[@]}" do - cat <> $ASDF_INSTALL_PATH/asdf_bin/$filename + cat <> $ASDF_INSTALL_PATH/asdf_bin/$filename #!/usr/bin/env bash source $ASDF_INSTALL_PATH/bin/activate PIPENV_IGNORE_VIRTUALENVS=1 $filename "\$@" EOT - chmod a+x $ASDF_INSTALL_PATH/asdf_bin/$filename + chmod a+x $ASDF_INSTALL_PATH/asdf_bin/$filename done diff --git a/bin/latest-stable b/bin/latest-stable new file mode 100755 index 0000000..cfd2994 --- /dev/null +++ b/bin/latest-stable @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +current_script_path=${BASH_SOURCE[0]} +plugin_dir=$(dirname "$(dirname "$current_script_path")") + +# shellcheck source=./bin/utils.sh +source "${plugin_dir}/bin/utils.sh" + +latest_version=$(get_latest_version "$1") + +echo "$latest_version" diff --git a/bin/list-all b/bin/list-all index 339521e..798d7fb 100755 --- a/bin/list-all +++ b/bin/list-all @@ -1,10 +1,9 @@ #!/usr/bin/env bash -set -eu +current_script_path=${BASH_SOURCE[0]} +plugin_dir=$(dirname "$(dirname "$current_script_path")") -cmd="curl --silent --location" -releases_path="https://pypi.org/pypi/pipenv/json" +# shellcheck source=./bin/utils.sh +source "${plugin_dir}/bin/utils.sh" -versions=$(eval "$cmd $releases_path" | exec python -c "import sys, json, pkg_resources; releases = json.load(sys.stdin)['releases']; print(' '.join(sorted(releases, key=pkg_resources.parse_version)))") - -echo "$versions" +list_all_versions diff --git a/bin/utils.sh b/bin/utils.sh new file mode 100755 index 0000000..1fa45b0 --- /dev/null +++ b/bin/utils.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +set -eo pipefail + +list_all_versions() { + cmd="curl --silent --location" + releases_path="https://pypi.org/pypi/pipenv/json" + + versions=$($cmd "$releases_path" | + sed -E 's/.*"releases":\{(.*)\},"urls".*/\1/' | + grep -oE '"[^"]+":\[' | + sed -E 's/^"([^"]+)":\[/\1/' | + sort -V + ) + + echo "$versions" +} + +get_latest_version() { + version_list=$(list_all_versions) + version_list_filtered=$([[ -z "$1" ]] && echo "$version_list" || echo "$version_list" | grep -e "^$1") + + echo "$version_list_filtered" | tail -1 +}