Skip to content
Open
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
23 changes: 15 additions & 8 deletions cooldowns.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,20 @@ esac
# ---------------------------------------------------------------------------

# Get pip version (e.g., "26.1.0" -> "26.1.0")
# Returns empty string if pip is not installed
# Returns empty string if neither pip nor pip3 is on PATH (e.g. Homebrew only ships pip3)
get_pip_version() {
if ! command -v pip &>/dev/null; then
local pip_cmd=""
if command -v pip &>/dev/null; then
pip_cmd=pip
elif command -v pip3 &>/dev/null; then
pip_cmd=pip3
else
echo ""
return 1
fi

local version
version=$(command pip --version 2>/dev/null | awk '{print $2; exit}')
version=$(command "$pip_cmd" --version 2>/dev/null | awk '{print $2; exit}')
echo "$version"
}

Expand Down Expand Up @@ -256,26 +261,28 @@ SHELL
echo "pip: set PIP_UPLOADED_PRIOR_TO=\"P${days}D\" in $PROFILE_SCRIPT"
else
# Use shell wrapper for older pip or when pip is not installed
local date_cmd
local date_cmd pip_for_command
date_cmd=$(_date_days_ago "$days")
pip_for_command=pip
command -v pip &>/dev/null || pip_for_command=pip3

cat >> "$PROFILE_SCRIPT" << SHELL
# cooldowns:pip:start
pip() {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the name of the wrapper itself needs to be modified here, otherwise if users are executing pip3 then this will never trigger the wrapper.

local pip_major cutoff
pip_major=\$(command pip --version 2>/dev/null | awk '{ split(\$2, a, "."); print a[1]; exit }')
pip_major=\$(command ${pip_for_command} --version 2>/dev/null | awk '{ split(\$2, a, "."); print a[1]; exit }')
case "\$1" in
install|download|wheel)
if [[ "\${pip_major:-0}" -ge 26 ]]; then
cutoff=\$($date_cmd)
command pip "\$1" --uploaded-prior-to "\$cutoff" "\${@:2}"
command ${pip_for_command} "\$1" --uploaded-prior-to "\$cutoff" "\${@:2}"
else
echo "warning: pip \${pip_major:-unknown} does not support --uploaded-prior-to (need >= 26), skipping cooldown" >&2
command pip "\$@"
command ${pip_for_command} "\$@"
fi
;;
*)
command pip "\$@"
command ${pip_for_command} "\$@"
;;
esac
}
Expand Down
Loading