Skip to content

Commit 1d09385

Browse files
committed
make list-all script non-dependent on python to avoid library/versioning issues
1 parent 06a3181 commit 1d09385

File tree

5 files changed

+61
-27
lines changed

5 files changed

+61
-27
lines changed

bin/check-python

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,32 @@ PYTHON_MINIMUM_MINOR=4
1010
PYTHON3_REF=$(which python3 | grep "/python3")
1111
PYTHON_REF=$(which python | grep "/python")
1212

13-
error_msg(){
14-
echo "NoPython"
13+
error_msg() {
14+
echo "NoPython"
1515
}
1616

17-
python_ref(){
18-
local my_ref=$1
19-
echo $($my_ref -c 'import platform; major, minor, patch = platform.python_version_tuple(); print(major); print(minor);')
17+
python_ref() {
18+
local my_ref=$1
19+
echo $($my_ref -c 'import platform; major, minor, patch = platform.python_version_tuple(); print(major); print(minor);')
2020
}
2121

2222
# Print success_msg/error_msg according to the provided minimum required versions
23-
check_version(){
24-
local major=$1
25-
local minor=$2
26-
local python_ref=$3
27-
[[ $major -ge $PYTHON_MINIMUM_MAJOR && $minor -ge $PYTHON_MINIMUM_MINOR ]] && echo $python_ref || error_msg
23+
check_version() {
24+
local major=$1
25+
local minor=$2
26+
local python_ref=$3
27+
[[ $major -ge $PYTHON_MINIMUM_MAJOR && $minor -ge $PYTHON_MINIMUM_MINOR ]] && echo $python_ref || error_msg
2828
}
2929

3030
# Logic
3131
if [[ ! -z $PYTHON3_REF ]]; then
32-
version=($(python_ref python3))
33-
check_version ${version[0]} ${version[1]} $PYTHON3_REF
32+
version=($(python_ref python3))
33+
check_version ${version[0]} ${version[1]} $PYTHON3_REF
3434
elif [[ ! -z $PYTHON_REF ]]; then
35-
# Didn't find python3, let's try python
36-
version=($(python_ref python))
37-
check_version ${version[0]} ${version[1]} $PYTHON_REF
35+
# Didn't find python3, let's try python
36+
version=($(python_ref python))
37+
check_version ${version[0]} ${version[1]} $PYTHON_REF
3838
else
39-
# Python is not installed at all
40-
error_msg
39+
# Python is not installed at all
40+
error_msg
4141
fi

bin/install

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ __dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
66

77
PYTHON_REF=$(source ${__dir}/check-python)
88
if [[ "$PYTHON_REF" == "NoPython" ]]; then
9-
echo "Python3.4+ is not installed."
10-
exit
9+
echo "Python3.4+ is not installed."
10+
exit
1111
fi
1212

1313
# create and activate virtual environment
@@ -24,12 +24,12 @@ mkdir $ASDF_INSTALL_PATH/asdf_bin
2424
declare -a executables=("pipenv" "pipenv-resolver")
2525
for filename in "${executables[@]}"
2626
do
27-
cat <<EOT >> $ASDF_INSTALL_PATH/asdf_bin/$filename
27+
cat <<EOT >> $ASDF_INSTALL_PATH/asdf_bin/$filename
2828
#!/usr/bin/env bash
2929
3030
source $ASDF_INSTALL_PATH/bin/activate
3131
PIPENV_IGNORE_VIRTUALENVS=1 $filename "\$@"
3232
EOT
3333

34-
chmod a+x $ASDF_INSTALL_PATH/asdf_bin/$filename
34+
chmod a+x $ASDF_INSTALL_PATH/asdf_bin/$filename
3535
done

bin/latest-stable

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
current_script_path=${BASH_SOURCE[0]}
4+
plugin_dir=$(dirname "$(dirname "$current_script_path")")
5+
6+
# shellcheck source=./bin/utils.sh
7+
source "${plugin_dir}/bin/utils.sh"
8+
9+
latest_version=$(get_latest_version "$1")
10+
11+
echo "$latest_version"

bin/list-all

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#!/usr/bin/env bash
22

3-
set -eu
3+
current_script_path=${BASH_SOURCE[0]}
4+
plugin_dir=$(dirname "$(dirname "$current_script_path")")
45

5-
cmd="curl --silent --location"
6-
releases_path="https://pypi.org/pypi/pipenv/json"
6+
# shellcheck source=./bin/utils.sh
7+
source "${plugin_dir}/bin/utils.sh"
78

8-
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)))")
9-
10-
echo "$versions"
9+
list_all_versions

bin/utils.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail
4+
5+
list_all_versions() {
6+
cmd="curl --silent --location"
7+
releases_path="https://pypi.org/pypi/pipenv/json"
8+
9+
versions=$($cmd "$releases_path" |
10+
sed -E 's/.*"releases":\{(.*?)\},"urls".*/\1/' |
11+
grep -oE '"[^"]+":\[' |
12+
sed -E 's/^"([^"]+)":\[/\1/' |
13+
sort -V
14+
)
15+
16+
echo "$versions"
17+
}
18+
19+
get_latest_version() {
20+
version_list=$(list_all_versions)
21+
version_list_filtered=$([[ -z "$1" ]] && echo "$version_list" || echo "$version_list" | grep -e "^$1")
22+
23+
echo "$version_list_filtered" | tail -1
24+
}

0 commit comments

Comments
 (0)