added major/minor shorthands

this PR allows you to install python via `asdf install python 3.10` or
`asdf install python 3`. It will then install the latest version
starting with that prefix.

It will add an alias in ~/.asdf/installs/python so you can have a
.tool-versions file like the following:

```
python 3.10
```
This commit is contained in:
Jeff Dickey 2022-07-28 18:53:30 -05:00
parent dcba495647
commit 3c2bb7b8a1
No known key found for this signature in database
GPG key ID: 08E8B99BC6F84BC4
2 changed files with 51 additions and 3 deletions

View file

@ -6,8 +6,12 @@ source "$(dirname "$0")/utils.sh"
install_python() {
local install_type=$1
local version=$2
local install_path=$3
local version
local symlink_path=$3
local install_path
version="$(resolve_partial_version "$2")"
install_path="$(dirname "$symlink_path")/$version"
if [ "$install_type" != "version" ]; then
echoerr "Cannot install specific ref from source, sorry."
@ -28,6 +32,13 @@ install_python() {
echo "python-build $version $install_path"
$(python_build_path) "$version" "$install_path"
fi
if [ "$install_path" != "$symlink_path" ]; then
# add a symlink for an alias like:
# ~/.asdf/installs/python/3 -> ~/.asdf/installs/python/3.1.2
rmdir "$symlink_path" # asdf creates this empty directory we don't want
ln -sfv "$install_path" "$symlink_path"
fi
}
install_default_python_packages() {
@ -39,6 +50,21 @@ install_default_python_packages() {
fi
}
fetch_all_versions() {
$(python_build_path) --definitions | grep -E '^\d+\.\d+\.\d+$' | sort -rV
}
resolve_partial_version() {
local version=$1
if [[ "$version" =~ ^[0-9]+(\.[0-9]+)?$ ]]; then
# maps a version like "3.0" or "3" to "3.1.2"
fetch_all_versions | grep -e "^$version\." | head -n1
else
echo "$version"
fi
}
ensure_python_build_installed
install_python "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"
install_default_python_packages

View file

@ -4,7 +4,29 @@ source "$(dirname "$0")/utils.sh"
list_all() {
install_or_update_python_build
$(python_build_path) --definitions | tr '\n' ' '
echo $(
$(python_build_path) --definitions
echo 2
echo 2.1
echo 2.2
echo 2.3
echo 2.4
echo 2.5
echo 2.6
echo 2.7
echo 3
echo 3.0
echo 3.1
echo 3.2
echo 3.3
echo 3.4
echo 3.5
echo 3.6
echo 3.7
echo 3.8
echo 3.9
echo 3.10
) | tr '\n' ' '
}
list_all