Merge pull request #136 from matan129/matan-rosenberg-auto-reshim
Pip Auto Reshim Support
This commit is contained in:
commit
dcba495647
1 changed files with 66 additions and 0 deletions
66
shims/pip
Executable file
66
shims/pip
Executable file
|
@ -0,0 +1,66 @@
|
|||
#! /usr/bin/env bash
|
||||
|
||||
# This script wraps pip to run `asdf reshim` after installs and uninstalls.
|
||||
# Any other cases are passed-through to pip.
|
||||
#
|
||||
# Inspired by the npm shim: https://github.com/asdf-vm/asdf-nodejs/blob/b2d06a768d9a14186db72/shims/npm
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
this_dir=$(dirname "${BASH_SOURCE[0]}")
|
||||
this_dir=$(cd "$this_dir" && pwd -P) # Normalizes the directory; see https://stackoverflow.com/a/7666/2308068
|
||||
plugin_name=$(basename "$(dirname "$this_dir")")
|
||||
|
||||
should_reshim() {
|
||||
if [ "${ASDF_PYTHON_SKIP_RESHIM:-}" ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
for arg; do
|
||||
case "$arg" in
|
||||
install|uninstall)
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
resolve_pip() {
|
||||
local pip_location="${ASDF_PYTHON_CANON_PIP_PATH:-$(search_pip_bin)}"
|
||||
|
||||
if ! [ "$pip_location" ]; then
|
||||
echo "asdf-python couldn't find a suitable pip executable"
|
||||
echo "This is probably a problem with the plugin, please report this issue"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "$pip_location"
|
||||
}
|
||||
|
||||
search_pip_bin() {
|
||||
local probably_pip="$(asdf where python)/bin/pip"
|
||||
|
||||
if [ -x "$probably_pip" ]; then
|
||||
echo "$probably_pip"
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
wrap_pip() {
|
||||
local pip=$(resolve_pip)
|
||||
|
||||
if should_reshim "$@"; then
|
||||
"$pip" "$@"
|
||||
echo "Reshimming asdf $plugin_name..."
|
||||
asdf reshim "$plugin_name"
|
||||
else
|
||||
exec "$pip" "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
wrap_pip "$@"
|
||||
|
Reference in a new issue