asdf-python/bin/install
Jeremy Fleischman e3ada52ca4
Don't complain if a patch file doesn't exist for a particular version of python
I hope this isn't too controversial: I personally have this
`ASDF_PYTHON_PATCHES_DIRECTORY` globally set up on my machine, which is
super useful when I install/reinstall random versions of Python, but is
kind of annoying when I try to install versions of python that don't
actually need a patch: I have to create an empty file just to get it to
install.

With this change, I don't have to do that: instead I only have to create
`.patch` files for the versions of Python that need it.
2022-03-22 14:28:22 -07:00

51 lines
1.7 KiB
Bash
Executable file

#!/usr/bin/env bash
set -e
source "$(dirname "$0")/utils.sh"
install_python() {
local install_type=$1
local version=$2
local install_path=$3
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
install_or_update_python_build
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:-}" ]] && [[ -f ${ASDF_PYTHON_PATCHES_DIRECTORY}/${version}.patch ]]; then
local patch_file=${ASDF_PYTHON_PATCHES_DIRECTORY}/${version}.patch
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
}
install_default_python_packages() {
local packages_file="${ASDF_PYTHON_DEFAULT_PACKAGES_FILE:-$HOME/.default-python-packages}"
if [ ! -f "$packages_file" ]; then return; fi
while read -r name; do
echo -ne "\nInstalling \033[33m${name}\033[39m python package... "
PATH="$ASDF_INSTALL_PATH/bin:$PATH" pip install "$name" > /dev/null 2>&1 && rc=$? || rc=$?
if [[ $rc -eq 0 ]]; then
echo -e "\033[32mSUCCESS\033[39m"
else
echo -e "\033[31mFAIL\033[39m"
fi
done < "$packages_file"
}
ensure_python_build_installed
install_python "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"
install_default_python_packages