Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions bin/check-python
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,12 +24,12 @@ mkdir $ASDF_INSTALL_PATH/asdf_bin
declare -a executables=("pipenv" "pipenv-resolver")
for filename in "${executables[@]}"
do
cat <<EOT >> $ASDF_INSTALL_PATH/asdf_bin/$filename
cat <<EOT >> $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
11 changes: 11 additions & 0 deletions bin/latest-stable
Original file line number Diff line number Diff line change
@@ -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"
11 changes: 5 additions & 6 deletions bin/list-all
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions bin/utils.sh
Original file line number Diff line number Diff line change
@@ -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
}