From 1d09385d776445905be034e159c7356f5ee39e79 Mon Sep 17 00:00:00 2001 From: Luiz Fernando Figueiredo Date: Fri, 20 Jun 2025 10:44:05 -0300 Subject: [PATCH 1/2] make list-all script non-dependent on python to avoid library/versioning issues --- bin/check-python | 34 +++++++++++++++++----------------- bin/install | 8 ++++---- bin/latest-stable | 11 +++++++++++ bin/list-all | 11 +++++------ bin/utils.sh | 24 ++++++++++++++++++++++++ 5 files changed, 61 insertions(+), 27 deletions(-) create mode 100755 bin/latest-stable create mode 100755 bin/utils.sh 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..4a3aa94 --- /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 +} \ No newline at end of file From 20c5002d50b81064543802a0d16d11e0f8f5727d Mon Sep 17 00:00:00 2001 From: Fernando Figueiredo Date: Tue, 9 Sep 2025 11:18:08 -0300 Subject: [PATCH 2/2] fix: sed strict syntax (macOS) --- bin/utils.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/utils.sh b/bin/utils.sh index 4a3aa94..1fa45b0 100755 --- a/bin/utils.sh +++ b/bin/utils.sh @@ -7,7 +7,7 @@ list_all_versions() { releases_path="https://pypi.org/pypi/pipenv/json" versions=$($cmd "$releases_path" | - sed -E 's/.*"releases":\{(.*?)\},"urls".*/\1/' | + sed -E 's/.*"releases":\{(.*)\},"urls".*/\1/' | grep -oE '"[^"]+":\[' | sed -E 's/^"([^"]+)":\[/\1/' | sort -V @@ -21,4 +21,4 @@ get_latest_version() { version_list_filtered=$([[ -z "$1" ]] && echo "$version_list" || echo "$version_list" | grep -e "^$1") echo "$version_list_filtered" | tail -1 -} \ No newline at end of file +}