2016-04-24 10:28:48 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2018-04-13 23:26:06 +01:00
|
|
|
set -e
|
2017-01-22 09:31:29 +00:00
|
|
|
|
2018-04-06 09:14:25 +01:00
|
|
|
source "$(dirname "$0")/utils.sh"
|
2016-04-24 10:28:48 +01:00
|
|
|
|
2018-04-13 23:26:06 +01:00
|
|
|
install_python() {
|
|
|
|
local install_type=$1
|
2022-07-29 00:53:30 +01:00
|
|
|
local version
|
|
|
|
local symlink_path=$3
|
|
|
|
local install_path
|
|
|
|
|
|
|
|
version="$(resolve_partial_version "$2")"
|
|
|
|
install_path="$(dirname "$symlink_path")/$version"
|
2016-04-24 10:28:48 +01:00
|
|
|
|
2018-04-13 23:26:06 +01:00
|
|
|
if [ "$install_type" != "version" ]; then
|
|
|
|
echoerr "Cannot install specific ref from source, sorry."
|
|
|
|
echoerr "For a list of available versions, see \`asdf list-all python\`."
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-04-06 09:14:25 +01:00
|
|
|
install_or_update_python_build
|
2016-04-24 10:28:48 +01:00
|
|
|
|
2021-02-10 04:59:05 +00:00
|
|
|
if [[ -n "${ASDF_PYTHON_PATCH_URL:-}" ]]; then
|
|
|
|
echo "python-build --patch $version $install_path"
|
|
|
|
echo "with patch file from: $ASDF_PYTHON_PATCH_URL"
|
|
|
|
$(python_build_path) --patch "$version" "$install_path" < <(curl -sSL "$ASDF_PYTHON_PATCH_URL")
|
|
|
|
elif [[ -n "${ASDF_PYTHON_PATCHES_DIRECTORY:-}" ]]; then
|
|
|
|
local patch_file=${ASDF_PYTHON_PATCHES_DIRECTORY}/${version}.patch
|
2020-12-23 16:46:37 +00:00
|
|
|
echo "python-build $version $install_path -p < $patch_file"
|
|
|
|
$(python_build_path) "$version" "$install_path" -p < $patch_file
|
|
|
|
else
|
|
|
|
echo "python-build $version $install_path"
|
|
|
|
$(python_build_path) "$version" "$install_path"
|
|
|
|
fi
|
2022-07-29 00:53:30 +01:00
|
|
|
|
|
|
|
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
|
2016-04-24 10:28:48 +01:00
|
|
|
}
|
|
|
|
|
2018-09-24 22:30:16 +01:00
|
|
|
install_default_python_packages() {
|
2020-01-14 09:26:39 +00:00
|
|
|
local packages_file="${ASDF_PYTHON_DEFAULT_PACKAGES_FILE:-$HOME/.default-python-packages}"
|
2019-06-29 05:31:27 +01:00
|
|
|
|
2022-02-28 15:21:08 +00:00
|
|
|
if [ -f "$packages_file" ]; then
|
|
|
|
echo -ne "\nInstalling default python packages..."
|
|
|
|
PATH="$ASDF_INSTALL_PATH/bin:$PATH" pip install -U -r "$packages_file"
|
|
|
|
fi
|
2018-08-13 15:55:51 +01:00
|
|
|
}
|
|
|
|
|
2022-07-29 00:53:30 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-04-13 23:26:06 +01:00
|
|
|
ensure_python_build_installed
|
|
|
|
install_python "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"
|
2018-09-24 22:30:16 +01:00
|
|
|
install_default_python_packages
|